473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

vb5 game help

3
i have a vb5 game in the works and i need help with it. it needs a random number genorator because the player must later guess the number. there is a problom i can't solve. the number is never actually returned. please help. this is the code i have for this function:


Private Sub Command1_Click()
If Option1.Value = True Then
Randomize
thenumb = Int((15 * Rnd) + 1)
End If
If Option2.Value = True Then
Randomize
thenumb = Int((30 * Rnd) + 1)
End If
If Option3.Value = True Then
Randomize
thenumb = Int((50 * Rnd) + 1)
End If
If Option1.Value = False Then
If Option2.Value = False Then
If Option3.Value = False Then
Randomize
thenumb = Int((1000000 * Rnd) + 1)
End If
End If
End If
Form1.Visible = False
Form2.Visible = True
End Sub
May 21 '06 #1
3 2013
CaptainD
135 100+
First off, you say the game works, does that mean you are trying to make a change to it?

As for your code, I made a simple change to test your code and it works.
Add a label to your form and paste this into your click event and see what happens.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim thenumb As Long 'Added this for the variable to hold the random number
  3. If Option1.Value = True Then
  4. Randomize
  5. thenumb = Int((15 * Rnd) + 1)
  6. End If
  7. If Option2.Value = True Then
  8. Randomize
  9. thenumb = Int((30 * Rnd) + 1)
  10. End If
  11. If Option3.Value = True Then
  12. Randomize
  13. thenumb = Int((50 * Rnd) + 1)
  14. End If
  15. If Option1.Value = False Then
  16. If Option2.Value = False Then
  17. If Option3.Value = False Then
  18. Randomize
  19. thenumb = Int((1000000 * Rnd) + 1)
  20. End If
  21. End If
  22. End If
  23. 'Form1.Visible = False
  24. 'Form2.Visible = True
  25. Label1.Caption = thenumb 'Added this to display the results
  26. End Sub
  27.  
Second, this is a sub event, not a function. Do you understand how a function works? (Subs do work where functions return values)

Here is a simple function. Add a second command button and paste the following code then click the second command button
Expand|Select|Wrap|Line Numbers
  1. Private Function ReturnRandomNumber(iPassedNumber As Long) As Long
  2. 'The number passed in is a long (iPassedNumber) and "ReturnRandomNumber"
  3. ' is the output, also a long
  4. Randomize
  5. ReturnRandomNumber = Int((iPassedNumber * Rnd) + 1)
  6.  
  7. End Function
  8.  
  9. Private Sub Command2_Click()
  10. Dim lngNumberToPass As Long
  11.  
  12. If Option1.Value = True Then
  13.     lngNumberToPass = 15
  14. End If
  15.  
  16. If Option2.Value = True Then
  17.     lngNumberToPass = 30
  18. End If
  19. If Option3.Value = True Then
  20.     lngNumberToPass = 50
  21. End If
  22. If (Option1.Value And Option2.Value And Option3.Value) = False Then
  23.     lngNumberToPass = 1000000
  24. End If
  25. Label1.Caption = CStr(ReturnRandomNumber(lngNumberToPass))
  26.  
  27. End Sub
  28.  
  29.  
  30.  
May 21 '06 #2
JMy
3
thanks, i forgot to mention the moduel (can't spell) that had thenumb. thanks again!

i ran it, and it works, but now the second form doesn't...

Private Sub Command1_Click()
pguess = Text1.Text
If pguess = thenumb Then
Form2.Visible = False
Form3.Visible = True
End If
If pguess < thenumb Then
Label1.Caption = "too small"
pscore = pscore - 1
End If
If pguess > thenumb Then
Label1.Caption = "too big"
pscore = pscore - 1
End If
Command1.Value = False
End Sub

i want it to run again, but it runs in a loop if you tell it to goto the top. i need it to stop here, then rerun...
May 22 '06 #3
CaptainD
135 100+
Couple of things.

First, your new code does not reference Form1 like it initially did and you now have a Form3. So, I'm not sure what's missing or what is supposed to happen.

You should try to explain you problem a little clearer since no one here can see your program. you also should post code where the problem exist and note what type of problem.

Do you know how to "Step Through" code? If you click on the bar to the left of where you type the code it will place a "Break Point" (Red Dot) where you clicked.(try to do it at the beginning of where you want to check your code)
Once the4 cursor stops at the break point you can press F8 and move through the code checking values.

On you coding, it's a common practice to Type with both Lower and Upper case to separate words that are joined, it makes them easier to read.
Example: NumberToPass is easier to read then numbertopass
Also, try indenting your code.
Example:
Expand|Select|Wrap|Line Numbers
  1. If bThisValue = True Then
  2.     DoSomeWork
  3. Else
  4.     If bAnotherValue = True Then
  5.         DoMoreWork
  6.     End If
  7. End If
  8.  
Post more information and I'll see what I can find, as it is, I can not see a "Loop"
May 22 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

138
by: theodp | last post by:
--> From http://www.techdirt.com/articles/20040406/1349225.shtml Microsoft Patents Saving The Name Of A Game Contributed by Mike on Tuesday, April 6th, 2004 @ 01:49PM from the...
1
by: Claude Vernier | last post by:
Hello, I'm a C# programmer. I have two projects. First, write an action scrolling game in C#, (portable to Windows Mobile eventually...), This game will look like The Adventure of Link from...
7
by: Gasten | last post by:
Hello. The last weeks I've been coding a roguelike (you know, like nethack) in python using the nCurses library. Some week ago I ran into a problem: When I made the object for messagebar-output, I...
1
hpbutterbeer
by: hpbutterbeer | last post by:
We have a Machine Project and my brain is currently in a clouded state. Sorry, I'm just a beginner in C Programming... Text twist is a windows game whose main objective is to form words out of the...
0
by: raypjr | last post by:
Hi everyone. I need a little help with some parts of a word guessing game I'm working on. I have some parts done but unsure about others and could use a little advice. Any help is very much...
0
by: Jeff Rush | last post by:
At PyCon this year we're going to have a multi-day game programming clinic and challenge. This is a first-time event and an experiment to find those in the Python community who enjoy playing and...
0
by: smartx | last post by:
Hi, I would like to share my knowledge as a game programmer, really game programming is hard, I don't want to disappoint you, the important point to become a game programmer is to love game...
2
by: LilMeechc20 | last post by:
Hello, I have a group assignment that I have to do. We have to write a Tic Tac Toe game. One person in my group has managed to write the code for a multiplayer (human -vs- human) game and I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.