[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.
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.
Re: random up sentences. please help me!!
Damn it, just about to suggest the same thing :D
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
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.
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)
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
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.
1 Attachment(s)
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
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
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
1 Attachment(s)
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.
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:
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
1 Attachment(s)
Re: random up sentences. please help me!!
hi guy,.
thank alot for ur help. :bigyello:
i have slove the problem..!! :thumb:
and i have attach a completed program..
hope it will help others or maybe there need some improvement..
;)