|
-
Mar 9th, 2000, 01:11 AM
#1
Thread Starter
Member
I have a form with an array of textboxes. A different number, between -12 and 12, loads into the textboxes at random when the form loads.
I use this code:
Private Sub Form_Load()
Randomize Timer
Text5(0).Text = Int((10 + 13) * Rnd - 10)
Text5(1).Text = Int((10 + 13) * Rnd - 10)
Text5(2).Text = Int((10 + 13) * Rnd - 10)
Text5(3).Text = Int((10 + 13) * Rnd - 10)
Text5(4).Text = Int((10 + 13) * Rnd - 10)
Text5(5).Text = Int((10 + 13) * Rnd - 10)
Text5(6).Text = Int((10 + 13) * Rnd - 10)
Text5(7).Text = Int((10 + 13) * Rnd - 10)
For X = 0 To 7
If Rnd > 0.5 Then
Text5(X).Text = "+" & Int(Rnd * 12)
End If
Next X
I want to have it so that '0' doesn't appear in the textboxes - if it happens to come up at random. I thought that placing the code below, between the 'End If' and 'Next X' above, would do it. but it doesn't:
If Val(Text5(index).Text) = 0 Then
Text5(index).Text = "3"
End If
Could someone please tell me how I can do it?
Thanks!
-
Mar 9th, 2000, 03:29 AM
#2
Fanatic Member
Hi Richie. I believe that this code does what you are looking for:
Code:
Option Explicit
Private Sub Form_Load()
Dim iCounter as Integer
For iCounter = 0 to 7
Text5(iCounter) = 0
Randomize
Do Until Text5(iCounter) <> 0
Text5(iCounter) = Int((23 * Rnd) - 10)
Loop
Next
End Sub
All the best.
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
|