|
-
Feb 18th, 2013, 03:14 PM
#1
Thread Starter
New Member
Passing parameters using
Does anyone know how to pass parameter from one procedure to another via an event such as a button click rather than using a CALL statement?
Procedure 1 fills a 6 element array with random numbers.
Procedure 2 display 1st element in a text box when button is clicked
Procedure 3 display 2nd element in a text box when another button is clicked
etc
Code:
Public Class Form1
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
lstDisplay.Items.Clear()
Dim Cam(5) As Integer
Dim lottery As Integer
Dim counter As Integer
Dim unique As Boolean
Dim index As Integer
For counter = 0 To 5
Do
lottery = Int((49 * Rnd()) + 1)
unique = False
For index = 0 To 5
If Cam(index) = lottery Then
unique = True
End If
Next
Loop Until (unique = False)
Cam(counter) = lottery
lstDisplay.Items.Add(Cam(counter))
Next
TxtNumber1.Text = Cam(0)
TxtNumber2.Text = Cam(1)
TxtNumber3.Text = Cam(2)
TxtNumber4.Text = Cam(3)
TxtNumber5.Text = Cam(4)
TxtNumber6.Text = Cam(5)
End Sub
Private Sub cmdBall1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBall1.Click
Would like this TxtNumber1.Text = Cam(0) here
End Sub
Private Sub cmdBall2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBall2.Click
End Sub
Private Sub cmdBall3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBall3.Click
End Sub
Private Sub cmdBall4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBall4.Click
End Sub
Private Sub cmdBall5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBall5.Click
End Sub
Private Sub cmdBall6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBall6.Click
End Sub
End Class
Last edited by Hack; Feb 19th, 2013 at 07:35 AM.
Reason: Added Code Tags
-
Feb 18th, 2013, 03:15 PM
#2
Thread Starter
New Member
Re: Passing parameters using
Ooops
Title should be Passing parameters using button click event
-
Feb 18th, 2013, 10:58 PM
#3
Re: Passing parameters using
It won't work the way you have it because Cam is a local variable in the Button1_Click method. For Cam to be accessed from anywhere else it has to be declared at form scope rather than as a local variable in a method.
Also, since this sure looks like .NET, you shouldn't be using Rnd, but have a single Random object created at form scope.
My usual boring signature: Nothing
 
-
Feb 19th, 2013, 07:36 AM
#4
Re: Passing parameters using
Thread moved to the VB.NET forum section
-
Feb 19th, 2013, 03:42 PM
#5
Re: Passing parameters using
Apropos of very little, if you were using this for a proper lottery, your method would be illegal because of the no-repeat method you're employing. After the first selection from x options it is required that the option be removed altogether and the second selection be from the remaining x - 1 options.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|