Results 1 to 2 of 2

Thread: one less or more than another random number

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 1999
    Location
    France
    Posts
    90


    Hi,

    I have a form. On my form I have 2 labels - label1 and label2.

    When my form loads, I use the following code to have it so that label2 is always 1 less than label1:

    Private Sub Form_Load()
    Randomize
    Label1 = Int(Rnd * 10) + 1
    Label2 = Val(Label1) - 1
    End Sub

    But this isn't exactly what I'm trying to acheive. I want label2 to also be a random number. That is, each time the form loads, it will either be 1 less or 1 higher than label1.

    For example, If Label1 is 6, Label2 might be 5 or 7.

    Could someone please help me to do this?

    Thanks.

  2. #2
    Junior Member
    Join Date
    Sep 1999
    Location
    Kempton Park, Guateng, South Africa
    Posts
    24
    The answer is quite easy...
    Just create variable that will contain a random number (in the range of 0 to 1) which means that the number will be either 1 or 0. If the number is 0 then label2 is label1-1 and if the number is 1 then label2 is label1+1
    "He who laughs at a question is not worth being asked"

    RavenCrow

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