Results 1 to 2 of 2

Thread: making all characters except '0' appear in textbox

  1. #1

    Thread Starter
    Member
    Join Date
    May 1999
    Posts
    49

    Post

    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!


  2. #2
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Post

    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
  •  



Click Here to Expand Forum to Full Width