Announcement

Collapse
No announcement yet.

GOSUB + switches

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Guest's Avatar
    Guest replied
    Thanks for the tips, guys!

    ------------------

    Leave a comment:


  • Allen B. Zilbert
    replied
    Hi Bruce,

    Here is an example of a parsing routine.

    Allen

    $DIM ALL

    REM First Parameter: Number of items on command line
    REM Second Parameter: Storage for parse items
    REM Third Parameter: Parse delimiter

    OPTION ARRAY BASE 1

    DECLARE SUB Parse (INTEGER, STRING ARRAY, STRING)
    DECLARE SUB Test (INTEGER, STRING ARRAY)

    DIM Arg(10) AS STRING, ArgNo AS INTEGER

    Parse ArgNo, Arg(), "/"
    Test ArgNo, Arg()

    END

    SUB Parse (ArgNo AS INTEGER, Arg() AS STRING, ParChar AS STRING)
    DIM Cmd AS LOCAL STRING, Ctr AS LOCAL INTEGER
    DIM StartSpot AS LOCAL INTEGER, EndSpot AS LOCAL INTEGER
    LET Cmd = COMMAND$
    LET ArgNo = TALLY(Cmd, ParChar)
    LET StartSpot = INSTR(Cmd, ParChar)
    FOR Ctr = 1 TO ArgNo - 1
    LET EndSpot = INSTR(StartSpot + 1, Cmd, ParChar) - StartSpot - 1
    LET Arg(Ctr) = RTRIM$(MID$(Cmd, StartSpot + 1, EndSpot))
    LET StartSpot = INSTR(StartSpot + 1, Cmd, ParChar)
    NEXT Ctr
    LET Arg(Ctr) = RTRIM$(MID$(Cmd, StartSpot + 1))
    END SUB

    SUB test (ArgNo AS INTEGER, Arg() AS STRING)
    DIM Ctr AS LOCAL INTEGER
    FOR Ctr = 1 TO ArgNo
    PRINT Arg(Ctr)
    NEXT Ctr
    END SUB


    ------------------

    Leave a comment:


  • Lance Edmonds
    replied
    PARSE$ is in PB/CC and PB/DLL only... sorry!

    The ARGC and ARGV code should easily suffice though. However, for simple command-line parsing, the INSTR() function works quite well:
    Code:
    a$ = UCASE$(COMMAND$)
    IF INSTR(a$, "/QUICK") THEN ...
    IF INSTR(a$, "/SYSTEM") THEN ...
    ...

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Jerry Fielden
    replied
    My last version of PBDos was 3.0 and it doesn't have PARSE$.
    I really don't know about 3.2 or 3.5 it may have it. If it
    does, the following should do COMMAND line strings.

    Code:
         commands$ = " /Format=A: /Quick /System"
         REPLACE ANY "/" WITH "," IN commands$
         First$ = PARSE$(commands$, 2)
         Second$ = PARSE$(commands$, 3)
         Third$ = PARSE$(commands$, 4)
         
         PRINT First$
         PRINT Second$
         PRINT Third$
    ------------------

    Leave a comment:


  • Scott Slater
    replied
    Originally posted by Bruce Lindstrom:
    Also, about command line switches, does anybody have a neat
    little working subroutine which extracts multiple switches with
    arguments?

    Like for example;

    Myprog.EXE /Format=A: /Quick /System


    Thanks for reading!

    Hi Bruce,

    In the PB35\EXAMPLE directory there is a file called DOSUNIT.BAS
    and in that file there are the functions ArgV and ArgC
    that are for command line stuff. One returns the number of arguments
    and the other returns a specific argument.



    ------------------
    Scott Slater
    Summit Computer Networks
    www.summitcn.com

    Leave a comment:


  • Allen B. Zilbert
    replied
    Bruce,

    Try using the GOSUB with the DWORD option along with the
    DWDVAR. You will have to set the DWDVAR to a CODEPTR32.

    Allen

    Here some sample code.

    DIM proc as DWORD
    LET proc = CODEPTR32(HELLO)
    GOSUB DWORD proc
    END

    HELLO:
    PRINT "Hi"
    RETURN



    ------------------

    Leave a comment:


  • Guest's Avatar
    Guest started a topic GOSUB + switches

    GOSUB + switches

    Hi!

    Is it in anyway possible to GOSUB alt. GOTO a label which is a
    string? If not, is there any other ways to do this?

    String$="Test"
    GOSUB String$

    Also, about command line switches, does anybody have a neat
    little working subroutine which extracts multiple switches with
    arguments?

    Like for example;

    Myprog.EXE /Format=A: /Quick /System


    Thanks for reading!

    ------------------
Working...
X