How do I pass information between subs?

Hello! I have the following sub:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim randomObject As Random = New Random()
Dim randomNumber As Integer = randomObject.Next()
'two random numbers being multiplied
Dim number1 As Integer
Dim number2 As Integer
'user's answer input
Dim userGuess As Integer

'random numbers between 0 and 9 are generated
number1 = randomObject.Next(0, 10)
number2 = randomObject.Next(0, 10)

'assigns appropriate variable to textboxes for display
Me.value1.Text = String.Format("{0}", number1)
Me.value2.Text = String.Format("{0}", number2)

'converts numbers to be mult. to integers
number1 = Convert.ToDouble(Me.value1.Text)
number2 = Convert.ToDouble(Me.value2.Text)
End Sub


I want to pass the values contained in number1, number2 and userGuess to the following sub:


Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click

'program's reply to user's answer
Dim reply As String

'sends above variable values to CheckCalculation function
CheckCalculation(number1, number2, userGuess)
End Sub

How do I do it????

Thanks,

Linda

Comments

  • : Hello! I have the following sub:
    :
    : Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    : Dim randomObject As Random = New Random()
    : Dim randomNumber As Integer = randomObject.Next()
    : 'two random numbers being multiplied
    : Dim number1 As Integer
    : Dim number2 As Integer
    : 'user's answer input
    : Dim userGuess As Integer
    :
    : 'random numbers between 0 and 9 are generated
    : number1 = randomObject.Next(0, 10)
    : number2 = randomObject.Next(0, 10)
    :
    : 'assigns appropriate variable to textboxes for display
    : Me.value1.Text = String.Format("{0}", number1)
    : Me.value2.Text = String.Format("{0}", number2)
    :
    : 'converts numbers to be mult. to integers
    : number1 = Convert.ToDouble(Me.value1.Text)
    : number2 = Convert.ToDouble(Me.value2.Text)
    : End Sub
    :
    :
    : I want to pass the values contained in number1, number2 and userGuess to the following sub:
    :
    :
    : Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
    :
    : 'program's reply to user's answer
    : Dim reply As String
    :
    : 'sends above variable values to CheckCalculation function
    : CheckCalculation(number1, number2, userGuess)
    : End Sub
    :
    : How do I do it????
    :
    : Thanks,
    :
    : Linda
    :

    Actually, you don't have to pass anything since your info is in the textboxes. In your button click sub add:

    Dim number1, number2, userNumber as Integer
    number1 = value1.Text
    number2 = value2.Text
    userNumber = .Text

    before your call to CheckCalculation
  • : : Hello! I have the following sub:
    : :
    : : Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    : : Dim randomObject As Random = New Random()
    : : Dim randomNumber As Integer = randomObject.Next()
    : : 'two random numbers being multiplied
    : : Dim number1 As Integer
    : : Dim number2 As Integer
    : : 'user's answer input
    : : Dim userGuess As Integer
    : :
    : : 'random numbers between 0 and 9 are generated
    : : number1 = randomObject.Next(0, 10)
    : : number2 = randomObject.Next(0, 10)
    : :
    : : 'assigns appropriate variable to textboxes for display
    : : Me.value1.Text = String.Format("{0}", number1)
    : : Me.value2.Text = String.Format("{0}", number2)
    : :
    : : 'converts numbers to be mult. to integers
    : : number1 = Convert.ToDouble(Me.value1.Text)
    : : number2 = Convert.ToDouble(Me.value2.Text)
    : : End Sub
    : :
    : :
    : : I want to pass the values contained in number1, number2 and userGuess to the following sub:
    : :
    : :
    : : Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
    : :
    : : 'program's reply to user's answer
    : : Dim reply As String
    : :
    : : 'sends above variable values to CheckCalculation function
    : : CheckCalculation(number1, number2, userGuess)
    : : End Sub
    : :
    : : How do I do it????
    : :
    : : Thanks,
    : :
    : : Linda
    : :
    :
    : Actually, you don't have to pass anything since your info is in the textboxes. In your button click sub add:
    :
    : Dim number1, number2, userNumber as Integer
    : number1 = value1.Text
    : number2 = value2.Text
    : userNumber = .Text
    :
    : before your call to CheckCalculation
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories