Page 1 of 1

console program

Posted: Wed Jun 16, 2010 11:30 am
by angelian
why this code does not work?

Code: Select all

Global rarpath.s, jpgpath.s
cmdline.s
Procedure set_path(string.s)
    Select LCase(GetExtensionPart(string))
      Case "rar", "zip", "jar"
         rarpath = string
      Case "jpg", "jpeg", "png"
         jpgpath = string
    EndSelect
EndProcedure

CountParam=CountProgramParameters()

If CountParam = 2
  For i=0 To CountParam-1
   cmdline=cmdline+ProgramParameter(i)+Chr(10)
  Next i
      lineparam1.s = Left(cmdline, FindString(cmdline, Chr(10), 0)-1)
      lineparam2.s = RemoveString( cmdline, lineparam1+Chr(10))     
    MessageRequester("path", lineparam1+Chr(10)+lineparam2)
      set_path(lineparam2)
      set_path(lineparam1)
    MessageRequester("path", "jpg: "+jpgpath+Chr(10)+"rar: "+rarpath)
EndIf
but this works!

Code: Select all

Global rarpath.s, jpgpath.s
cmdline.s

Procedure set_path(string.s)
     Select LCase(GetExtensionPart(string))
       Case "rar", "zip", "jar"
          rarpath = string
       Case "jpg", "jpeg", "png"
          jpgpath = string
     EndSelect
 EndProcedure
 
CountParam=CountProgramParameters()
If CountParam = 2
  For i=1 To CountParam
   set_path(ProgramParameter(i-1))
  Next i
   MessageRequester("jpg+rar",jpgpath+Chr(10)+rarpath)
  End
EndIf

Re: console program

Posted: Thu Jun 17, 2010 12:36 am
by PureLeo
Both seem to work here.

Re: console program

Posted: Thu Jun 17, 2010 10:31 pm
by angelian
The second code correctly handles both arguments. But the first code loses the last argument.
Variable rarpath is empty.

Re: console program

Posted: Fri Jun 18, 2010 1:48 am
by PureLeo
It seems in the second code you just used set_path(ProgramParameter(i-1)) which will get exactly the first and second parameters...

In the first code, if you look at the variable viewer, the vars are:
(I used xxx.jpg and xxx.rar)

lineparam1 = "xxx.jpg"
lineparam2 = "xxx.rarChr(10)" (you get a line break there)

This works fine:

Code: Select all

      lineparam1.s = Left(cmdline, FindString(cmdline, Chr(10), 0)-1)
      lineparam2.s = RemoveString( cmdline, lineparam1+Chr(10))
      lineparam2.s = RemoveString( lineparam2, Chr(10)); *******

Re: console program

Posted: Fri Jun 18, 2010 1:54 am
by Jihugen
PureLeo was faster than me ;)
Well, I'm posting my answer anyway. Seems to be the same idea than Leo's.

Here is my an idea (just an idea, I have not tested):
With the loop on cmdline=cmdline+ProgramParameter(i)+Chr(10)
you'll get at the end:
cmdline = cmd1 + chr(10) + cmd2 + chr(10)
Then you extract cmd1 with Left(...), ok.
Then you extract cmd2 with RemoveString(...), not ok. I think here your result will be cmd2 + chr(10), not cmd2 as you expected.
So next, when you'll call your set_path() proc, the Case "jpg", "jpeg", "png" will never be verified, because of the trailing Chr(10).

Re: console program

Posted: Fri Jun 18, 2010 2:18 am
by PureLeo
Jihugen explained it better...

Instead of my last code you could just use

Code: Select all

 lineparam1.s = StringField(cmdline,1,Chr(10))
 lineparam2.s = StringField(cmdline,2,Chr(10))
Much better :)

Re: console program

Posted: Fri Jun 18, 2010 8:45 am
by angelian
Thanks for your help!