473,840 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Keeping Score

1 New Member
O.k. guys trying to teach myself in VB6 to start i am writing a math program for my daughter but i am having trouble with my code to keep score. the program is two random numbers that pop up in 2 txtboxes and a 3 txtbox for the answer on a 3 min timer what i want to do is keep track of how many she got right and display it at the end of the 3 min. here is the code any info you code give will be helpful and if you see any other mistakes in the code let me know.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdcheck_Click()
  2. Dim score As Integer
  3. score = score + 1
  4. txtscore.Text = score
  5. Dim sum As String
  6. x = Answer.Text
  7. sum = val(text1.Text) + val(Text2.Text)
  8.  
  9. If x = sum Then
  10. score = score + 1
  11. MsgBox "Good Job!"
  12. 'put random number in textbox 1
  13. text1.Text = Int((10 - 0 + 1) * Rnd + 0)
  14. 'put random number in textbox 2
  15. Text2.Text = Int((10 - 0 + 1) * Rnd + 0)
  16. 'clear textbox 3 for the answer
  17. Answer.Text = ""
  18.  
  19. Else
  20.  
  21. MsgBox "wrong"
  22. ' put random number in textbox 1
  23. text1.Text = Int((10 - 0 + 1) * Rnd + 0)
  24. ' put random number in textbox 2
  25. Text2.Text = Int((10 - 0 + 1) * Rnd + 0)
  26. ' clear textbox 3 for the answer
  27. Answer.Text = ""
  28. End If
  29. End Sub
as the code is it will add one to txt.score on the first right answer but then nothing after that. Thanks in advance for any help
Mar 22 '08 #1
6 9108
jg007
283 Contributor
O.k. guys trying to teach myself in VB6 to start i am writing a math program for my daughter but i am having trouble with my code to keep score. the program is two random numbers that pop up in 2 txtboxes and a 3 txtbox for the answer on a 3 min timer what i want to do is keep track of how many she got right and display it at the end of the 3 min. here is the code any info you code give will be helpful and if you see any other mistakes in the code let me know.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdcheck_Click()
  2. Dim score As Integer
  3. score = score + 1
  4.  
as the code is it will add one to txt.score on the first right answer but then nothing after that. Thanks in advance for any help
you are using the score as an interer for this sub only and it is redimming it each time and setting it as 1

sorry probably not described well but hopefully you understand what I mean, I would ( possibly incorrectly! ) be declaring score as an integer in the class section and then using the form load to set it to 0
Mar 23 '08 #2
Killer42
8,435 Recognized Expert Expert
Ignore this message. I'm just "subscribin g" to the discussion thread so I can find it again later.
Mar 25 '08 #3
jamesd0142
469 Contributor
Try this

Expand|Select|Wrap|Line Numbers
  1.   Dim score As Integer = 0
  2.     Dim x As String = Nothing
  3.  
  4.  
  5.     Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6.         'put random number in textbox 1
  7.         Text1.Text = Int((10 - 0 + 1) * Rnd() + 0)
  8.         'put random number in textbox 2
  9.         Text2.Text = Int((10 - 0 + 1) * Rnd() + 0)
  10.         'clear textbox 3 for the answer
  11.         Answer.Text = ""
  12.     End Sub
  13.  
  14.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  15.         Dim sum As String
  16.         x = Answer.Text
  17.         sum = Val(Text1.Text) + Val(Text2.Text)
  18.  
  19.         If x = sum Then
  20.             score = score + 1
  21.             MsgBox("Good Job!")
  22.             'put random number in textbox 1
  23.             Text1.Text = Int((10 - 0 + 1) * Rnd() + 0)
  24.             'put random number in textbox 2
  25.             Text2.Text = Int((10 - 0 + 1) * Rnd() + 0)
  26.             'clear textbox 3 for the answer
  27.             Answer.Text = ""
  28.  
  29.         Else
  30.             MsgBox("wrong")
  31.             ' put random number in textbox 1
  32.             Text1.Text = Int((10 - 0 + 1) * Rnd() + 0)
  33.             ' put random number in textbox 2
  34.             Text2.Text = Int((10 - 0 + 1) * Rnd() + 0)
  35.             ' clear textbox 3 for the answer
  36.             Answer.Text = ""
  37.         End If
  38.  
  39.         txtscore.Text = score
  40.     End Sub
  41.  
NOTE: your 'random' numbers will repeat everytime u restart the program, to get better randoom numbers

use something like this, to reduce the chance of repeating values.

Expand|Select|Wrap|Line Numbers
  1. Dim a As String
  2. a =  System.DateTime.Now.Millisecond
  3.  

MABY THIS WILL WORK UNLESS SOMEONE CAN SUGGEST ANY BETTER:

