|
-
Jan 5th, 2007, 04:14 PM
#1
Thread Starter
Lively Member
[RESOLVED] randomizing program
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.
-
Jan 5th, 2007, 04:57 PM
#2
Re: randomizing program
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!
-
Jan 5th, 2007, 05:26 PM
#3
Thread Starter
Lively Member
Re: randomizing program
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.
-
Jan 5th, 2007, 05:37 PM
#4
PowerPoster
Re: randomizing program
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 :-)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jan 5th, 2007, 05:38 PM
#5
Re: randomizing program
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.
-
Jan 5th, 2007, 05:54 PM
#6
Thread Starter
Lively Member
Re: randomizing program
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.
-
Jan 5th, 2007, 05:59 PM
#7
PowerPoster
Re: randomizing program
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 :-)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jan 5th, 2007, 09:03 PM
#8
Thread Starter
Lively Member
Re: randomizing program
got it working, thanks a lot for the help.
-
Jan 6th, 2007, 11:27 AM
#9
PowerPoster
Re: randomizing program
Don't forget to mark your thread as resolved if your problem is fully resolved :-P
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jan 6th, 2007, 11:55 AM
#10
Thread Starter
Lively Member
Re: randomizing program
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?
-
Jan 6th, 2007, 12:02 PM
#11
PowerPoster
Re: randomizing program
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 :-)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jan 6th, 2007, 12:04 PM
#12
Thread Starter
Lively Member
-
Jan 6th, 2007, 12:06 PM
#13
Re: [RESOLVED] randomizing program
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
-
Jan 6th, 2007, 12:07 PM
#14
PowerPoster
Re: [RESOLVED] randomizing program
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 :-)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
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
|