Sver
Full Member
Posts: 145
|
Post by Sver on Nov 23, 2019 10:05:49 GMT -5
Is it possible to create a variable ?
Example: The input of a textbox is "Car"
Can we change the input "car" into a variable : Car$ ? (not before)
|
|
|
Post by Rod on Nov 23, 2019 10:50:32 GMT -5
Yes, look at the help file. You send the textbox a command to give up its contents. The command places the contents into a variable of your choice.
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Nov 23, 2019 11:05:20 GMT -5
Hei Rod !
I mean : when a user write "car" in a textbox, the variable have to be car$ but, when the user write "boat" in the same textbox, the program have to create a new variable: boat$
Can you make a new variable when the program is running ?
|
|
ntech
New Member
Posts: 49
|
Post by ntech on Nov 23, 2019 12:46:15 GMT -5
Sver, the way I'd do that is this:
1) Read the textbox into an arbitrary variable (textboxContents$) 2) if textboxContents$ = "car" then car$ = "this" 'assign whatever you like to car$ else if textboxContents$ = "boat" then boat$ = "that" 'assign whatever you like to boat$ end if end if
|
|
|
Post by Rod on Nov 23, 2019 12:58:55 GMT -5
A variable has a name and has content. So while it is easy to capture the name from the textbox where are we getting the content from? What is the content of the variable named “car”
An array may help but I am not understanding the problem just yet.
|
|
|
Post by tsh73 on Nov 23, 2019 13:18:24 GMT -5
Really interesting what you want to do with it. Here's a way, kind of.
Sample session
There is existing variable named aaa$ Check: Variable name is empty Checking variable aaa$ varName$=>xyzzy< Checking variable boat$ varName$=>< Seting variable boat$to >123< Checking variable car$ varName$=>< Seting variable car$to >Ferrary< Checking variable boat$ varName$=>123< Checking variable car$ varName$=>Ferrary<
'Form created with the help of Freeform 3 v07-31-2015 'Generated on Nov 23, 2019 at 20:58:42
[setup.main.Window]
'-----Begin code for #main
nomainwin WindowWidth = 550 WindowHeight = 410 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'-----Begin GUI objects code
TexteditorColor$ = "white" texteditor #main.log, 10, 72, 520, 280 TextboxColor$ = "white" textbox #main.textbox1, 10, 32, 100, 25 statictext #main.statictext2, "Var name", 10, 12, 58, 20 button #main.button3,"Check variable",[button3Click], UL, 135, 17, 125, 25 statictext #main.statictext4, "Var value", 280, 7, 70, 20 textbox #main.textbox6, 275, 27, 100, 25 button #main.button7,"Set variable",[button7Click], UL, 395, 12, 95, 25
'-----End GUI objects code
'-----Begin menu code aaa$="xyzzy" 'existing variable, for test
menu #main, "Edit" ' <-- Texteditor menu.
'-----End menu code
open "untitled" for window as #main print #main, "font ms_sans_serif 10" print #main, "trapclose [quit.main]"
#main.log "There is existing variable named aaa$"
[main.inputLoop] 'wait here for input event wait
[button3Click] 'Check variable #main.textbox1 "!contents? varName$" varName$=trim$(varName$) if trim$(varName$)="" then #main.log "Check: Variable name is empty" wait end if if right$(varName$, 1)<>"$" then varName$=varName$+"$" 'aaa->aaa$ #main.log "Checking variable ";varName$
#main.log " varName$=>";EVAL$(varName$);"<" wait
[button7Click] 'Set variable #main.textbox1 "!contents? varName$" varName$=trim$(varName$) if trim$(varName$)="" then #main.log "Set: Variable name is empty" wait end if if right$(varName$, 1)<>"$" then varName$=varName$+"$" 'aaa->aaa$
#main.textbox6 "!contents? varVal$" #main.log "Seting variable ";varName$ ;"to >";varVal$;"<"
#main.textbox6 "!contents? ";varName$ wait
[quit.main] 'End the program close #main end
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Nov 23, 2019 13:39:01 GMT -5
A variable has a name and has content. So while it is easy to capture the name from the textbox where are we getting the content from? What is the content of the variable named “car” An array may help but I am not understanding the problem just yet. When the content of a textbox is "car", into variable textboxContents$, can i rename the variable textboxContents$ to car$. The question : Is it possible to rename a variable into the name of the content of a textbox.
|
|
|
Post by Rod on Nov 23, 2019 14:31:49 GMT -5
No, you can get the string$ variable “car” from the textbox but you can’t use that as an ordinary Liberty variable. You might use a multi dimensional array to store the string variable “car” and store the content in beside it but processing and retrieval would be hard.
Why not tell us what the overall task is for more focused support.
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Nov 25, 2019 13:48:04 GMT -5
Thanks ntech, Rod,tsh73. "Really interesting what you want to do with it" I want to use it for "program with pictograms." A program to make little programs without coding. By clicking on a picture, you can set a few parameters.(and make/rename variables) www.youtube.com/watch?v=JXbqGyWZL0I
|
|
|
Post by Rod on Nov 25, 2019 15:13:32 GMT -5
I would use an array to hold the position of the bmp, its name and its content. Then when the user clicks on the bmp, knowing where it is drawn you can discern what bmp has been clicked and so its name and content, you may also allow the user to change the name and content. Indeed its position. So no need to create a variable just keep adding elements to an array when the user adds a .bmp
|
|
|
Post by sarmednafi on Nov 25, 2019 15:14:17 GMT -5
> Can you make a new variable when the program is running ?
That was possible using the Basic of CBM64, with the help of machine code created by the Basic program itself. Also it was possible to add DATA into DATA statement created by the program to it's Data while the program running.
Regards,
|
|
|
Post by Carl Gundel on Nov 25, 2019 15:20:30 GMT -5
I would use an array to hold the position of the bmp, its name and its content. Then when the user clicks on the bmp, knowing where it is drawn you can discern what bmp has been clicked and so its name and content, you may also allow the user to change the name and content. Indeed its position. So no need to create a variable just keep adding elements to an array when the user adds a .bmp Yeah, you can use an array. Or if you want to dynamically add new named values to your program you can use the keyed dictionary code I wrote in my blog, or something like it. ;-) Follow this link to see all the dictionary lookup blog articles along with a few others I wrote in 2016. basicprogramming.blogspot.com/2016/
|
|
|
Post by Rod on Nov 25, 2019 15:27:54 GMT -5
This is what I mean by arrays associated with bmps. It has a few elements you speak of.
dim box(64) dim nam$(64) dim con$(64) for n= 0 to 63 nam$(n)="Var;";n con$(n)="Val;";str$(n) next
' nomainwin WindowWidth = 600 WindowHeight = 600 graphicbox #1.gb 20,30,160,160 textbox #1.tb 20, 10, 160, 20 open "Button Array" for window as #1 #1 "trapclose [quit]"
'build images #1.gb "down ; backcolor darkgray ; color lightgray" #1.gb "place 0 0 ; boxfilled 20 20" #1.gb "place 10 10 ; size 2"
'make red box for n= 0 to 70 #1.gb "color ";255-n;" ";0;" ";0 #1.gb "circle ";n/8 next n #1.gb "getbmp on 0 0 20 20"
'make grey box for n= 0 to 70 #1.gb "color ";255-n;" ";255-n;" ";255-n #1.gb "circle ";n/8 next n #1.gb "getbmp off 0 0 20 20"
'draw all the boxes for x = 0 to 7 for y = 0 to 7 #1.gb "drawbmp off ";x*20;" ";y*20 next next #1.gb "flush seg"
'start event tracking #1.gb "when leftButtonUp [processchange]" #1.gb "when mouseMove [trackit]" #1.gb "setfocus"
wait
[trackit] x=int(MouseX/20) y=int(MouseY/20) #1.tb nam$(y*8+x);" ";con$(y*8+x) wait
[processchange] x=int(MouseX/20) y=int(MouseY/20) if box(y*8+x)=0 then box(y*8+x)=1 goto [showboxes] else box(y*8+x)=0 goto [clearboxes] end if
[clearboxes] #1.gb "delsegment seg" for x = 0 to 7 for y = 0 to 7 #1.gb "drawbmp off ";x*20;" ";y*20 box(y*8+x)=0 next next #1.gb "flush seg" wait
[showboxes] #1.gb "delsegment seg" for x = 0 to 7 for y = 0 to 7 if box(y*8+x)=1 then #1.gb "drawbmp on ";x*20;" ";y*20 end if next next #1.gb "flush seg" wait
[quit] close #1 end
|
|
|
Post by Rod on Nov 25, 2019 15:37:34 GMT -5
Carl's method is clever, while you are not creating a true variable you are creating a retrievable name and value held in a long string. You should play around and see what suits.
|
|
|
Post by Carl Gundel on Nov 25, 2019 16:57:57 GMT -5
Carl's method is clever, while you are not creating a true variable you are creating a retrievable name and value held in a long string. You should play around and see what suits. An even more advanced method would be to write routines to set and get values in a string with XML being the format. That way you could keep data in a structured fashion and other applications could be used to read and write it.
|
|