At the risk of someone who sounds like they dont know anything:
How do you declare a procedure as void in VB.net?
And where do i declare it?
Dan
VB.NET ARGH!!!!
- Topher
- Legit Extremist
- Posts: 301
- Joined: Sun May 01, 2005 11:29 am
- Location: Temple of the Rat
- Contact:
Declare it as void?
A procedure is generally going to be called from somewhere.
If you are wanting a procedure to basically never run no matter what calls it, then as the first line of your procedure put this:
Exit Sub
That will exit out of the procedure before any code below it runs.
Not sure why you'd want to do this though.
Hope this helps.
A procedure is generally going to be called from somewhere.
If you are wanting a procedure to basically never run no matter what calls it, then as the first line of your procedure put this:
Exit Sub
That will exit out of the procedure before any code below it runs.
Not sure why you'd want to do this though.
Hope this helps.
- Topher
- Legit Extremist
- Posts: 301
- Joined: Sun May 01, 2005 11:29 am
- Location: Temple of the Rat
- Contact:
Ok, you could create your own custom Sub Procedure like this:
The above code creates a procedure called Close_Me
When called from anywhere in the current form (or class), it will run the statement Me.Close which just closes the current form. Or completly exits the program if it's the only form in the app.
I'm still not sure what you mean by declaring it void though. This procedure will never be run unless it's called so in that case, you wouldn't really need to mark it as void.
However, a Sub Procedure never returns a value, a Funtion Procedure does though.
Functions are a tad more complicated to explain than Sub Procedures. You can declare a function with the following code:
What the above code does is creates a function called Boost. Functions are sort of treated like variables in that you assign them a type. In this case we're creating the function Boost as an Integer (whole number).
The (ByVal i as Integer) means that this function is expecting an argument to be passed when the function is called and it's going to assign that argument to the variable "i" as an integer. so in this case we'd pass a number as an argument to the function.
To call this function from any procedure, we'd use the following code:
Now what the above code does is first it creates an integer variable called ReturnedBoost to hold the value that will be passed back from the Boost Function.
Then it assigns the value to ReturnedBoost by calling the Boost function and passing an argument of 4.
The ending result will be that the ReturnedBoost variable will now have a value of 5 because the funtion took the argument of 4 and added 1 to it, and returned 5 when the function closed. Make Sense?
As for making a function void so it doesn't return a value, I don't think VB supports that. I could be wrong though because I'm not a programmer by profession, I just code for hobby.
Sorry for the long winded post. I hope it helped.
Code: Select all
Private Sub Close_Me()
Me.Close()
End Sub
When called from anywhere in the current form (or class), it will run the statement Me.Close which just closes the current form. Or completly exits the program if it's the only form in the app.
I'm still not sure what you mean by declaring it void though. This procedure will never be run unless it's called so in that case, you wouldn't really need to mark it as void.
However, a Sub Procedure never returns a value, a Funtion Procedure does though.
Functions are a tad more complicated to explain than Sub Procedures. You can declare a function with the following code:
Code: Select all
Private Function Boost(ByVal i as Integer) as Integer
Boost = i + 1
End Function
The (ByVal i as Integer) means that this function is expecting an argument to be passed when the function is called and it's going to assign that argument to the variable "i" as an integer. so in this case we'd pass a number as an argument to the function.
To call this function from any procedure, we'd use the following code:
Code: Select all
Dim ReturnedBoost as Integer
ReturnedBoost = Boost(4)
Then it assigns the value to ReturnedBoost by calling the Boost function and passing an argument of 4.
The ending result will be that the ReturnedBoost variable will now have a value of 5 because the funtion took the argument of 4 and added 1 to it, and returned 5 when the function closed. Make Sense?
As for making a function void so it doesn't return a value, I don't think VB supports that. I could be wrong though because I'm not a programmer by profession, I just code for hobby.
Sorry for the long winded post. I hope it helped.
Sorry, my fault for posting my original question without regard for clarification!
What I was after was the sub procedure thing.
With C++ you have to declare your sub procedures before you can use them (though you probably know that!) and the first time on VB.net i tried to call a procedure (without any declaration) and it gave me an error.
So i thought you had to define the sub procedures first. But you dont!
So I've just removed the sub procedure for now and it works! (I think it was because i had referenced something without passing it to the procedure)
I'll be back asking for more help if it doesnt work next time i want a procedure!
Dan
What I was after was the sub procedure thing.
With C++ you have to declare your sub procedures before you can use them (though you probably know that!) and the first time on VB.net i tried to call a procedure (without any declaration) and it gave me an error.

So i thought you had to define the sub procedures first. But you dont!
So I've just removed the sub procedure for now and it works! (I think it was because i had referenced something without passing it to the procedure)
I'll be back asking for more help if it doesnt work next time i want a procedure!
Dan
Ok, so i've sucessfully been able to call a sub procedure from another procedure (when a button is clicked).
But it wont let me call the sub procedure from the main procedure?!?!?
The compiler error is "Expression is not a method"!
Any idea's, lol, i'll ask someone tomorrow at uni if i cant figure it out tonight!
Dan
But it wont let me call the sub procedure from the main procedure?!?!?
The compiler error is "Expression is not a method"!
Any idea's, lol, i'll ask someone tomorrow at uni if i cant figure it out tonight!
Dan