Wednesday, May 9, 2012
CD DVD Tips
This was the code I wrote originally:
Private Sub btnTip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTip.Click
Call Message(Me.lblTip)
End Sub
'After button has been clicked, a random number will be chosen that represents one of the three tips
'post: the tip will show up in the label
Sub Message(ByRef lblMessage As Label)
Randomize()
Dim tipNumber As Integer
tipNumber = Int(3 * Rnd()) + 1
Select Case tipNumber
Case 1
lblMessage.Text = "Handle CD/DVDS by the center hole or by the edges."
Case 2
lblMessage.Text = "Keep CD/DVDs away from extreme temperatures and moisture."
Case 3
lblMessage.Text = "Store discs in a jewel case or sleeve to prevent scratches."
End Select
This is the updated version with parameters based on TestRndIntFunction
Dim lowNum As Integer = 1
Dim highNum As Integer = 3
Dim chosenNum As Integer
Call RndInt(lowNum, highNum, chosenNum)
If chosenNum = 1 Then
Me.lblTip.Text = "Handle CD/DVDS by the center hole or by the edges."
ElseIf chosenNum = 2 Then
Me.lblTip.Text = "Keep CD/DVDs away from extreme temperatures and moisture."
Else
Me.lblTip.Text = "Store discs in a jewel case or sleeve to prevent scratches."
End If
End Sub
'After button has been clicked, a random number will be chosen that represents one of the three tips
'post: the tip will show up in the label
Sub RndInt(ByVal firstNum As Integer, ByVal secondNum As Integer, ByRef thirdNum As Integer)
Randomize()
thirdNum = ((secondNum - firstNum + 1) * Rnd()) + firstNum
Subscribe to:
Post Comments (Atom)
Hi I need help with a vb exercise that I have no idea how to do. I have to reduce fractions but I can't use that Mod thing that everyone is using because I haven't learned that and then I will get in trouble by my teacher. It says use a reduce() procedure with num and denom parameters if possible. Please help
ReplyDelete