|
Post by ptitjoz on Feb 22, 2018 19:10:18 GMT 1
Hello I try to convert a string to an instruction. Example: I have 6 ENTRY entree1=ENTRY("a", 120, 25) entree2=ENTRY("b", 120, 25) etc. Currently I use this code which is not optimized SUB SubReinit TEXT(entree1,"") TEXT(entree2,"") TEXT(entree3,"") TEXT(entree4,"") TEXT(entree5,"") TEXT(entree6,"")
END SUB So, I try to clean all ENTRY with a routine SUB SubReinit LOCAL i% TYPE NUMBER LOCAL ent$ TYPE STRING FOR i%=1 TO 6 ent$="entree"&STR$(i%) PRINT ent$ TEXT(ent$," ") NEXT END SUB
But I have this message : I guess I have to use something else ... EVAL? Thank you for your advice Regards
|
|
|
Post by Pjot on Feb 26, 2018 15:20:21 GMT 1
Dear ptitjoz, Sorry for my late response but I have overlooked this question. The way you would like to reset an ENTRY cannot be done with something like EVAL, as there is no such functionality in the C language. Compilers usually have a hard time to execute code during runtime because it would require an embedded interpreter to do so. Alternatively, you can use an array (see program below). Note that arrays in C are 0-based, so an array of 6 elements ranges from 0-5. You can set a different base using the OPTION BASE statement. Best regards Peter INCLUDE "hug.bac", INIT, WINDOW, ENTRY, ATTACH, TEXT, BUTTON, DISPLAY, CALLBACK
DECLARE entree ARRAY 6
SUB SubReinit
LOCAL i TYPE NUMBER
FOR i = 0 TO 5 TEXT(entree[i], " ") NEXT
END SUB
INIT
win = WINDOW("Testing ENTRY", 600, 400)
but = BUTTON("Click here", 120, 30) ATTACH(win, but, 300, 10) CALLBACK(but, SubReinit)
entree[0]=ENTRY("a", 120, 25) entree[1]=ENTRY("b", 120, 25) entree[2]=ENTRY("a", 120, 25) entree[3]=ENTRY("b", 120, 25) entree[4]=ENTRY("a", 120, 25) entree[5]=ENTRY("b", 120, 25)
ATTACH(win, entree[0], 10, 10) ATTACH(win, entree[1], 10, 40) ATTACH(win, entree[2], 10, 70) ATTACH(win, entree[3], 10, 100) ATTACH(win, entree[4], 10, 130) ATTACH(win, entree[5], 10, 160)
DISPLAY
|
|
|
Post by ptitjoz on Feb 28, 2018 9:29:35 GMT 1
Hello Peter Thank you for your answer. There is never an urgency to answer me. So thank you very much for your explanations and for the example you give, it helps me a lot. Regards
|
|