|
Post by regoroxford on Dec 16, 2022 13:17:00 GMT -5
The var$ variable in Liberty Basic help file seemed to lend itself to what I'm showing here. iterable checkbox data should save some typing for big project.
'nomainwin 'set the foreground and background colors BackgroundColor$ = "cyan" ForegroundColor$ = "black" dim cb$(20) : dim cbstatus$(20)
'create a window with a bunch of checkboxes 'The [] are not functional to create check vs nocheck mark status 'They need to be present as place holders; [dummy] followed by wait would suffice checkbox #1.red, "Red",[dummy] ,[dummy], 10, 10, 400, 24 checkbox #1.blue, "Blue", [dummy] ,[dummy] , 10, 35, 400, 24 checkbox #1.green, "Green", [dummy] ,[dummy] , 10, 60, 400, 24 checkbox #1.yellow, "Yellow", [dummy] ,[dummy], 10, 85, 400, 24 checkbox #1.cyan, "Cyan", [dummy] ,[dummy], 10, 110, 400, 24
UpperLeftX = 150 UpperLeftY = 150 WindowWidth = 190 WindowHeight = 260
open "The new handle variable way" for window as #1 print #1,"trapclose [quit]"
UpperLeftX = 420 UpperLeftY = 520 WindowWidth = 190 WindowHeight = 160
menu #2, "Setting check boxes", "Set all", [setall], "Reset all", [resetall], "quit", [quitFromMenu] open "The new handle variable way" for window as #2 wait
[setall] for x = 1 to 5 var$ = "#1."+word$("red blue green yellow cyan", x) 'print var$ #var$ "set" next x wait
[resetall] for x = 1 to 5 var$ = "#1."+word$("red blue green yellow cyan", x) 'print var$ #var$ "reset" next x wait [dummy] wait
[quit] 'iterable checkbox summary for k = 1 to 5 var$ = "#1."+word$("red blue green yellow cyan", k ) print #var$, "value?" 'this pair input #var$, t$ 'goes together cb$(k)= var$ : cbstatus$(k) =t$ next k print "Checkbox handle ";" Status " for k= 1 to 5 print tab(3);k;" ";cb$(k);tab(18);cbstatus$(k) next k close #1 close #2 end [quitFromMenu] close #1 close #2 end
|
|
|
Post by Walt Decker on Dec 17, 2022 12:53:26 GMT -5
There is a much easier way to do that. Change all of the branch labels to the same sub: checkbox #1.red, "Red", RDO.SET ,RDO.SET , 10, 10, 400, 24 checkbox #1.blue, "Blue", RDO.SET, RDO.SET, 10, 35, 400, 24 ETC. ----------------------------------------- -----------------------------------------
SUB RDO.SET RdoHndl$ IsSet$ = "" PRINT #RdoHndl$, "VALUE?, IsSet$" IF IsSet$ = "set" THEN '<--- DO SOMETHING ---> END IF END SUB
|
|
|
Post by regoroxford on Dec 17, 2022 13:38:27 GMT -5
Walt I tried to run your script after open a window as #1, but no cigar for me. it looks like the sub will put check mark in place; one checkbox at a time. I was posting an edit to the code placed earlier when I noticed your response. I thought a for next loop to generate data about checkboxes was unique; using the var$ variable. I don't yet know if var$ is sacred or reserved. When my code is terminated with the X, a summary of checkbox status is printed on the screen.
|
|
|
Post by Rod on Dec 17, 2022 14:00:39 GMT -5
I am not sure you are understanding the difference between var$ and #var$ where var$ contents starts with #handle
This is a special handle variable that can access controls like checkboxes and buttons that are named #handle
Like #main.cb can be accessed directly with the literal #main.cb OR accessed by a handle variable with the contents var$=“#main.cb” when the var$ is then preceded by #
So then #var$ will actually access #main.cb
|
|
|
Post by tsh73 on Dec 17, 2022 15:07:55 GMT -5
regoroxford,
Magic happens then string variable contains valid control handle like var$="#1.yellow" then you can use it instead of handle so
#1.yellow "set" or
#var$ "set" works the same. And you can use any variable name. I often use handle$.
Also if you name your checkboxes with numbers, like
checkbox #1.chk1 checkbox #1.chk2 ... you can easily use
for x = 1 to 5 var$ = "#1.chk";x #var$ "set" next x
|
|
|
Post by tsh73 on Dec 17, 2022 15:09:12 GMT -5
Walt, comma after question mark in
PRINT #RdoHndl$, "VALUE?, IsSet$" is extra - command does not work with it
Should be
PRINT #RdoHndl$, "VALUE? IsSet$"
|
|
|
Post by Walt Decker on Dec 17, 2022 16:02:40 GMT -5
Yes, that comma gets me every time. Too used to other languages.
' DIM CkState$(4, 1)
checkbox #1.red, "Red", CHK.SET ,CHK.SET, 10, 10, 400, 24 checkbox #1.blue, "Blue", CHK.SET, CHK.SET, 10, 35, 400, 24 checkbox #1.green, "Green", CHK.SET, CHK.SET, 10, 60, 400, 24 checkbox #1.yellow, "Yellow", CHK.SET, CHK.SET, 10, 85, 400, 24 checkbox #1.cyan, "Cyan", CHK.SET, CHK.SET, 10, 110, 400, 24
UpperLeftX = 150 UpperLeftY = 150 WindowWidth = 190 WindowHeight = 260
open "The new handle variable way" for window as #1 print #1,"trapclose [quit]"
UpperLeftX = 420 UpperLeftY = 520 WindowWidth = 190 WindowHeight = 160
menu #2, "Setting check boxes", "Set all", [setall], "Reset all", [resetall], "quit", [quitFromMenu] open "The new handle variable way" for window as #2 #2, "TRAPCLOSE [quitFromMenu]" [BEGIN.WAIT] wait
'------------------------------------- '-------------------------------------
[setall] for x = 0 to 4 IsSet$ = "#1." + WORD$("red blue green yellow cyan", x + 1) CkState$(x, 0) = IsSet$ CkState$(x, 1) = "1" #IsSet$ "set" next x GOTO [BEGIN.WAIT] [END.SETALL]
'------------------------------------- '-------------------------------------
[resetall] for x = 0 to 4 IsSet$ = "#1." + WORD$("red blue green yellow cyan", x + 1) CkState$(x, 0) = IsSet$ CkState$(x, 1) = "1" #IsSet$ "reset" next x GOTO [BEGIN.WAIT] [END.RESET.ALL]
'------------------------------------- '-------------------------------------
SUB CHK.SET ChkHndl$
IsSet$ = "" #ChkHndl$, "VALUE? IsSet$"
SELECT CASE ChkHndl$ CASE "#1.red" IF IsSet = "set" THEN CkState$(0, 1) = "1" EXIT SUB END IF CkState$(0, 1) = "0" CASE "#1.blue" IF IsSet = "set" THEN CkState$(1, 1) = "1" EXIT SUB END IF CkState$(1, 1) = "0" CASE "#1.green" IF IsSet = "set" THEN CkState$(2, 1) = "1" EXIT SUB END IF CkState$(2, 1) = "0" CASE "#1.yellow" IF IsSet = "set" THEN CkState$(3, 1) = "1" EXIT SUB END IF CkState$(3, 1) = "0" CASE "#1.cyan IF IsSet = "set" THEN CkState$(4, 1) = "1" EXIT SUB END IF CkState$(4, 1) = "0" END SELECT
'------------------------------------- '-------------------------------------
[quit] 'iterable checkbox summary
print "Checkbox handle ";" Status "
for k = 0 to 4 print tab(3);k + 1;" ";CkState$(k, 0); tab(18); CkState$(k, 1) next k close #1 close #2 end
'------------------------------------- '-------------------------------------
[quitFromMenu] close #1 close #2 end
'
|
|
|
Post by xxgeek on Dec 17, 2022 17:12:12 GMT -5
Walt, your new code has a few errors as well. A few of these IF IsSet = "set" THEN IsSet is a string and there was no end sub Fixed in code below. Walt are you staying up all night working on the Form generator? I've been suffering the same symptoms and notice them in others when I see them DIM CkState$(4, 1)
checkbox #1.red, "Red", CHK.SET ,CHK.SET, 10, 10, 400, 24 checkbox #1.blue, "Blue", CHK.SET, CHK.SET, 10, 35, 400, 24 checkbox #1.green, "Green", CHK.SET, CHK.SET, 10, 60, 400, 24 checkbox #1.yellow, "Yellow", CHK.SET, CHK.SET, 10, 85, 400, 24 checkbox #1.cyan, "Cyan", CHK.SET, CHK.SET, 10, 110, 400, 24
UpperLeftX = 150 UpperLeftY = 150 WindowWidth = 190 WindowHeight = 260
open "The new handle variable way" for window as #1 print #1,"trapclose [quit]"
UpperLeftX = 420 UpperLeftY = 520 WindowWidth = 190 WindowHeight = 160
menu #2, "Setting check boxes", "Set all", [setall], "Reset all", [resetall], "quit", [quitFromMenu] open "The new handle variable way" for window as #2 #2, "TRAPCLOSE [quitFromMenu]" [BEGIN.WAIT] wait
'------------------------------------- '-------------------------------------
[setall] for x = 0 to 4 IsSet$ = "#1." + WORD$("red blue green yellow cyan", x + 1) CkState$(x, 0) = IsSet$ CkState$(x, 1) = "1" #IsSet$ "set" next x GOTO [BEGIN.WAIT] [END.SETALL]
'------------------------------------- '-------------------------------------
[resetall] for x = 0 to 4 IsSet$ = "#1." + WORD$("red blue green yellow cyan", x + 1) CkState$(x, 0) = IsSet$ CkState$(x, 1) = "1" #IsSet$ "reset" next x GOTO [BEGIN.WAIT] [END.RESET.ALL]
'------------------------------------- '-------------------------------------
SUB CHK.SET ChkHndl$
IsSet$ = "" #ChkHndl$, "VALUE? IsSet$"
SELECT CASE ChkHndl$ CASE "#1.red" IF IsSet$ = "set" THEN CkState$(0, 1) = "1" EXIT SUB END IF CkState$(0, 1) = "0"
CASE "#1.blue" IF IsSet$ = "set" THEN CkState$(1, 1) = "1" EXIT SUB END IF CkState$(1, 1) = "0" CASE "#1.green" IF IsSet$ = "set" THEN CkState$(2, 1) = "1" EXIT SUB END IF CkState$(2, 1) = "0" CASE "#1.yellow" IF IsSet$ = "set" THEN CkState$(3, 1) = "1" EXIT SUB END IF CkState$(3, 1) = "0" CASE "#1.cyan" IF IsSet$ = "set" THEN CkState$(4, 1) = "1" EXIT SUB END IF CkState$(4, 1) = "0" END SELECT end sub '------------------------------------- '-------------------------------------
[quit] 'iterable checkbox summary
print "Checkbox handle ";" Status "
for k = 0 to 4 print tab(3);k + 1;" ";CkState$(k, 0); tab(18); CkState$(k, 1) next k close #1 close #2 end
'------------------------------------- '-------------------------------------
[quitFromMenu] close #1 close #2 end
'
|
|
|
Post by Walt Decker on Dec 17, 2022 17:35:09 GMT -5
No. I have a couple of issues; a couple of weeks ago I was in the hospital for some preliminary work on my 80+ year old pump and have not completely recovered. Also my peepers are getting worse. Last eye checkup put me about 90% blind in the left eye and 80% in the right. Thanks for fixing the code. I appreciate all the help I can get.
PS: With a little API magic code in the SUB can be reduced to about six lines.
|
|
|
Post by xxgeek on Dec 17, 2022 18:33:31 GMT -5
Well, that sucks, not only for you, but the entire community. Please do post a version with "API magic code" "API magic code" doesn't scare me. After X-Mas I intend to purchase LB Pro as a gift to myself. P.S. If I 'can' help I will. No need to ask. Merry Christmas Walt
|
|
|
Post by Walt Decker on Dec 17, 2022 19:23:02 GMT -5
A little API magic: ' DIM CkState$(4, 1)
GLOBAL RdoLo
CtlHndl = 0
checkbox #1.red, "Red", CHK.SET ,CHK.SET, 10, 10, 400, 24 checkbox #1.blue, "Blue", CHK.SET, CHK.SET, 10, 35, 400, 24 checkbox #1.green, "Green", CHK.SET, CHK.SET, 10, 60, 400, 24 checkbox #1.yellow, "Yellow", CHK.SET, CHK.SET, 10, 85, 400, 24 checkbox #1.cyan, "Cyan", CHK.SET, CHK.SET, 10, 110, 400, 24
UpperLeftX = 150 UpperLeftY = 150 WindowWidth = 190 WindowHeight = 260
open "The new handle variable way" for window as #1 print #1,"trapclose [quit]"
'============================================================== ' With the exception of menus, every control has both a numeric ' handle and an integer identification (ID) number. The below is one ' way to retrieve the integer ID. '==============================================================
CtlHndl = HWND(#1.red) CALLDLL #user32, "GetDlgCtrlID", CtlHndl AS ULONG, RdoLo AS LONG
UpperLeftX = 420 UpperLeftY = 520 WindowWidth = 190 WindowHeight = 160
menu #2, "Setting check boxes", "Set all", [setall], "Reset all", [resetall], "quit", [quitFromMenu] open "The new handle variable way" for window as #2 #2, "TRAPCLOSE [quitFromMenu]" [BEGIN.WAIT] wait
'------------------------------------- '-------------------------------------
[setall] for x = 0 to 4 IsSet$ = "#1." + WORD$("red blue green yellow cyan", x + 1) CkState$(x, 0) = IsSet$ CkState$(x, 1) = "1" #IsSet$ "set" next x GOTO [BEGIN.WAIT] [END.SETALL]
'------------------------------------- '-------------------------------------
[resetall] for x = 0 to 4 IsSet$ = "#1." + WORD$("red blue green yellow cyan", x + 1) CkState$(x, 0) = IsSet$ CkState$(x, 1) = "1" #IsSet$ "reset" next x GOTO [BEGIN.WAIT] [END.RESET.ALL]
'------------------------------------- '-------------------------------------
SUB CHK.SET ChkHndl$
IsSet$ = "" Hndl = 0 Indx = 0
#ChkHndl$, "VALUE? IsSet$"
'==================================================== ' Retrieve the handle and ID of the control that was ' activated. ' Subtract the ID from the GLOBAL RdoLo variable to ' arrive at the CkState$() element. '====================================================
Hndl = HWND(#ChkHndl$) CALLDLL #user32, "GetDlgCtrlID", Hndl AS ULONG, Indx AS LONG Indx = Indx - RdoLo
IF IsSet$ = "set" THEN CkState$(Indx, 1) = "1" EXIT SUB END IF
CkState$(Indx, 1) = "0"
end sub
'------------------------------------- '-------------------------------------
[quit] 'iterable checkbox summary trace 2 print "Checkbox handle ";" Status "
for k = 0 to 4 print tab(3);k + 1;" ";CkState$(k, 0); tab(18); CkState$(k, 1) next k close #1 close #2 end
'------------------------------------- '-------------------------------------
[quitFromMenu] close #1 close #2 end
'
|
|
|
Post by xxgeek on Dec 17, 2022 19:51:28 GMT -5
That works, no problems.
Note to others: If you want to see the results, close the window with the checkboxes instead of the other one.
|
|
|
Post by Walt Decker on Dec 18, 2022 10:00:27 GMT -5
By setting up a function the code footprint can be reduced even more. In the set and reset menu blocks, remove the code and place it in a function, then pass either zero or 1 to the function, e. g. ' [setall]
RetVal = FN.DoSet(1)
GOTO [BEGIN.WAIT] [END.SETALL]
FUNCTION FN.DoSet(SetFlag)
for I = 0 to 4 IsSet$ = "#1." + WORD$("red blue green yellow cyan", I + 1) CkState$(I, 0) = IsSet$ IF SetFlag = 1 THEN CkState$(I, 1) = "1" #IsSet$ "set" ELSE CkState$(I, 1) = "0" #IsSet$ "reset" END IF next I END FUNCTION '
PS. By using the NUMBERMAN.DLL the memory usage can be reduced by replacing the ChkState$() array with a single variable, setting the appropriate bits in that variable and then checking the bit state in the summation. No additional code would be needed.
|
|