|
-
Feb 17th, 2006, 08:43 PM
#1
Thread Starter
New Member
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.
-
Feb 17th, 2006, 08:49 PM
#2
Re: How to return a val
You would have to call the ExitProcess API function for that.
VB Code:
Private Declare Sub ExitProcess Lib "kernel32.dll" (ByVal uExitCode As Long)
-
Feb 17th, 2006, 10:00 PM
#3
Re: How to return a val
Or just a simple function.
VB Code:
Public Function MyFunction() As Integer
If SomeCondition Then
MyFunction = 1024
Else
MyFunction = 0
End If
End Function
-
Feb 17th, 2006, 10:04 PM
#4
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.
-
Feb 18th, 2006, 12:41 PM
#5
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:
Private Sub Form_Unload(Cancel As Integer)
Call ExitProcess(1024) '<-or whatever you want to return
End Sub
-
Feb 18th, 2006, 12:55 PM
#6
Thread Starter
New Member
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.
-
Feb 18th, 2006, 01:10 PM
#7
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 .
-
Feb 18th, 2006, 09:21 PM
#8
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|