# How to declare Variables in Visual Basic



## Rhino24 (Feb 8, 2008)

I need some help on declaring some variables for example lblOutput...I was thinking Dim lblOutput As ....that is the part I am missing. Here is the code

Private Sub btnFactorial_Click( _
ByVal eventSender As System.Object, _
ByVal eventArgs As System.EventArgs) _
Handles btnFactorial.Click
Dim x As Double
Dim Fact As Double

lblOutput.Text = "To determine the Factorial of a number. " _
& "Please enter a number less than 10."
& "Then, click on the Factorial Button to view the results."

x = Val(txtInput.Text)

Fact = Factorial(x)
lblOutput.Text = ("")
lblOutput.Text = (" " & x & "! is " & Fact)


End Sub

Private Function Factorial(ByRef x As Double) As Double


If x <= 1 Then
Factorial = 1
Else
Factorial = x * Factorial(x - 1)
End If

End Function

End Sub

End Module


----------



## MustBNuts (Aug 21, 2003)

From the looks of it, what you want is an Inputbox (mind you I'm going off the top of my head here) not a label (I'm assuming you are trying to populate a label by the prefix lbl).

x = InputBox("Your message here", "Factor", 0)
val(x)

then for your output use a msgbox.

Hope this helps,

MBN


----------

