Hi, im new to vb6 and need to know how to make a randomizing program that will select one word from one list to display in text1 and select another word from another list and put it in text2. Thanks.
Printable View
Hi, im new to vb6 and need to know how to make a randomizing program that will select one word from one list to display in text1 and select another word from another list and put it in text2. Thanks.
Use Randomize and Rnd..
Like...
VB Code:
Private Sub Form_Load() With List1 .AddItem "one" .AddItem "two" .AddItem "three" .AddItem "four" .AddItem "five" .AddItem "six" .AddItem "seven" .AddItem "eight" .AddItem "nine" .AddItem "ten" End With End Sub Private Sub Command1_Click() Dim i As Integer Randomize i = Rnd(List1.ListCount) * List1.ListCount Text1.Text = List1.List(i) End Sub
do the same thing for text2. Hope it helps!
its not working... i get a runtime error, says object required?
I am by the way in the first week of learning vb6, or any programming by the way. so please be gentle.
What line is being highlighted when you close the error (click the "ok" button)...usually a line is highlighted in yellow (by default) to tell you where the error is, and this is an important piece of information. One of the objects in *that* line is incorrectly named on your form.
If, for instance, it was highlighting "Text1.Text = List1.List(i)" then either you don't have a Text1 object or a List1 object on your form and need to add one.
And we're usually very gentle with people who are courteous and polite and don't push us for answers, so don't worry...we're as gentle with you as you are with us :-)
Weird huh? What line are you gettin an error? I have included a listbox named List1 and a textbox named Text1 plus a command button named Command1.
the first .additem "one"
Thanks for the help too. Im going home soon, and my father is an old vb5 guru type. so ill see what he says.
Right, then that means you don't have the listbox list1, most likely. I assume you've either not added the listbox or (most likely) you're actually using a textbox to list the items rather than a listbox/listview. If you're using a textbox it is difficult (for newer programmers, I mean...proficient programmers have umpteen ways of doing it although they would most likely use a listbox which is a LOT easier) to take out a random word from a text box and put it elsewhere.
Either try using a listbox (if you need more help with how listboxes work, people here will help you...and it's a lot easier than you think, you'll get used to it in time) or if you're really set on using a textbox to list the words then I guess we can show you a few ways (they'll involve a command called split() probably, which splits the words into an array, then they'll use the replace() command to remove it from the textbox) to do it :-)
got it working, thanks a lot for the help.
Don't forget to mark your thread as resolved if your problem is fully resolved :-P
just one small question...
If Label3.Caption = "one""two""three""four""five" Then
pic1.Visible = True
Else
pic1.Visible = False
End If
thats what i have and it isnt working. i must need to put something between the "" but i dont know what. I want it so that if label3.caption = a couple of different things from list1 the pic1.visible = true else false.
get it?
I assume you mean the first line to say:
If Label3.Caption = "one" or Label3.Caption = "two" or Label3.Caption = "three" or Label3.Caption = "four" or Label3.Caption = "five" Then
I know of no easier way to do that, and I'd be interested to know if there is a better way :-)
thanks! resolved.
FYI, an alternative to that would be this:
VB Code:
Select Case Label3.Caption Case "one", "two", "three", "four", "five" pic1.Visible = True Case Else pic1.Visible = False End Select
Ah...I knew there was something out there, I just couldn't think of it. I though it was more than the case statement though :-)