QB64 Phoenix Edition
Command$(count%) - I can't get a value when using the optional argument "(count%)" - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: Command$(count%) - I can't get a value when using the optional argument "(count%)" (/showthread.php?tid=3876)



Command$(count%) - I can't get a value when using the optional argument "(count%)" - Unatic - 08-21-2025

Please see the complete program below, and the results of running it with the parameter    one two three.
I do not get a value in the optional argument (count1%).  it is always zero.   Am I reading the WIKI wrong to think that the variable count1% should also contain the value 3 after running the program.

Thanks in advance........


Option _Explicit
Dim cmd$, count1%, count2%
Open "text.txt" For Output As #1
cmd$ = Command$(count1%)
count2% = _CommandCount

Print #1, "Command$="; cmd$
Print #1, "Command$ elements1 cntr  ="; count1%
Print #1, "CommandCount$ elements2  ="; count2%
Print #1, "Command$(0)="; Command$(0)
Print #1, "Command$(1)="; Command$(1)
Print #1, "Command$(2)="; Command$(2)
Print #1, "Command$(3)="; Command$(3)
Print #1, "Command$(4)="; Command$(4)
End


Command$=D:\QBTest\CommandUse.exe
Command$ elements1 cntr  = 0
CommandCount$ elements2  = 3
Command$(0)=D:\QBTest\CommandUse.exe
Command$(1)=one
Command$(2)=two
Command$(3)=three
Command$(4)=


RE: Command$(count%) - I can't get a value when using the optional argument "(count%)" - bplus - 08-22-2025

Option _Explicit
Dim cmd$, count1%, count2%
Open "text.txt" For Output As #1
cmd$ = Command$(count1%) ' <<< this is saying cmd$ = Command$(0) because you never assigned count1% !!!
' just as this line reports!!!
Print #1, "Command$ elements1 cntr  ="; count1% ' = 0

count1% is always 0 because you don't make it anything other.


RE: Command$(count%) - I can't get a value when using the optional argument "(count%)" - hsiangch_ong - 08-22-2025

why do you need two variables?  to determine how many parameters.  are passed from the command line?

Code: (Select All)
Option _Explicit
Dim cmd$, count1%
Open "text.txt" For Output As #1
count1% = _CommandCount
cmd$ = Command$(count1%)
'rest of program
':
that's all there is to it.

if you need the length of the entire command line, use len() on the string.


RE: Command$(count%) - I can't get a value when using the optional argument "(count%)" - Unatic - 08-22-2025

Thank you for the help and explanation.  My tired old eyes were reading the WIKI incorrectly.....





(08-22-2025, 12:49 AM)bplus Wrote: Option _Explicit
Dim cmd$, count1%, count2%
Open "text.txt" For Output As #1
cmd$ = Command$(count1%) ' <<< this is saying cmd$ = Command$(0) because you never assigned count1% !!!
' just as this line reports!!!
Print #1, "Command$ elements1 cntr  ="; count1% ' = 0

count1% is always 0 because you don't make it anything other.