Call statement

ddady

Member
Joined
Sep 19, 2006
Messages
20
Programming Experience
Beginner
Hi all,

I'm newbie to VB 2005 express and to VB at all. I have learned how to do some basic stuff but now i want to get in to it more. Is there any good guide that explain commands and syntax?

For example i want to use the call statement or procedure and i dont know how to do it, how to declare it, how to send arguments etc.. Simple example will be appriciated :)

Thanks in advance!
 
To call a button click event:

VB.NET:
Call Button1_Click(Me, Nothing)

(or both could be Nothing, but for the click event the first argument is Sender, so I put Me :))
 
Yick!!:) No, you shouldn't be calling event handlers directly, the button should have a performclick method (if memory serves)which raises the event internally.

VB.NET:
Button.PerformClick

Also i'm sure that i read somewhere that you shouldn't be using the call keyword at all, i just can't remember where...

When you invoke a method the arguments you need to pass in will popup in a tooltip like window. For example a GraphicsPath object's constructor is overloaded to take several arguments. One of which is fill mode, so we could do this to create a 'New' GraphicsPath

VB.NET:
Dim Gp as New GraphicsPath(FillMode.Alternate)

We do this because the GraphicsPath's Constructor (Sub New) looks something like this..

VB.NET:
Public Sub New(Byval FillMode as FillMode)
End Sub

So that bit in brackets means that we have to pass in an 'argument' of the type FillMode. Don't get too bogged down with the term 'argument'. It is just a way of saying..

If you want to use this Sub Routine Or Function you are going to have to give me the information i ask for or i won't work. For example, if i create a sub like this..

VB.NET:
Public Sub GetMeAWig(Byval WigColor as Color)
...
End sub


So now i'm a bald man and i want a wig. So we call the sub, but we have to supply a wigcolor as specified in the 'argument'

VB.NET:
GetMeAWig(Color.Red)


Thats all you need to do to call that sub. Then inside that sub you can do what ever you want with WigColor because we have now assigned it the value of red.

VB.NET:
Public Sub GetMeAWig(Byval WigColor as Color)
 
MessageBox.Show(WigColor.Tostring)
 
End Sub


Calling this sub will make a messagebox popup and it will say 'Red' because that is the value of the wigcolor argument. With me?
 
Thanks vis781

I liked your explanation with the wig :D it realy helped.

That is my code :

VB.NET:
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Button1_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] ConvertBt.Click[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] cel [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Double[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] far [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Double[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] ComboBox2.SelectedIndex = 0 [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]cel = ValuBox.Text[/SIZE]
[SIZE=2]celtofar(cel)[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]far = ValuBox.Text[/SIZE]
[SIZE=2]fartocel(far)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2]Resultbox.Text = result    [COLOR=seagreen]' result was configured as a global[/COLOR][/SIZE]
[SIZE=2][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][/SIZE]
 
[SIZE=2][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] celtofar([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] cel [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Double[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]result = cel * 9 / 5 + 32[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2][COLOR=#000000] fartocel([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2][COLOR=#000000] far [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Double[/COLOR][/SIZE][SIZE=2][COLOR=#000000])[/COLOR][/SIZE]
[SIZE=2][COLOR=black]result = (far - 32) * 5 / 9[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[/COLOR][/SIZE]
[/SIZE]


Now, it's working perfectly but i'm facing one small problem, since the result could be sometimes not a whole number how can i decided how many figures will be after the point?

for an example i can get a result such as 4.666666666 and i want it to be 4.666
 
Back
Top