简体   繁体   中英

What is the best way for grabbing command line arguments in vb.net

I have done this a few times in c#, but for vb.net do I use My.Application.CommandLineArgs as follows or is there a better way?

Dim argListArray As New ArrayList

For Each argument As String In My.Application.CommandLineArgs
    argListArray.Add(argument)
Next

If argListArray.Count = 5 Then
    ImageName = argListArray(0).ToString            
    ImageAddress = argListArray(1).ToString 
    ImagePort = argListArray(2).ToString 
    FileLoc = argListArray(3).ToString 
    JPEGQuality = argListArray(4).ToString  
Else
    'TODO invalid # args

End If

Agreed...just use My.Application.CommandLineArgs directly:

    If My.Application.CommandLineArgs.Count = 5 Then
        ImageName = My.Application.CommandLineArgs(0)
        ImageAddress = My.Application.CommandLineArgs(1)
        ImagePort = My.Application.CommandLineArgs(2)
        FileLoc = My.Application.CommandLineArgs(3)
        JPEGQuality = My.Application.CommandLineArgs(4)
    Else
        ' TODO invalid # args
    End If

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM