vbCity
Migrating to the new kind of Visual Basic Developer Community

Need help to close the program and run the form

Latest post 03-20-2009 12:13 AM by XTab. 9 replies.
  • 03-18-2009 11:45 AM

    Need help to close the program and run the form

    Hi guys

    I am created two projects with two different executive files, which the one are for the normal program to create and the other one is for an update. I want to separate these dialogs. I have already added the update executive file as reference in my program. I would like you to help me to resolve this issue as I have problem with open the update dialog when I clicked on the menu item. When I clicked the menu item which are suppose to close the program and load the update form from the update executive file but they did not show up.




    Code:

        Private Sub updatetest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updatetest.Click
            Me.Close()
            End
            Dim update As New testUpdate.testUpdates
            update.ShowDialog()
        End Sub




    Please can you help me how do I correct my statements which I would close the program and run the update form??



    Thanks,
    Stephen
     
  • 03-18-2009 12:00 PM In reply to

    Re: Need help to close the program and run the form

    Since you are using 2 separate .exe programs, I would suggest:


    Code:


    Private Sub updatetest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updatetest.Click

         Dim myprocess as new System.Diagnostics.Process()

        myprocess.startinfo.filename = "c:\somepath\processname.exe"
        myprocess.start

       Application.Exit()

    End Sub


  • 03-18-2009 12:24 PM In reply to

    Re: Need help to close the program and run the form

    Thanks for this, but I would like to have short statement to get the executive file instead of this:




    Code:

    myprocess.StartInfo.FileName = My.Application.Info.DirectoryPath + "\bin\testupdate.exe"





    I have tried to correct the statement but I got an warning message which the system cannot find the file specified.




    Any idea how to refix this??



    Thanks,
    Stephen
     
  • 03-18-2009 12:46 PM In reply to

    Re: Need help to close the program and run the form

    In VB .NET you can't use the "+" to concatenate:


    Code:
    myprocess.StartInfo.FileName = My.Application.Info.DirectoryPath + "\bin\testupdate.exe"


    should be:


    Code:
    myprocess.StartInfo.FileName = My.Application.Info.DirectoryPath & "\bin\testupdate.exe"

  • 03-18-2009 1:05 PM In reply to

    Re: Need help to close the program and run the form

    Thanks but it is still the same. Any idea??





    Thanks,
    Stephen
     
  • 03-18-2009 1:34 PM In reply to

    Re: Need help to close the program and run the form

    What is the path for My.Application.Info.DirectoryPath? Use MyComputer and check if the executable exists in that \bin\
  • 03-18-2009 2:12 PM In reply to

    Re: Need help to close the program and run the form

    The executable are already exists in the bin folder. I have also tried this:


    Code:

    myprocess.StartInfo.FileName = My.Computer.FileSystem.CurrentDirectory & "testupdate.exe"





    Still get the same error "The system cannot find the file specified".




    Any idea??



    Thanks,
    Stephen
     
  • 03-19-2009 1:12 PM In reply to

    Re: Need help to close the program and run the form

    do anyone know how to refix this??
     
  • 03-20-2009 12:06 AM In reply to

    • XTab
    • Not Ranked
    • Joined on 02-21-2002
    • Dumfries, Scotland
    • Posts 8,585

    Re: Need help to close the program and run the form

    If you keep getting that message, it's 99% that the file isn't in what you think is the CurrentDirectory. (Or there is an error in the filename).

    Try this to check:

      
    Code:
    Console.WriteLine(My.Computer.FileSystem.CurrentDirectory.ToString)


    ----------------------------------------------------------------------------
    XTab : Microsoft MVP (Visual Developer - Visual Basic)
    For (Sometimes) Useful Hints and Tips, Check Out My VBCity Blog
             

  • 03-20-2009 12:13 AM In reply to

    • XTab
    • Not Ranked
    • Joined on 02-21-2002
    • Dumfries, Scotland
    • Posts 8,585

    Re: Need help to close the program and run the form

    Another way of testing for the existence:



    Code:
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Console.WriteLine(My.Computer.FileSystem.CurrentDirectory.ToString)
            Dim str As String = My.Computer.FileSystem.CurrentDirectory.ToString & "\MyFile.exe"
            If Not System.IO.File.Exists(str) Then
                MessageBox.Show(str & " does not exist")
            End If

        End Sub


    ----------------------------------------------------------------------------
    XTab : Microsoft MVP (Visual Developer - Visual Basic)
    For (Sometimes) Useful Hints and Tips, Check Out My VBCity Blog
             

Page 1 of 1 (10 items) | RSS
Copyright 1998-2009 vbCity.com LLC