Post by darencraddock on Dec 20, 2008 9:52:52 GMT -5
I came across a problem today with a project while trying to jump to a branch point from within a for/next loop.
Reason: I was writing code to dynamically create a new Table in an SQLite database. My code asks the user to enter the number of fields, then runs a For/Next loop to enable naming and selecting data-type of each new field.
For selecting data-type, I used a listbox (with some choices), followed by a button ("Click to Select Data-Type"), followed by a WAIT command.
After a user clicks the button, it should be a straight-forward job to jump to a branch (or Sub), or even simply to the next line of code, to store the selected data-type. This works well when not in a For/Next loop, but I couldn't get it to work in a loop.
The problem occurs because Branches are locally scoped. My program could not recognise a Branch inside my For/Next loop!
Solution: jump to a 'dummy' branch outside the scope of the current loop/procedure! This worked great! The dummy branch doesn't 'do' anything, but simply enables the program to pause at a point within a loop, then continue after a user has clicked a button (or link).
Example:
Cheers! ;D
Reason: I was writing code to dynamically create a new Table in an SQLite database. My code asks the user to enter the number of fields, then runs a For/Next loop to enable naming and selecting data-type of each new field.
For selecting data-type, I used a listbox (with some choices), followed by a button ("Click to Select Data-Type"), followed by a WAIT command.
After a user clicks the button, it should be a straight-forward job to jump to a branch (or Sub), or even simply to the next line of code, to store the selected data-type. This works well when not in a For/Next loop, but I couldn't get it to work in a loop.
The problem occurs because Branches are locally scoped. My program could not recognise a Branch inside my For/Next loop!
Solution: jump to a 'dummy' branch outside the scope of the current loop/procedure! This worked great! The dummy branch doesn't 'do' anything, but simply enables the program to pause at a point within a loop, then continue after a user has clicked a button (or link).
Example:
For m = 1 to NumberOfFields
'select datatype
dim dataTypes$(26)
dataTypes$(0) = "BIGINT"
dataTypes$(1) = "BLOB"
dataTypes$(2) = "BOOLEAN"
etc etc etc ...
'create listbox
listbox #dataTypes, dataTypes$(), 1
'set selected data-type
#dataTypes select("VARCHAR")
'create link to enable selection to be stored
link #storeNewFieldType, "Select", [dummyBranch]
wait
'code to store selected data-type, eg
arrayNewFieldType$(m) = #dataTypes selection$()
Next m
'here's the dummy branch!
[dummyBranch]
End
Cheers! ;D