Results 1 to 8 of 8

Thread: How to return a val

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    7

    Cool How to return a val

    Hello.

    We can use "return val;" to make the program(which is cimpiled by C++)return specific value in C & C++, for example:

    C++ source code:
    -----------------------------------------------------------------------

    #include<iostream.h>
    main()
    {
    cout<<"The exe returns a value before ends.">>
    return 1024;
    }
    -----------------------------------------------------------------------

    So, the compiled exe will return 1024 other programs before exit.

    My question is, how can i do in VB6 to return a value like this?
    wether if i hava to call API?
    Notice: The val is not return by a function. It is return by the whole program, so that other program(s) can receive it. I am a VB and English learner, so, I hope you can know what I say.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: How to return a val

    You would have to call the ExitProcess API function for that.
    VB Code:
    1. Private Declare Sub ExitProcess Lib "kernel32.dll" (ByVal uExitCode As Long)

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: How to return a val

    Or just a simple function.

    VB Code:
    1. Public Function MyFunction() As Integer
    2.  
    3.     If SomeCondition Then
    4.         MyFunction = 1024
    5.     Else
    6.         MyFunction = 0
    7.     End If
    8.  
    9. End Function

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: How to return a val

    But he wanted to have an exit value. Return a value to the OS, which is not the same thing as letting a function return a value to the caller.

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: How to return a val

    Hmmm... If you wanted more help you should just have asked... Giving me a negative rep just because I didn't show exactly how you would call the API function was a bit harch in my opinion . In Form_Unload event:
    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2.     Call ExitProcess(1024) '<-or whatever you want to return
    3. End Sub

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    7

    Re: How to return a val

    Thank you very very much, Joacim Andersson! It is a good idea to use ExitProcess API function.
    Another question is:
    My programs always use a lot of memory, althought they are simple. For example:
    Windows task manager show that the thread "Explore.exe" use 4,196K memory. but one of my vb program use as much as 5,110K. How can I write efficient code? Can you give me some advice? Or some links to recommended webs?
    Thanks in advance.

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: How to return a val

    If you start a new standard EXE project and compile it without writing a single line of code but still keep the Form that is created this program will take up approx. 2.5MB of memory... This is unfortunatly something VB does because of the run-time files that is always linked, but that doesn't mean it actually takes up 2.5 MB of your RAM. The run-time library is only loaded once into the physical memory regardless of how many VB programs you're running, but each process will add this memory to the virtual memory space. So you shouldn't worry about it .

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    7

    Re: How to return a val

    Oh...I see...Hah...It cheats me...
    Thank you!

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