Hola Comunidad:
Bueno he estado aprendiendo Vb por mi cuenta asi que vi que una de las formas es estudiando los codigos y ver el trabajo de otros. asi que me descargue el source en VB 6 del International Lotto Uk, pero No entiendo la ultima parte me gustaria saber si alguien podria hecharme una mano.
Source
Option Explicit
Dim iBallsToMake As Integer
Private Sub Form_Load()
' Initialize random procedure:
Randomize
End Sub
Private Function Get_RANDOM(lowerbound As Integer, upperbound As Integer) As Integer
' The RND formula!
' Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Get_RANDOM = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
End Function
Private Sub lblURL_Click(Index As Integer)
Dim sURL As String
sURL = Trim(lblURL(Index).Caption)
Shell "explorer " & sURL, vbMaximizedFocus
End Sub
Private Sub cmdMake_Click()
' Disable button and properties:
cmdMake.Enabled = False
txtBallCount.Enabled = False
txtMinBall.Enabled = False
txtMaxBall.Enabled = False
Dim i As Integer
' Hide all balls and set labels to "77":
For i = imgBall.LBound To imgBall.UBound
imgBall(i).Visible = False
lblNum(i).Visible = False
lblNum(i).Caption = "77"
Next i
' Get the number of balls to make:
iBallsToMake = Val(txtBallCount.Text)
' Check if number is between 1 and 7:
If iBallsToMake > 7 Then
iBallsToMake = 7
txtBallCount.Text = "7"
ElseIf iBallsToMake <= 0 Then
iBallsToMake = 1
txtBallCount.Text = "1"
End If
' Start the process:
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
' Are there balls to make?
If iBallsToMake <= 0 Then
' Stop timer:
Timer1.Enabled = False
' Enable properties:
cmdMake.Enabled = True
txtBallCount.Enabled = True
txtMinBall.Enabled = True
txtMaxBall.Enabled = True
Exit Sub ' Done!
End If
' Make ball visible:
imgBall(7 - iBallsToMake).Visible = True
lblNum(7 - iBallsToMake).Visible = True
Dim iNewNum As Integer
Dim i As Integer
Dim iTryAgainCounter As Integer
iTryAgainCounter = 0
try_again:
' Avoid hand up with max ball 2 and 7 balls :)
If iTryAgainCounter > 100 Then
' Set the ball value:
lblNum(7 - iBallsToMake).Caption = "?"
GoTo one_less
End If
' Get the random value:
iNewNum = Get_RANDOM(Val(txtMinBall.Text), Val(txtMaxBall.Text))
' Avoid falling the same number again:
For i = imgBall.LBound To imgBall.UBound
If Val(lblNum(i).Caption) = iNewNum Then
iTryAgainCounter = iTryAgainCounter + 1
GoTo try_again
End If
Next i
' Set the ball value:
lblNum(7 - iBallsToMake).Caption = iNewNum
one_less:
' Ok, one ball is there!
iBallsToMake = iBallsToMake - 1
End Sub
-----------------------------------------------------------------------------------------------
Duda:
Bueno el problema es el siguiente, supuestamente en el codigo con variable iballstomake es ekivalente al numero de bolas que se va a caer al azar, entonces
' Make ball visible:
imgBall(7 - iBallsToMake).Visible = True
lblNum(7 - iBallsToMake).Visible = True
Esto solo haria aparecer a la primera bola y no las 7 que supuestamente deberia estar alli.
Es mas otra cosa que no entiendo, porque pone esta condicion si itryagaincounter es dificil que sea mayor a 100 x lo que nunka se cumpliria.....
If iTryAgainCounter > 100 Then
' Set the ball value:
lblNum(7 - iBallsToMake).Caption = "?"
GoTo one_less
End If
La verdad estoy con muchas ganas d aprender sin embargo creo... que necesitare de ayuda...
Espero que haya sido claro con mi explicacion.
Salu2