dcsimg
Results 1 to 10 of 10

Thread: How to run opened form Directly?

  1. #1

    Thread Starter
    Registered User
    Join Date
    Dec 2013
    Posts
    2

    How to run opened form Directly?

    I have a project in which i have added hundreds of forms....is there any way by which i can directly run(execute) opened form without changing in 'sub main' option?

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,605

    Re: How to run opened form Directly?

    Either Sub Main is executed or the Form you have specified.
    You can find this in "Project Properties -> General -> Statup Object"

  3. #3
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: How to run opened form Directly?

    I'm not quite sure if something like the following is what you seek:

    Code:
    Option Explicit
    
    Private Sub Main()
        Dim sCmdLine As String
    
        sCmdLine = Command$
    
        If LenB(sCmdLine) Then
            On Error GoTo 1
            Forms.Add(sCmdLine).Show
        Else
    1       Form1.Show
        End If
    End Sub
    Command line example:

    Code:
    C:\>Project1.exe Form2
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,073

    Re: How to run opened form Directly?

    How would you do that if the Project1 is not on C and the path has spaces and special characters?

    Example: F:/some - folder/some folder/some folder/Project1.exe Form2


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  5. #5
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: How to run opened form Directly?

    You'll have to enclose the path in quotation marks. Here's a command line example:

    Code:
    C:\>"F:\some - folder\some folder\some folder\Project1.exe" Form2
    Windows doesn't allow the following characters as part of a file or folder's name:

    \ / : * ? " < > |
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  6. #6
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,073

    Re: How to run opened form Directly?

    OK, that works but why did you put Form1.Show in your code example?

    How to .Show the correct Form without explicitly stating it?

    Example:

    Code:
      '
      '
    If LenB(sCmdLine) Then
            On Error GoTo 1
            Forms.Add(sCmdLine).Show
        Else
    1       Form1.Show <--- HERE. HOW TO SHOW THE SAME FORM AS SPECIFIED IN COMMAND LINE
        End If


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  7. #7
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,423

    Re: How to run opened form Directly?

    Are you serious? 8000 posts and you're not even able to succesfully read a simple if statement? Don't you see that code means that if a command line parameter is passed then it's used as Form name inside the If and the Form with that name is then shown?
    Code:
    Forms.Add(sCmdLine).Show
    Form1.Show line is only executed when no parameter is passed, this is where you'll set the default Form to show.
    Last edited by jcis; Dec 10th, 2013 at 08:49 PM.

  8. #8
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: How to run opened form Directly?

    The Forms.Add(sCmdLine).Show line does the job of showing the Form whose name was specified at the command line. The Forms collection has a method called "Add" that accepts a Form's name and returns a newly created instance of that Form.

    Form1.Show loads and displays the default Form (Form1 in this example) in case there was no command line argument passed (LenB(sCmdLine) = 0) or the argument(s) was/were an invalid Form name (On Error GoTo 1).



    EDIT

    Didn't see jcis' post.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  9. #9
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,346

    Re: How to run opened form Directly?

    Quote Originally Posted by Bonnie West View Post
    (On Error GoTo 1)
    I didn't know that "On Error GoTo" could disregard "Else", etc such as in the example in post #3, interesting.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  10. #10
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: How to run opened form Directly?

    Quote Originally Posted by Nightwalker83 View Post
    I didn't know that "On Error GoTo" could disregard "Else", etc such as in the example in post #3, interesting.
    Yes. GoTo can direct program flow to any desired executable line in a procedure and it often results in spaghetti code when abused.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width