Expand|Select|Wrap|Line Numbers
  1.     Dim score As Integer = 0
  2.     Dim x As String = Nothing
  3.     Dim a As String
  4.     Dim b As String
  5.  
  6.     Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  7.         a = Mid(System.DateTime.Now.Millisecond, 1, 1)
  8.         System.Threading.Thread.Sleep(CInt(a) + 284)
  9.         b = Mid(System.DateTime.Now.Millisecond, 1, 1)
  10.         'put random number in textbox 1
  11.         Text1.Text = a 'Int((10 - 0 + 1) * Rnd() + 0)
  12.         'put random number in textbox 2
  13.         Text2.Text = b 'Int((10 - 0 + 1) * Rnd() + 0)
  14.         'clear textbox 3 for the answer
  15.         Answer.Text = ""
  16.     End Sub
  17.  
  18.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  19.         a = Mid(System.DateTime.Now.Millisecond, 1, 1)
  20.         System.Threading.Thread.Sleep(CInt(a) + 284)
  21.         b = Mid(System.DateTime.Now.Millisecond, 1, 1)
  22.  
  23.         Dim sum As String
  24.         x = Answer.Text
  25.         sum = Val(Text1.Text) + Val(Text2.Text)
  26.  
  27.         If x = sum Then
  28.             score = score + 1
  29.             MsgBox("Good Job!")
  30.             'put random number in textbox 1
  31.             Text1.Text = a 'Int((10 - 0 + 1) * Rnd() + 0)
  32.             'put random number in textbox 2
  33.             Text2.Text = b 'Int((10 - 0 + 1) * Rnd() + 0)
  34.             'clear textbox 3 for the answer
  35.             Answer.Text = ""
  36.  
  37.         Else
  38.             MsgBox("wrong")
  39.             ' put random number in textbox 1
  40.             Text1.Text = Int((10 - 0 + 1) * Rnd() + 0)
  41.             ' put random number in textbox 2
  42.             Text2.Text = Int((10 - 0 + 1) * Rnd() + 0)
  43.             ' clear textbox 3 for the answer
  44.             Answer.Text = ""
  45.         End If
  46.  
  47.         txtscore.Text = score
  48.     End Sub
  49.  
NOTE: i did this in vb2005 but should work in vb6
Mar 25 '08 #4
jg007
283 Contributor
as far as I am aware RND() generates a random value based on system time/data so should not be the same although I did used to use randomise at the start of programs but I am not sure if that was necessary
Mar 25 '08 #5
Killer42
8,435 Recognized Expert Expert
as far as I am aware RND() generates a random value based on system time/data so should not be the same although I did used to use randomise at the start of programs but I am not sure if that was necessary
In VB6, you need to use the Randomize statement to seed the pseudo-random number generator. If you don't, it will produce the same series of numbers each time. I think Randomize uses the system time, unless you provide a seed.
Mar 26 '08 #6
Killer42
8,435 Recognized Expert Expert
...Int((10 - 0 + 1) * Rnd() + 0)
Is this being done to illustrate what is normally added/subtracted in these circumstances, or what? Because it seems as though you could get the same result with Int(11 * Rnd()).
Mar 26 '08 #7

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

Similar topics

3
1414
by: hazz | last post by:
if i have a table record called Rule 1 with 1. table name 2. table column name 3. operator (>,< =) 4. value (0 to n) 5. score how could I create code to create a rule automatically so that i could create an object to compare to these rules in the database.
0
2182
by: kristian | last post by:
Hi. I read somewhere that there is a limit to the way the score is calculated. As far as I remember the problem was that if the keyword in the search string was present more than N times the score would be wrong. Can anyone comfirm this or point me to the limitations of the score? I have read about it on mysql.com but Im unable to find anything about the actual score calculation.
2
3407
by: windsorben | last post by:
How would I pass the student's final score to a hidden form field? <script language="javascript" type="text/javascript"> <!-- var score = 0;
54
6648
namcintosh
by: namcintosh | last post by:
First of all, here is my program: #include <iostream> #include <conio> using namespace std; //Function prototype void getscore(int&, int&, int&, int&, int&); void findLowest (int, int, int, int, int, int); int main()
1
1688
by: cutzz | last post by:
Hi u all, i've made a 10 paged asp quiz. at the end of the quiz u will recieve a score. the script is shown below. my answer = how can i save this score into a database? <!-- #include file="functions.asp" --> <% function content %>
5
2998
by: eliana82 | last post by:
I have problems calculating score percentages within groups. I have created a boat program in access where the information provided is name, team, boat and score. The first query I've done is to produce the ranking according to the score, which worked fine. The second query is about giving 100% to the highest score per boat and then taking the percentage of that score and calculate the rest of the team scores according to that score;...
1
3412
by: Flanders | last post by:
I have developed a small arcade game with the help of a few VB books. A scoring system was implemented in the design of the game but I as hoping that some one would be able to instruct me on how display the score at the end of the game. At the moment when a player finishes the game I have a window displaying "Puzzle Solved." If I could display the players score under this in the same window would be great. This is a quick copy and paste...
4
5421
by: kyle christian | last post by:
I am trying to save the high scores of a game I made. Now Im stumped on trying to search through the file. Should I use a string, array, or one of the STL containers to manipulate the information read from the file? I have tried the stringname.find("Name"); This only returns the first occurence, and doesn't look for other occurences.
3
8904
by: hamishmcgee | last post by:
Ok, so for a project at university I have to create a High Score table in C++ with Visual Studio. Just to let you know this is my first year at university and also my first time ever learning C++. So far I have a working menu, which lets you enter in your name, highscore and date which then gets saved to a file and is outputted via another option on the menu. I had a lot of trouble gettin the user info to save to a file in the first place, then...
0
9860
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9699
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10603
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7023
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5685
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4076
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3138
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.