Passing Parameters to VB.NET Apps

  • Thread starter Thread starter Malosita
  • Start date Start date
M

Malosita

Hi!

I have a small app with 2 forms. The first one requires users to login
and once they do the second one presents several combo boxes and text
boxes for them to select certain data. I need to schedule this
application to run several times a week without user intervention.

What would be the best way for me to accomplish this? How can I pass
the parameters I need?

Thank you!
Malosita
 
Hi,

the best way to pass parameters is creating a tiny Main static method. I
think you can create it even in the form class. In the form source file,
enter the following:

Public Shared Sub Main(Params As String())

'Create the form instance
Dim loginForm As New Form1

'Fill the two textboxes with data from the command line
loginForm.txtUsername = Params(0)
loginForm.txtPassword = Params(1)

'Show the form and let the application run
loginForm.Show()
Application.Run(loginForm)

End Sub

I assumed the class for the login form is called "Form1" and that the two
textboxes are txtUsername and txtPassword. Also I assumed you passed name
and password as first and second parameters, like this: myapp.exe username
password

Remember to set your project (in project properties) to start from the
Form1.Main, instead of loading Form1 directly.

Hope this helps.
 
Back
Top