Oct 28th, 2005, 01:16 AM
#1
Thread Starter
New Member
[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.
Oct 28th, 2005, 01:46 AM
#2
Re: random up sentences. please help me!!
You can use the Split() function to extract your words into an array.
VB Code:
Dim Words() As String
Dim Sentence As String
Sentence = "I'[color=black]m loving it"[/color]
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.
Oct 28th, 2005, 01:57 AM
#3
Re: random up sentences. please help me!!
Damn it, just about to suggest the same thing
Oct 28th, 2005, 01:58 AM
#4
Thread Starter
New Member
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 .
Oct 28th, 2005, 02:08 AM
#5
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.
Oct 28th, 2005, 02:22 AM
#6
Lively Member
Re: random up sentences. please help me!!
Ok, try this:
VB Code:
stri = split("I'm Loving It", " ")
randomize timer
n = int(rnd * ubound(str) + 1)
label1.caption = str(n)
do
o = int(rnd * ubound(str) + 1)
loop until not o = n
label2.caption = str(o)
1 p = int(rnd * ubound(str) + 1)
if p = o then goto 1
if p = n then goto 1
label3.caption = str(p)
Oct 28th, 2005, 03:14 AM
#7
Thread Starter
New Member
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
Oct 28th, 2005, 03:53 AM
#8
Lively Member
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.
Oct 28th, 2005, 04:03 AM
#9
Thread Starter
New Member
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
Last edited by bang2711; Oct 30th, 2005 at 08:08 PM .
Oct 30th, 2005, 08:00 PM
#10
Thread Starter
New Member
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 .
Oct 30th, 2005, 08:16 PM
#11
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:
Private Sub Form_Load()
Randomize
End Sub
Private Sub start_Click()
Dim x As Integer
Sentence = Text1.Text
word() = Split(Sentence, " ")
x = Int(Rnd * (UBound(word) + 1))
Label1.Caption = word(x)
End Sub
Oct 30th, 2005, 08:58 PM
#12
Re: random up sentences. please help me!!
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
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
Oct 30th, 2005, 09:44 PM
#13
Re: random up sentences. please help me!!
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:
myNumber = Int(Rnd * 10) 'This will generate a random number between 0 and 9
myNumber = Int(Rnd * 10) + 1 'This gives you numbers from 1 to 10
Nov 16th, 2005, 04:53 AM
#14
Thread Starter
New Member
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width