Results 1 to 6 of 6

Thread: A string that can change, rather than being fixed?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Glasgow,Scotland
    Posts
    281

    I was thinking about this for a while, thought I could do it, but then realised that I could be thinking about it all day and mightn't even acheive it.

    I have a button on my form:

    Private Sub Command1_Click()
    dim randomnumber as integer
    randomnumber = Int(rnd * 10) + 2
    end sub

    This generates a random number from 2 to 11

    Then I have another button, command2.

    When I click this I want the series of numbers, starting at 0 and ending at the number before randomnumber, to be printed in my label1.

    For example:

    randomnumber = 7

    In label1 will be printed: 0,1,2,3,4,5,6

    Does anybody have any code as to how this could be done. I bet you it's something like For x = 0 to randomnumber blah, blah, but I don't know much about that.

    Thanks!

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yep, youre correct
    Code:
    For x=0 to randomnumber-1
     if temp>0 then temp =temp & ","
     temp=temp & randomnumber
    next x
    label=temp
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Your right! It has something to do with For...Next:
    Code:
    'assuming all variables is declared allready
    For i = 0 To randomnumber - 1
        strTemp = strTemp & i & ", "
    Next
    'remove the last comma+space and asign to the Label
    Label1 = Left$(strTemp, Len(strTemp - 2))
    Good luck!

  4. #4
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    Code:
    Dim intCount as Integer
    
    Label1.Caption = ""
    
    For intCount = 0 To RandomNumber - 1
    
      Label1.Caption = Label1.Caption & intCount
    
      If intCount <> RandomNumber - 1 Then Label1.Caption = Label1.Caption & ","
    
    Next intCount
    VB6 sp5, SQL Server 2000, C#

    There are no stupid questions. Only stupid people.

  5. #5
    New Member
    Join Date
    Aug 2000
    Posts
    11
    for x=0 to (randomnumber - 1)
    if x <> (randomnumber - 1) then
    label1.caption = label1.caption & x & ","
    else
    label1.caption = label1.caption & x
    end if
    next x

    Give me five lines written by the most honourable of men, and I shall find in them an excuse to hang him. - Cardinal Richelieu

    Ben Stappleton
    VB6E SP4

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Glasgow,Scotland
    Posts
    281

    Thumbs up

    Thanks everybody!

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