First time programming
Results 1 to 5 of 5

Thread: First time programming

  1. #1
    Senior Member
    Join Date
    Apr 2003
    Posts
    125

    Question First time programming

    Im new to programming and am coding this project in VB 6.
    I know that this code generates numbers from 1-9 only. Rnd chooses a decimal number in between 0,1. Int multiples this number by ten and rounds it. I want it to generate numbers at random in between 1-52. I feel lame but thought I could get advice or help, I know lamers use VB but C++ looks wicked hard. If I could get a list of functions like the ones you see here I would appreciate it and what If statement would you use?

    Label1.Caption = Int(Rnd * 10)

    Label2.Caption = Int(Rnd * 10)

    Label3.Caption = Int(Rnd * 10)

    Label4.Caption = Int(Rnd * 10)

    Label5.Caption = Int(Rnd * 10)

    Label6.Caption = Int(Rnd * 10)

    End If
    A+ Certified

  2. #2
    Senior Member
    Join Date
    Jun 2003
    Posts
    772
    He, VB isn't lame, although I don't really like it (but that's just my opinion and I don't think at all VB is lame or something).
    I don't know VB but can't you simply do:

    Label1.Caption = Int(Rnd * 53)
    The above sentences are produced by the propaganda and indoctrination of people manipulating my mind since 1987, hence, I cannot be held responsible for this post\'s content - me

    www.elhalf.com

  3. #3
    Senior Member
    Join Date
    Apr 2003
    Posts
    125
    Yeah, I just did and it works, Thanx. I totally forgot to state two problems. Rnd picks decimal numbers in between 0,1. I dont want it to pick zero or .01. Last, I dont want identical numbers to be displayed in the labels at any given process. Have no idea what to do. Thanks for replies
    A+ Certified

  4. #4
    Senior Member
    Join Date
    Jun 2003
    Posts
    772
    you can just create some if-then-else contruction to avoid that.
    The above sentences are produced by the propaganda and indoctrination of people manipulating my mind since 1987, hence, I cannot be held responsible for this post\'s content - me

    www.elhalf.com

  5. #5
    Custom User
    Join Date
    Oct 2001
    Posts
    503
    Getting rid of zero is easy as well. I'm not a VB programmer, but I think this should do:

    Code:
    Label1.caption = Int( Rnd * (num-1)) + 1
    So if you wanted it between 1 and 10, you would put 9 instead of num-1 and it would generate a number between 0 and 9, and then add one to it, thus making it between 1 and 10:

    Code:
    Label1.caption = Int( Rnd * 9 ) + 1
    Hope that helped.

    ac

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides