VB 4 questions 
Author Message
 VB 4 questions

(1)
-How do you check for ARGs from the command line (i.e. Dos prompt or RUN
option in Start menu) and then process them. I've seen an
option/function called "Command" but not sure if that allows for parsing
of the args?
(i.e. if exists use values, if not set your own), and then sends the
appropriate output to a DOS prompt/window (as opposed to a popup
"windows" window)?
Ex:
"Program.exe argname argcount"
and the VB program processes the arguments and writes out several text
lines to Dos window.

(2)
-In VB 4 can you run a function with two other functions as the
parameters (as opposed to variable values) so that the functions IN the
parenthesis are run first and therefore if successful, return values
back to the first function to perfom its code?
(i.e. trying to simulate C, Pascal coding in VB)

ex:
Main routine:
func1(func2,func3)

func2:
-checks to see if a first ARG is passed
if so, returns a value)
if not, sets an alternate value

func3:
-checks to see if a second ARG is passed
if so, returns a value)
if not, sets an alternate value
---

SO, the first func uses the first two "returned" values to perform it's
own code with those values.



Sat, 02 Sep 2000 03:00:00 GMT  
 VB 4 questions

On Tue, 17 Mar 1998 11:21:14 -0500, "Mike S. Nowostawsky"

Quote:

>(1)
>-How do you check for ARGs from the command line (i.e. Dos prompt or RUN
>option in Start menu) and then process them. I've seen an
>option/function called "Command" but not sure if that allows for parsing
>of the args?
>(i.e. if exists use values, if not set your own), and then sends the
>appropriate output to a DOS prompt/window (as opposed to a popup
>"windows" window)?
>Ex:
>"Program.exe argname argcount"
>and the VB program processes the arguments and writes out several text
>lines to Dos window.

Just did a parsing of four parameters passed by a batch file calling
the program.

Example:
    Dim C_string as string

    C_String = Trim(Command$)

    'Extract each parameter from the command string
   'First param
    If InStr(1, C_String, " ", 1) > 0 Then
        Pos = InStr(1, C_String, " ", 1)
        import_ship$ = Trim(Left(C_String, Pos))
        C_String = Right(C_String, Len(C_String) - (Pos))
    End If
   'Second param
    If InStr(1, C_String, " ", 1) > 0 Then
        Pos = InStr(1, C_String, " ", 1)
        export_ship$ = Trim(Left(C_String, Pos))
        C_String = Right(C_String, Len(C_String) - (Pos))
    End If
   'Third param
    If InStr(1, C_String, " ", 1) > 0 Then
        Pos = InStr(1, C_String, " ", 1)
        import_look$ = Trim(Left(C_String, Pos))
        C_String = Right(C_String, Len(C_String) - (Pos))
    End If
   'Last param
    export_look$ = Trim(C_String)

    'Catch for parameter missing (check each file)
    If FileExists(import_ship$) Then......

Function FileExists(ByVal strFileName As String) As Boolean

    Dim iFile As Integer

    iFile = FreeFile
    On Error Resume Next
    Open strFileName For Input As iFile
    Close iFile
    FileExists = (Err = 0) Or (Err = 55)
    On Error GoTo 0

End Function

Hope that helps

Nicole Ewing
Programmer/Playtex Apparel, Inc

If responding by Email, please use this address, not
the one in the message header:

(SPAM protection - take out XYZ)



Sat, 02 Sep 2000 03:00:00 GMT  
 VB 4 questions

Quote:

>-How do you check for ARGs from the command line (i.e. Dos prompt or RUN
>option in Start menu) and then process them. I've seen an
>option/function called "Command" but not sure if that allows for parsing
>of the args?

You use the Command$ function to get the entire string that was entered on
the command line. You would then need to parse the line using Instr to
search for the delimiters (most often a space, /, or -) or a particular
string and then Mid$() to break out the parts you need.

Quote:
>-In VB 4 can you run a function with two other functions as the
>parameters (as opposed to variable values) so that the functions IN the
>parenthesis are run first and therefore if successful, return values
>back to the first function to perfom its code?

Yes, if I understand you correctly. Here's a {*filter*} example....

Option Explicit

Private Sub Form_Load()
   Debug.Print func3(func1(), func2())
End Sub

Private Function func1() As Integer
   func1 = 10
End Function

Private Function func2() As Integer
   func2 = 20
End Function

Private Function func3(arg1 As Integer, arg2 As Integer) As Integer
   func3 = arg1 + arg2
End Function

Frank Carr



Sun, 03 Sep 2000 03:00:00 GMT  
 VB 4 questions

Quote:

>     Dim C_string as string

>     C_String = Trim(Command$)

>     'Extract each parameter from the command string
>    'First param
>     If InStr(1, C_String, " ", 1) > 0 Then
>         Pos = InStr(1, C_String, " ", 1)
>         import_ship$ = Trim(Left(C_String, Pos))
>         C_String = Right(C_String, Len(C_String) - (Pos))
>     End If
>   ...

Yeah, I did something similar. Was hoping I didn't have to use INSTR to parse
it (was hoping there was a system variable for each ARG .. like in Unix's

better than nothing.

thx,



Sun, 03 Sep 2000 03:00:00 GMT  
 VB 4 questions

You use the Command$ function to get the entire string that was entered on

Quote:
> the command line. You would then need to parse the line using Instr to
> search for the delimiters (most often a space, /, or -) or a particular
> string and then Mid$() to break out the parts you need.

> >-In VB 4 can you run a function with two other functions as the

yeah, I figured that (did it that way). Was hoping I didn't have to parse them
myself though with INSTR (some other languages have system vars that do that..

Quote:
> Yes, if I understand you correctly. Here's a {*filter*} example....

> Option Explicit

> Private Sub Form_Load()
>    Debug.Print func3(func1(), func2())
> End Sub

> Private Function func1() As Integer
>    func1 = 10
> End Function

> Private Function func2() As Integer
>    func2 = 20
> End Function

> Private Function func3(arg1 As Integer, arg2 As Integer) As Integer
>    func3 = arg1 + arg2
> End Function

Hmm.. that might do it.. I'll try it

thx,



Sun, 03 Sep 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. vb : Memory Question in vb Please Respond

2. VB 6.0 + VB 4.0 Questions

3. Easy VB Programming Questions From VB Newbie

4. Simple VB Code Question

5. VB Code question

6. VB/ODBC question

7. easy VB coding question

8. Writing to a Word document in VB - performance question

9. OUTLOOK AND VB + MAPI QUESTION

10. VB Excel Question

11. VB.Net Question

12. VB 6.0 Question

 

 
Powered by phpBB® Forum Software