ernie
New Member
Posts: 44
|
Post by ernie on Jan 26, 2020 10:07:26 GMT -5
Hi guys-
I'm trying to insert the contents of controls directly into an array, for example: #main.tb01 "!contents? b$(4)" but this produces the error, "bad variable name"
a simple workaround would be: #main.tb01 "!contents? name$" b$(4) = name$ but this array holds over a thousand variables and I'd like to avoid the extra code.
Is there a way to do this using a single statement? Or a sub or a function?
|
|
|
Post by sarossell on Jan 26, 2020 15:40:43 GMT -5
Hello ernie,
I can't answer your question, but I might be able to assuage your concerns regarding the "extra" code by providing a couple of insights:
1) You've got plenty of memory to work with in Liberty BASIC, so no matter how many hoops you have to jump through by adding "extra" steps in your code to get things working, LB can handle it.
2) Sometimes, with code, there's the old joke of "you can't get there from here". I recently ran across a couple of challenges with the REPLSTR$ command. You can't directly replace a semi-colon with something that includes a semi-colon. You have to replace it with something else and then replace it again. (See the code example below). You also can't replace anything with multiples of the same thing. The reason, I suspect is that the REPLSTR$ command is actually a loop and if you keep changing the data it's looking for, it can get caught in an infinite loop.
Header$="ASXcode;Code;Underlying;Exchange;Type;Strike;Stop;ReqNum;CurSharePrice;Gearing;MiniValue;Perc2Stop"
a$ = ";" : b$ = "''" : w$ = "';'"
REM This doesn't work. REM Header$ = REPLSTR$(Header$, ";", "';'")
REM You have to sneak up on it by first replacing the semicolon with two single quotes and then replacing them with the semicolon between two single quotes.
Header$ = REPLSTR$(REPLSTR$(Header$,a$,b$),b$,w$) print Header$
wait end
Good luck!
:@)
|
|
ernie
New Member
Posts: 44
|
Post by ernie on Jan 26, 2020 16:40:32 GMT -5
this seems to work..nomainwin textbox #main.tb01, 40, 50, 200, 22 open "Page 1" for window as #main #main "trapclose [quit]" #main.tb01 "Harcor Snooty" call box2array "#main.tb01", 4 notice v$(4) wait end
Sub box2array control$, number #control$ "!contents? temp$" v$(number) = temp$ End Sub
[quit] close #main end
|
|
|
Post by sarossell on Jan 26, 2020 20:25:45 GMT -5
Yep, the !contents? command is expecting a variable, and as much as an array can look like a variable, it really isn't one, unfortunately in this case.
Still, clever coding!
BTW, for the alpha 5 testers out there, this doesn't work. Not sure what that's about. :@(
|
|
|
Post by honkytonk on Jan 28, 2020 13:01:59 GMT -5
'nomainwin textbox #main.tb01, 40, 50, 200, 22 open "Page 1" for window as #main #main "trapclose [quit]" dim array(12): dim array$(15) var=4 #main.tb01, str$(var) #main.tb01, "!contents? temp$" avar=val(temp$) array(1)=avar array$(1)=temp$ print avar print temp$ print array(1) print array$(1) wait [quit] close #main end
|
|