Results 1 to 8 of 8

Thread: Exit in sub main?

  1. #1

    Thread Starter
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Post

    It's early in the morning and my brain has not started yet.

    My App starts in sub Main and there I make a check to see if a PLC is connected to "com2" if not I will show a MSGBOX and tehn I wanna exit the program.
    Since no forms are loaded yet I cant use unload, is exit the correct way to end the program ore what should I use.
    I know I'm supposed to know this but as I said, It's early in the morning



    ------------------
    On Error Goto Bed :0)
    [email protected]



  2. #2
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    Since you have no forms open you should be able to just use End to stop the program running.



    ------------------
    Mark "Buzby" Beeton
    VB Developer
    [email protected]



  3. #3

    Thread Starter
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Post

    Thank You

    ------------------
    On Error Goto Bed :0)
    [email protected]



  4. #4
    Member
    Join Date
    Apr 1999
    Posts
    38

    Post

    You should NEVER use the End statement in your code !!!!!!!!!


    I suppose you have a MSComm control on a form to communicate with the PLC.
    When you access the properties or methods of the MSComm control, the form it is placed on is loaded (but not shown)!

    Therefore you have to unload that form and when all forms are unloaded, the program will end by itself !!!

  5. #5

    Thread Starter
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Post

    Hello Fredrik
    Im not usin MScomm in my app, its using a DLL that was shipped with the PLC (SIOX) and the first thing I do is trying to initiate the serial com-port to communicate with the SIOX.
    If this initiation fails then it return an error and its here I wanna show a msgbox and then Exit my app.

    What do you suggest I use if the initiation fails, since no forms are loaded yet?
    I need to make sure that my app is totaly unloaded from the memory.


    ------------------
    On Error Goto Bed :0)
    [email protected]



  6. #6
    Member
    Join Date
    Apr 1999
    Posts
    38

    Post

    When there are no forms loaded into memory and your application reaches the end sub line of your Sub Main routine, the application should terminate automatically.

    When this is not the case, this means that there must be loaded something into the memory.

    This is the case when you access f.ex. a control's properties:
    The control is places on a form and when you access its properties, the form is automatically loaded.


    So you should check if there is anything loaded.

    A way to check this is to write something (MsgBox "Form Loaded") in the Form_Load event of each form.

    Like this, a message box appears each time a form is loaded.

    When you notice that a form is loaded, you can implicitly unload the form by the command 'unload FormName'

    [This message has been edited by Frederik Gekiere (edited 02-04-2000).]

  7. #7

    Thread Starter
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Post

    OK
    Lets see if I got this right.

    I should check for the return value of the initiate function and If no error is returned then I should carry on with my startup tasks Else I should let the program do nothing after the end if and then it WILL
    terminate itself leaving nothing in the memory when it reaches End Sub.

    OK that is great if it works that way, but now my boss has decided that if we get an error in return in the initiate secuense than we will start another demoApp and "unload" the main app.
    How will this affect my program, will it still "unload" my App when it reaches the end sub line, since it have not loaded any forms yet?
    The demoApp is located in another directory.

    Thank you

    ------------------
    On Error Goto Bed =:0)
    [email protected]

    [This message has been edited by onerrorgoto (edited 02-07-2000).]

  8. #8
    Member
    Join Date
    Apr 1999
    Posts
    38

    Post

    When you start the other application (I guess that will be by using the Shell function ??) and your program reaches End Sub, normally your program should stop while the other program (the one started with the shell function) continues running.

    You should check it out yourself by testing it ...

    You can see in the task manager which programs are running.
    When your program has stopped running, all memory resources used by the program will automatically be cleared.

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