none
Run a program in silent mode?

    Question

  •  

    I'm working on an application which I have migrated from VB6 into .NET 1.1.  Part of the code causes the program to run silently if it is run from a command-line or batch file.  Here's the old code:

     

     

    If Command$ = "/RUN" And AutoRun <> True Then
        Form1.Show
        AutoRun = True
        Command1_Click
    End If

    What I want to do is the same thing in .NET 1.1.  I'm not exactly sure how to write the proper code.  Thanks.

    Thursday, October 04, 2007 3:16 PM

Answers

  • pblecha,

     

    Based on your post, the code snippet runs when AutoRun is false. The form is opened firstly, you can write the code in VB.NET like Me.Show(). When the form shows, the AutoRun becomes True, then the Command1_Click() sub is called. During the procedure, you can do nothing this is so called "silent mode".

     

    I would like to suggest you as follows:

     

    1. Please define AutoRun as Boolean, make the sub named Command_Click() as the following code snippet:

     

    Code Block

        Private Sub Test()

            Dim AutoRun As Boolean

            If Command() = "/RUN" And AutoRun <> True Then

                Me.Show()

                AutoRun = True

                Command1_Click()

            End If

        End Sub

     

        Sub Command1_Click()

            'Your code here

        End Sub

     

     

    2. Since the code snippet runs without any communication with the user, you can define some MsgBox or the "Run" switch. For example, you can put the TextBox, Button on the form shown, then generate the customer's input. In the Switch statement, you can try to write some selections for the user input, such as /Run, /Stop.

     

    Hope that can provide you some idea.

    Tuesday, October 09, 2007 6:37 AM
  • That's a bit tricky in .NET 1.1, it doesn't have the Form.Shown event.  Your button's Click event will run before the form is visible. Try it like this:

    Public Class Form1
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If String.Compare(Command(), "/run", True) = 0 Then
          Me.BeginInvoke(New MethodInvoker(AddressOf InvokeClick))
        End If
      End Sub
      Private Sub InvokeClick()
        Command1.PerformClick()
      End Sub
      Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command1.Click
        MsgBox("Click!")
      End Sub
    End Class
    Tuesday, October 09, 2007 11:33 AM
    Moderator

All replies

  • pblecha,

     

    Based on your post, the code snippet runs when AutoRun is false. The form is opened firstly, you can write the code in VB.NET like Me.Show(). When the form shows, the AutoRun becomes True, then the Command1_Click() sub is called. During the procedure, you can do nothing this is so called "silent mode".

     

    I would like to suggest you as follows:

     

    1. Please define AutoRun as Boolean, make the sub named Command_Click() as the following code snippet:

     

    Code Block

        Private Sub Test()

            Dim AutoRun As Boolean

            If Command() = "/RUN" And AutoRun <> True Then

                Me.Show()

                AutoRun = True

                Command1_Click()

            End If

        End Sub

     

        Sub Command1_Click()

            'Your code here

        End Sub

     

     

    2. Since the code snippet runs without any communication with the user, you can define some MsgBox or the "Run" switch. For example, you can put the TextBox, Button on the form shown, then generate the customer's input. In the Switch statement, you can try to write some selections for the user input, such as /Run, /Stop.

     

    Hope that can provide you some idea.

    Tuesday, October 09, 2007 6:37 AM
  • That's a bit tricky in .NET 1.1, it doesn't have the Form.Shown event.  Your button's Click event will run before the form is visible. Try it like this:

    Public Class Form1
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If String.Compare(Command(), "/run", True) = 0 Then
          Me.BeginInvoke(New MethodInvoker(AddressOf InvokeClick))
        End If
      End Sub
      Private Sub InvokeClick()
        Command1.PerformClick()
      End Sub
      Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command1.Click
        MsgBox("Click!")
      End Sub
    End Class
    Tuesday, October 09, 2007 11:33 AM
    Moderator