Command line arguments and form processing

G

Guest

Hello Everyone,

I have this little app, that I would like to configure two modes of
operation by using command line arguments. If the app is started with no
arguments, the Main UserForm shows up, if the app is started with an argument
of -q it runs in Quiet Mode. Where a form pops up, runs the process I need
run without user intervention and then closes. I'm having a problem when the
app runs with -q, it starts the Quiet Mode form... but doesn't process any of
the code for the next steps I need run. Can someone help me out. I have
posted pertinent code snippets below.

-----------------------------------------------------
Module ProgramCode
Public Sub Main(ByVal CmdArgs() As String)
If (CmdArgs Is Nothing) OrElse (CmdArgs.Length = 0) Then
Application.Run(New frmMain)
ElseIf CmdArgs(0).Trim.ToLower = "-q" Then
Application.Run()
Dim quietForm As New frmQuiet
quietForm.QuietModeProcess()
End If
End Sub
End Module
-------------
Public Class frmQuiet
Inherits System.Windows.Forms.Form
Const applicationName = "OFAC File Generator"

#Region " Windows Form Designer generated code "
#End Region

Public Sub QuietModeProcess()
MsgBox("Now Procecssing Quiet Mode Steps", MsgBoxStyle.Information,
applicationName)
End Sub

End Class
 
K

Ken Tucker [MVP]

Hi,

You code will create the quiet form, tell it to run your procedure,
and end because there is no code to keep the program going. Two possible
solutions for this. First run you code for the quiet mode in sub main.
Second application.run the quiet form. In the form load procedure call the
the quietmode procedure. When you are done with the quiet mode code close
the form so the program will end.

Ken
-------------
Hello Everyone,

I have this little app, that I would like to configure two modes of
operation by using command line arguments. If the app is started with no
arguments, the Main UserForm shows up, if the app is started with an
argument
of -q it runs in Quiet Mode. Where a form pops up, runs the process I need
run without user intervention and then closes. I'm having a problem when
the
app runs with -q, it starts the Quiet Mode form... but doesn't process any
of
the code for the next steps I need run. Can someone help me out. I have
posted pertinent code snippets below.

-----------------------------------------------------
Module ProgramCode
Public Sub Main(ByVal CmdArgs() As String)
If (CmdArgs Is Nothing) OrElse (CmdArgs.Length = 0) Then
Application.Run(New frmMain)
ElseIf CmdArgs(0).Trim.ToLower = "-q" Then
Application.Run()
Dim quietForm As New frmQuiet
quietForm.QuietModeProcess()
End If
End Sub
End Module
-------------
Public Class frmQuiet
Inherits System.Windows.Forms.Form
Const applicationName = "OFAC File Generator"

#Region " Windows Form Designer generated code "
#End Region

Public Sub QuietModeProcess()
MsgBox("Now Procecssing Quiet Mode Steps", MsgBoxStyle.Information,
applicationName)
End Sub

End Class
 
Z

Zoury

Hi Dubya ! :O)

Application.Run() kicks start the main message loop of an
application.Calling it without any parameters means that you start a message
loop on the current thread, so IOW, you enter in a infinite loop...

How about this ?
'***
Module ProgramCode
Public Sub Main(ByVal CmdArgs() As String)
If (CmdArgs Is Nothing) OrElse (CmdArgs.Length = 0) Then
Application.Run(New frmMain)
ElseIf CmdArgs(0).Trim.ToLower = "-q" Then
Application.Run(New frmQuiet)
End If
End Sub
End Module
'***
Public Class frmQuiet
Inherits System.Windows.Forms.Form

Const applicationName = "OFAC File Generator"

#Region " Windows Form Designer generated code "
#End Region

Public Sub frmQuiet_Load()

' moves the form out of the screen..
' Me.Hide() or Me.Visible = False doesn't seems to work
' within the Load() event. I tried them in the Activated() event
' but we can see Form disappear which is ugly
Me.Location = New Point(-10000, 0)

' Launch our quiet mode code
QuietModeProcess()

' Don't forget to call this method when your done.. since
' the form won't be there for you to close it.
Application.Exit()

End Sub

Private Sub QuietModeProcess()
MsgBox("Now Procecssing Quiet Mode Steps", MsgBoxStyle.Information,
applicationName)
End Sub

End Class
'***

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top