Welcome to %s forums

BrainModular Users Forum

Login Register

[script) Remove element from commatext

I need help on a Patch
Post Reply
ethnix73
Member
Posts: 604
Location: France, Caen
Contact:

Unread post by ethnix73 » 03 Mar 2011, 15:26

I'm trying to modify the get commatext element script, to obtain the inverse result: remove an element from commatext.

I just want to get an element from a commatext, and remove it. The goal is to get the commatext from a list box, and being able to remove the selected element from the list.....

Any script guru who could help me?
Seb.Dub

ethnix73
Member
Posts: 604
Location: France, Caen
Contact:

Unread post by ethnix73 » 03 Mar 2011, 15:31

Oups, the script:
/////////////////////////////////////////////
// Get Comma text element
////////////////////////////////////////////

// parameters declaration
var input : Tparameter;
var nth : Tparameter;
var output : Tparameter;
var sl1 : TStringList;


// destroy
procedure Destroy;
begin
sl1.free;

end;

// initialisation : create parameters
procedure init;
begin
SetModuleColor($808080+302060);
Input := CreateParam('in',ptTextField);
SetIsOutPut(Input,false);
nth := CreateParam('num',ptdataField);
SetIsOutPut(nth,false);
SetMin(nth,0);
SetMax(nth,MAXINT);
SetFormat(nth,'%.0f');
output := CreateParam('out',ptTextField);
SetIsInPut(Output,false);
Sl1 := TStringList.Create;

end;


procedure Callback(n:integer);
var idx : integer;
var result : string;
begin
Sl1.CommaText := GetStringValue(Input);
idx := round(GetValue(nth));
if (idx>=0)
and (idx<SL1.count)
then result := SL1.Strings[idx]
else result := '';
SetStringValue(Output,result);
// strace(GetStringValue(outPut));
end;

// no process bloc
Seb.Dub

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 03 Mar 2011, 15:46

I haven't tested it myself (at least not that I can remember), but after getting the input string and index I think you can try something like:

Code: Select all

Sl1.Delete&#40;idx&#41;;
SetStringValue&#40;Output, Sl1.CommaText&#41;;
Bjørn S

ethnix73
Member
Posts: 604
Location: France, Caen
Contact:

Unread post by ethnix73 » 03 Mar 2011, 16:39

Yes, thanks master bsork!

I tried delete but i have yet big difficulties with script syntax....

So, here is the good script for "Remove commatext elt":
/////////////////////////////////////////////
// Remove Comma text element
////////////////////////////////////////////

// parameters declaration
var input : Tparameter;
var nth : Tparameter;
var output : Tparameter;
var sl1 : TStringList;


// destroy
procedure Destroy;
begin
sl1.free;

end;

// initialisation : create parameters
procedure init;
begin
SetModuleColor($808080+302060);
Input := CreateParam('in',ptTextField);
SetIsOutPut(Input,false);
nth := CreateParam('num',ptdataField);
SetIsOutPut(nth,false);
SetMin(nth,0);
SetMax(nth,MAXINT);
SetFormat(nth,'%.0f');
output := CreateParam('out',ptTextField);
SetIsInPut(Output,false);
Sl1 := TStringList.Create;

end;


procedure Callback(n:integer);
var idx : integer;
var result : string;
begin
Sl1.CommaText := GetStringValue(Input);
idx := round(GetValue(nth));
if (idx>=0)
and (idx<SL1.count)
then Sl1.Delete(idx);
SetStringValue(Output, Sl1.CommaText);
// strace(GetStringValue(outPut));
end;

// no process bloc
Seb.Dub

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 04 Mar 2011, 13:12

Sorry, but I guess could've been more spesific in telling where to place the code. I does work, though. A tip if you want the commatext sometimes to be copied in to out is to use an nth value of eg -1 and add the needed IF test.
Bjørn S

ethnix73
Member
Posts: 604
Location: France, Caen
Contact:

Unread post by ethnix73 » 06 Mar 2011, 12:38

The script is ok for my need, bsork.

Thanks anyway.
Seb.Dub

Post Reply

Who is online

Users browsing this forum: No registered users and 151 guests