functions

eec

New member
Joined
Feb 18, 2005
Messages
3
Programming Experience
Beginner
We are doing a simple functions in class and i keep screwing it up.

PrivateSub btncalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalc.Click

Dim snglength, sngwidth, sngheight AsSingle

Dim total AsInteger

'declare varialbes

snglength = Val(Txtlength.Text)

sngwidth = Val(Txtwidth.Text)

sngheight = Val(Txtheight.Text)

'assign txtbox values to variables.

lblvolume.Text =





EndSub



PublicFunction calcvolume(ByVal snglength AsSingle, ByVal sngwidth AsSingle, ByVal sngheight AsSingle, ByVal inttotal AsInteger)

Dim total AsInteger

total = Val(snglength * sngwidth * sngheight)

Return total



EndFunction

it may look worse then before i keep changing things to try and get it to work. basiclly i need to know how i call the value the function is holding back up to display in the label. thank you
if you see anything major wrong please let me know too.
 
Last edited:

Schenz

Well-known member
Joined
Sep 11, 2004
Messages
181
Location
Cincinnati, OH
Programming Experience
5-10
Try Something like this:

VB.NET:
[size=2][color=#0000ff]Private[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] btncalc_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] btncalc.Click
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] snglength, sngwidth, sngheight [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Single
 
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] total [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Integer
 
[/color][/size][size=2][color=#008000]'declare varialbes
 
[/color][/size][size=2]snglength = Val(Txtlength.Text)
 
sngwidth = Val(Txtwidth.Text)
 
sngheight = Val(Txtheight.Text)
 
[/size][size=2][color=#008000]'assign txtbox values to variables.
 
[/color][/size][size=2]lblvolume.Text = calcvolume(snglength, sngwidth, sngheight).ToString
 
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub
 
 [/color][/size][size=2][color=#0000ff]Public[/color][/size][size=2][color=#0000ff]Function[/color][/size][size=2] calcvolume([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] snglength [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Single[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sngwidth [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Single[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sngheight [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Single[/color][/size][size=2]) as Single
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] total [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff] Integer
 
[/color][/size][size=2]total = Val(snglength * sngwidth * sngheight)
 
[/size][size=2][color=#0000ff]Return[/color][/size][size=2] total
 
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Function[/color][/size]
 
Top Bottom