Quote from Ronnie on July 7, 2019, 5:26 amHi All,
Not sure if it's my coding error, but below code doesn't work for me:
- StrLen reported value is 0 for 1st loop, subsequent is indicated as "undefined"
- ListBoxAddItem doesn't add any, and when run, extra 'blanks' items are added
- Am trying to dynamically add the minutes 00-59 into the listbox
Loop 0 59 [count]
StrLen "[count]" [res]
.jsalert "String:[sStr] | length: [res]"
If [res] <= 1
SetVar "[tmp1]" "0[sStr]"
Else
SetVar "[tmp1]" "[sStr]"
EndIf
ListBoxAddItem "cBox1" "[tmp1]" ""
EndLoop
Hi All,
Not sure if it's my coding error, but below code doesn't work for me:
Loop 0 59 [count]
StrLen "[count]" [res]
.jsalert "String:[sStr] | length: [res]"
If [res] <= 1
SetVar "[tmp1]" "0[sStr]"
Else
SetVar "[tmp1]" "[sStr]"
EndIf
ListBoxAddItem "cBox1" "[tmp1]" ""
EndLoop

Quote from luishp on July 7, 2019, 9:51 amHi @ronnie, try this instead:
ListBoxDeleteItem "cBox1" 0 ListBoxDeleteItem "cBox1" 0 Loop 0 59 [count] If [count] < 10 SetVar "[tmp1]" "0[count]" Else SetVar "[tmp1]" "[count]" EndIf ListBoxAddItem "cBox1" "[tmp1]" "" EndLoopYou can not use StrLen with a numeric variable.
There is a bug on ListBox object that automatically adds empty values when there are no values added at design time, but you can easily fix it using ListBoxDeleteItem before inserting new values.Best regards.
Hi @ronnie, try this instead:
ListBoxDeleteItem "cBox1" 0
ListBoxDeleteItem "cBox1" 0
Loop 0 59 [count]
If [count] < 10
SetVar "[tmp1]" "0[count]"
Else
SetVar "[tmp1]" "[count]"
EndIf
ListBoxAddItem "cBox1" "[tmp1]" ""
EndLoop
You can not use StrLen with a numeric variable.
There is a bug on ListBox object that automatically adds empty values when there are no values added at design time, but you can easily fix it using ListBoxDeleteItem before inserting new values.
Best regards.
Quote from Ronnie on July 8, 2019, 1:27 am@luishp
Thanks for the info. It’d be good to have StrLen support numerical texts too. Oh, while it’s easy to implement via plugin or scripting code, you might want to add StrLeft, StrRight, StrMid as well to complete the Strings function.
Thanks once again....
Thanks for the info. It’d be good to have StrLen support numerical texts too. Oh, while it’s easy to implement via plugin or scripting code, you might want to add StrLeft, StrRight, StrMid as well to complete the Strings function.
Thanks once again....
Quote from Gaev on July 8, 2019, 5:06 am@ronnie
It’d be good to have StrLen support numerical texts too.
What would be the length of ...
123
0123
00123
-123
-0123
123.45
-0123.45you might want to add StrLeft, StrRight, StrMid as well to complete the Strings function.
StrMid - SubStr "source string" "start position" "length" "variable"
StrLeft - SubStr "source string" "0" "length" "variable"
StrRight - use StrLen, Math to compute "start position" in SubStr
It’d be good to have StrLen support numerical texts too.
What would be the length of ...
123
0123
00123
-123
-0123
123.45
-0123.45
you might want to add StrLeft, StrRight, StrMid as well to complete the Strings function.
StrMid - SubStr "source string" "start position" "length" "variable"
StrLeft - SubStr "source string" "0" "length" "variable"
StrRight - use StrLen, Math to compute "start position" in SubStr

Quote from luishp on July 8, 2019, 7:52 amPlease note that this doesn't work:
SetVar [myvar] 12345 StrLen "[myvar]" [length]But this works:
SetVar [myvar] 12345 SetVar [myvar2] [myvar]+"" StrLen "[myvar2]" [length]I have just added an empty string at the end of the number to conver it into a string.
Anyway I will add this to StrLen so it's done automatically.
Please note that this doesn't work:
SetVar [myvar] 12345 StrLen "[myvar]" [length]
But this works:
SetVar [myvar] 12345 SetVar [myvar2] [myvar]+"" StrLen "[myvar2]" [length]
I have just added an empty string at the end of the number to conver it into a string.
Anyway I will add this to StrLen so it's done automatically.
Quote from Ronnie on July 8, 2019, 4:47 pm@Luishp
Thanks for the workaround. I was just thinking of perhaps to use javascript to create a simple IntegerToString command. Guess your workaround is fast, even if you add that into the next version, the +”” would her no impact too. Great!
@gaev
was the StrLeft, StrRight, and StrMid already available, as I don’t see them included? Otherwise it is very easy to create similar functions in javascript, but thought having such functions as part of the “Strings” library would be cleaner.
Thanks for the workaround. I was just thinking of perhaps to use javascript to create a simple IntegerToString command. Guess your workaround is fast, even if you add that into the next version, the +”” would her no impact too. Great!
was the StrLeft, StrRight, and StrMid already available, as I don’t see them included? Otherwise it is very easy to create similar functions in javascript, but thought having such functions as part of the “Strings” library would be cleaner.
Quote from Gaev on July 8, 2019, 5:04 pm@ronnie:
was the StrLeft, StrRight, and StrMid already available, as I don’t see them included?
No ... what I meant was that ...
StrMid is the same as the SubStr command (which is documented in the Help file)
StrLeft is the same as the SubStr command with starting position of zero
StrRight can also be accomplished by using SubStr ... the starting position can be computed using StrLen and Math commands
@ronnie:
was the StrLeft, StrRight, and StrMid already available, as I don’t see them included?
No ... what I meant was that ...
StrMid is the same as the SubStr command (which is documented in the Help file)
StrLeft is the same as the SubStr command with starting position of zero
StrRight can also be accomplished by using SubStr ... the starting position can be computed using StrLen and Math commands
Quote from Ronnie on July 9, 2019, 6:12 am@gaev
OK.. understood what you meant.... thanks
Aside to @luishp
- Tried your suggestion. But each time the ListBox included 2-3 empty rows before the item starts with 00-59 (for minutes). I tried searching for "" value and delete them... but to no use.
- How do I pre-set index/item in ListBox to be the current selected one. Assuming the ListBox has [selectedMinute] as variable, I tried adding statement like SetVar [SelectedMinute] [NAB.Minute], nothing was 'highlighted on the listbox. Maybe a ListBoxSetItem [value/index] might be better?
OK.. understood what you meant.... thanks
Aside to @luishp

Quote from luishp on July 9, 2019, 7:13 amHi @ronnie,
You are right, some more functionality should be added to ListBox and fix some issues.
Meanwhile please take a look at the attached sample. Includes a little bit of JavaScript to preset the selected value.
(right click to save it).Regards.
Hi @ronnie,
You are right, some more functionality should be added to ListBox and fix some issues.
Meanwhile please take a look at the attached sample. Includes a little bit of JavaScript to preset the selected value.
(right click to save it).
Regards.
Uploaded files: