console program

Just starting out? Need help? Post your questions and find answers here.
User avatar
angelian
New User
New User
Posts: 5
Joined: Tue Jun 08, 2010 1:08 pm

console program

Post 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
User avatar
PureLeo
Enthusiast
Enthusiast
Posts: 221
Joined: Fri Jan 29, 2010 1:05 pm
Location: Brazil

Re: console program

Post by PureLeo »

Both seem to work here.
User avatar
angelian
New User
New User
Posts: 5
Joined: Tue Jun 08, 2010 1:08 pm

Re: console program

Post by angelian »

The second code correctly handles both arguments. But the first code loses the last argument.
Variable rarpath is empty.
User avatar
PureLeo
Enthusiast
Enthusiast
Posts: 221
Joined: Fri Jan 29, 2010 1:05 pm
Location: Brazil

Re: console program

Post 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)); *******
Last edited by PureLeo on Fri Jun 18, 2010 2:17 am, edited 5 times in total.
Jihugen
User
User
Posts: 45
Joined: Mon Jun 07, 2010 11:36 pm
Location: Normandy, France

Re: console program

Post 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).
User avatar
PureLeo
Enthusiast
Enthusiast
Posts: 221
Joined: Fri Jan 29, 2010 1:05 pm
Location: Brazil

Re: console program

Post 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 :)
User avatar
angelian
New User
New User
Posts: 5
Joined: Tue Jun 08, 2010 1:08 pm

Re: console program

Post by angelian »

Thanks for your help!
Post Reply