Results 1 to 14 of 14

Thread: [RESOLVED] random up sentences. please help me!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    13

    Resolved [RESOLVED] random up sentences. please help me!!

    hi guys,

    i have some problem here
    i need to random up the whole Sentences with detection on spacing.

    then each word will be place into a label.


    example; " i`m loving it"

    "i`m" will be in labelA 1
    "loving" will be in labelA 2
    "it" will be in labelA 3


    then the 3 labelA will random up. like; 123, 213, 312,......


    reply me asap!!
    please help me..
    thanks alot.

  2. #2
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: random up sentences. please help me!!

    You can use the Split() function to extract your words into an array.
    VB Code:
    1. Dim Words() As String
    2. Dim Sentence As String
    3. Sentence = "I'[color=black]m loving it"[/color]
    4. Words = Split(Sentence, " ")
    Words(0) = "I'm"
    Words(1) = "loving"
    Words(2) = "it"

    I'm not sure what you mean by 'random up' though.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  3. #3
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: random up sentences. please help me!!

    Damn it, just about to suggest the same thing

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    13

    Re: random up sentences. please help me!!

    Mm.. then with the split word, can it do a random?

    so tat it will random place the word into the label.

    cos i need the place the word into a label, therefore i will hav 3 label(0) and so on

    the label will be automatic created
    Last edited by bang2711; Oct 28th, 2005 at 02:04 AM.

  5. #5
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: random up sentences. please help me!!

    See this post by RhinoBull, it shows how to randomize a list of items.
    http://www.vbforums.com/showpost.php...97&postcount=6
    This should give you an idea of how to solve your problem.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  6. #6
    Lively Member
    Join Date
    Jun 2005
    Location
    New Jersey, USA
    Posts
    119

    Re: random up sentences. please help me!!

    Ok, try this:

    VB Code:
    1. stri = split("I'm Loving It", " ")
    2. randomize timer
    3. n = int(rnd * ubound(str) + 1)
    4. label1.caption = str(n)
    5. do
    6. o = int(rnd * ubound(str) + 1)
    7. loop until not o = n
    8. label2.caption = str(o)
    9. 1 p = int(rnd * ubound(str) + 1)
    10. if p = o then goto 1
    11. if p = n then goto 1
    12. label3.caption = str(p)

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    13

    Re: random up sentences. please help me!!

    i`m very sorry guy..

    can u help me do some sample coding?
    and zip and attach for me?
    cos i`m new to this vb6.

    i put in the code but it wont work..
    sorry sorry

  8. #8
    Lively Member
    Join Date
    Jun 2005
    Location
    New Jersey, USA
    Posts
    119

    Re: random up sentences. please help me!!

    never mind, all that code did for me was crash visual basic. fool around with the "RND" command, which picks a random number and assignes it to a variable - x = int((RND * 10) + 1) will pick a number from zero to 10.

  9. #9

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    13

    Re: random up sentences. please help me!!

    hi, this is the layout of wat i`m doing.

    the label will auto create.
    then u need to drag the label1 down to label2.
    text1 is to key in the question.

    please help me..
    thanks
    Attached Files Attached Files
    Last edited by bang2711; Oct 30th, 2005 at 08:08 PM.

  10. #10

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    13

    Re: random up sentences. please help me!!

    hi, can anyone help me wif this.?

    i dont know how to put the break up sentence to every labels?
    and how to random up the label1s

    there is a sample program above the post
    Last edited by bang2711; Oct 30th, 2005 at 08:10 PM.

  11. #11
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: random up sentences. please help me!!

    I wasn't sure what you wanted in the second label, but this picks a random word and puts it in label1. Paste this in OVER your start_Click code

    VB Code:
    1. Private Sub Form_Load()
    2.   Randomize
    3. End Sub
    4.  
    5. Private Sub start_Click()
    6.   Dim x As Integer
    7.   Sentence = Text1.Text
    8.   word() = Split(Sentence, " ")
    9.   x = Int(Rnd * (UBound(word) + 1))
    10.   Label1.Caption = word(x)
    11. End Sub

  12. #12
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: random up sentences. please help me!!

    Quote Originally Posted by bang2711
    i dont know how to put the break up sentence to every labels?
    and how to random up the label1s
    I've modified your project. Take a look at the code I've added and try and understand what it's doing. Thanks to RhinoBull for the randomize list code.
    Attached Files Attached Files
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  13. #13
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: random up sentences. please help me!!

    Quote Originally Posted by colonel720
    never mind, all that code did for me was crash visual basic. fool around with the "RND" command, which picks a random number and assignes it to a variable - x = int((RND * 10) + 1) will pick a number from zero to 10.
    Just an FYI... that will give you a number between 1 and 10...

    Look at these for Rnd explanations:
    VB Code:
    1. myNumber = Int(Rnd * 10) 'This will generate a random number between 0 and 9
    2. myNumber = Int(Rnd * 10) + 1 'This gives you numbers from 1 to 10

  14. #14

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    13

    Re: random up sentences. please help me!!

    hi guy,.
    thank alot for ur help.
    i have slove the problem..!!

    and i have attach a completed program..
    hope it will help others or maybe there need some improvement..

    Attached Files Attached Files

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