passing a parameter to a VB.net class (newbie)

D

DivB

Hello,

I have this working class:
Option Strict Off
Option Explicit On
Friend Class Super
Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "

Public Sub New()
MyBase.New()

(...)

I want to pass a command-line parameter. But there's no Sub main() function
on this class. How can I achieve that?

Thanks in advance,
Pablo SV
 
H

Herfried K. Wagner [MVP]

DivB said:
Friend Class Super
Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "

Public Sub New()
MyBase.New()

(...)

I want to pass a command-line parameter. But there's no Sub main()
function on this class. How can I achieve that?

Add the code below to the form and select 'Sub Main' as startup object in
the project properties:

\\\
Public Shared Sub Main(ByVal Args() As String)
For Each Arg As String In Args
Console.WriteLine(Arg)
Next Arg
Application.Run(New Super())
End Sub
///
 
D

DivB

For Each Arg As String In Args
The compiler tells me:

Arg : not declared (should I use Dim?)

As : syntax error

Thanks in advance,
Pablo SV
 
K

Ken Tucker [MVP]

Hi,

For Each strArg As String In Environment.GetCommandLineArgs
Debug.WriteLine(strArg)
Next


Ken
---------------
"DivB" <divbyz at g mail.com> wrote in message
Hello,

I have this working class:
Option Strict Off
Option Explicit On
Friend Class Super
Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "

Public Sub New()
MyBase.New()

(...)

I want to pass a command-line parameter. But there's no Sub main() function
on this class. How can I achieve that?

Thanks in advance,
Pablo SV
 
A

Armin Zingler

DivB said:
For Each Arg As String In Args The compiler tells me:

Arg : not declared (should I use Dim?)

As : syntax error



You are probably still using VB 2002. Change it to:

Dim Arg As String

For Each Arg In Args


Armin
 

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