Results 1 to 4 of 4

Thread: Starting form from Sub Main

  1. #1

    Thread Starter
    Junior Member El-Phantasmo's Avatar
    Join Date
    Sep 2002
    Posts
    30

    Starting form from Sub Main

    Ok I have an app and I want to be able to execute from command line and from GUI.

    I created a sub main

    Code:
      Public Shared Sub main()
    
        Dim args As String() = Environment.GetCommandLineArgs()
        Dim arg As String
    
        If args.GetUpperBound(0) = 0 Then
          ' load user interaction form
          Dim f As New frmNetStat()
          f.FormLoad()
    
        Else
          frmNetStat.GetCommandLineArgs()
    
          ' process arguments
          ' no visual display is necessary
        End If
    
      End Sub
    
      Public Sub FormLoad()
        lblStatus.Text = "Awaiting command..."
        g_strConnection = "connection info..."
    ' form shows up and then exits immediately
        Me.Show() 
      End Sub
    however, the problem is it pops up the form and disappears w/o any type of input from the user

    My sub main procedure is placed just below the
    Public Sub New proc...
    public sub form load is in the main part of the code
    I did change the startup to be Sub Main and not the standard formload.

    Any ideas
    Last edited by El-Phantasmo; Sep 3rd, 2002 at 06:44 PM.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Try using the Application.Run method like this:
    VB Code:
    1. Public Shared Sub main()
    2.  
    3.     Dim args As String() = Environment.GetCommandLineArgs()
    4.     Dim arg As String
    5.  
    6.     If args.GetUpperBound(0) = 0 Then
    7.       ' load user interaction form
    8.       [b]Application.Run(New frmNetStat())[/b]
    9.  
    10.     Else
    11.       frmNetStat.GetCommandLineArgs()
    12.  
    13.       ' process arguments
    14.       ' no visual display is necessary
    15.     End If
    16.  
    17.   End Sub
    18.  
    19.   Public Sub FormLoad()
    20.     lblStatus.Text = "Awaiting command..."
    21.     g_strConnection = "connection info..."
    22. ' form shows up and then exits immediately
    23.     Me.Show()
    24.   End Sub

    You can get more info on the method in the help. Also you should just use the Form_Load event or call your FormLoad method from the Form's constructor.

  3. #3

    Thread Starter
    Junior Member El-Phantasmo's Avatar
    Join Date
    Sep 2002
    Posts
    30
    ahhh that worked great
    Thanks!

    I'll read up some more on that application.run

  4. #4

    Thread Starter
    Junior Member El-Phantasmo's Avatar
    Join Date
    Sep 2002
    Posts
    30
    ok.. new problem.
    I can't get console.writeline("some string") to actually output to console.

    I understand writeline writes to the standardoutput.

    I tried to set it with
    System.Console.SetOut(Console.Out)

    however, that didn't do a thing

    The GUI pops up fine when I don't have any parameters as it should, and it works great from command line.. but I can't get it to output text to command line.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width