Source language: Translate to:

Set Multiple Vars

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Set Multiple Vars

Postby dpayer » Mon Dec 17, 2012 1:38 pm

You can set multiple variables with one line of code with this function.

Syntax:

Code: Select all
  CALL "SetMultiVar" "var1=value1;var2=value2;var3=value3;var4=value4"


Note: no error correction done if your strings contains additional equal signs, quote marks or semi colons besides those used for delimiters.


Save the following code in your Functions folder (under NB)
Code: Select all
{NeoBook Function}
Version=5.70
Language=NeoBook
Comment=Note: no error correction done if your strings contain equal signs, quote marks or semi colons. |
Param=[%1]|Text|String with varname=value entries separated by semicolon
{End}
SearchStr ";" "[%1]" "[MultiVarArrayDelimiterFound]" ""
If "[MultiVarArrayDelimiterFound]" ">" "0"
StrParse "[%1]" ";" "[MultivarArray]" "[MultivarArrayLen]"

  Loop "1" "[MultivarArrayLen]" "[MultivarWILL]"
     SearchStr "=" "[MultivarArray[MultivarWILL]]" "[MultiVarArrayEqualFound]" ""
     If "[MultivarArrayEqualFound]" ">" "0"
       StrParse "[MultivarArray[MultivarWILL]]" "=" "[MultivarElement]" ""
       SetVar "[[MultivarElement1]]" "[MultivarElement2]"
     Else
     Alertbox "Error" "No equal delimiter found in string"
     Endif
  Endloop
Else
  Alertbox "Error" "No delimiter found in string"
Endif



Sample pub - using function named as SetMultiVar
(copy content below and paste into blank NB page):
Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5.70
ObjectType=3
Name=PushButton1
X=24
Y=136
W=280
H=40
Anchor=0
Text=Call MultiVar Set Function
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=Call "SetMultiVar" "var1=1;var2=2;var3=3;var4=4;varNOT5=not5"¶¶AlertBox "test" "Var1 = [Var1]|Var2 = [Var2]|Var3 = [Var3]|Var4 = [Var4]|VarNOT5 = [VarNOT5]"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Set Multiple Vars

Postby smokinbanger » Sun Dec 23, 2012 7:05 pm

Nice, Thanks!
Just Sayin'...
smokinbanger
 
Posts: 198
Joined: Mon Jan 16, 2012 9:53 am
Location: United States

Re: Set Multiple Vars

Postby Gaev » Sun Dec 23, 2012 7:54 pm

DavidP:

1) suggested enhancement ...

//specify primary separator string
CALL "SetMultiVar" "$@;" "var1=value1$@;var2=value2$@;var3=value3$@;var4=value4"
//same for secondary separator string
CALL "SetMultiVar" "$@;" "=_=" "var1=_=value1$@;var2=_=value2$@;var3=_=value3$@;var4=_=value4"

2) BTW, f.y.i. this can also be achieved with pure NeoBook commands ... key is to exploit NeoBook's nested parsing of brackets e.g. ...
Code: Select all
SetVar "[abc]" "var1"
SetVar "[[abc]] "[someValue]"
... will set variable [var1] to value in variable [someValue]
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada


Return to NeoBook Functions - VBScript & JavaScript

Who is online

Users browsing this forum: gcoulthard and 1 guest