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. - Private Sub cmdcheck_Click()
-
Dim score As Integer
-
score = score + 1
-
txtscore.Text = score
-
Dim sum As String
-
x = Answer.Text
-
sum = val(text1.Text) + val(Text2.Text)
-
-
If x = sum Then
-
score = score + 1
-
MsgBox "Good Job!"
-
'put random number in textbox 1
-
text1.Text = Int((10 - 0 + 1) * Rnd + 0)
-
'put random number in textbox 2
-
Text2.Text = Int((10 - 0 + 1) * Rnd + 0)
-
'clear textbox 3 for the answer
-
Answer.Text = ""
-
-
Else
-
-
MsgBox "wrong"
-
' put random number in textbox 1
-
text1.Text = Int((10 - 0 + 1) * Rnd + 0)
-
' put random number in textbox 2
-
Text2.Text = Int((10 - 0 + 1) * Rnd + 0)
-
' clear textbox 3 for the answer
-
Answer.Text = ""
-
End If
-
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
6 9084
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. - Private Sub cmdcheck_Click()
-
Dim score As Integer
-
score = score + 1
-
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
Ignore this message. I'm just "subscribing" to the discussion thread so I can find it again later.
Try this -
Dim score As Integer = 0
-
Dim x As String = Nothing
-
-
-
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
'put random number in textbox 1
-
Text1.Text = Int((10 - 0 + 1) * Rnd() + 0)
-
'put random number in textbox 2
-
Text2.Text = Int((10 - 0 + 1) * Rnd() + 0)
-
'clear textbox 3 for the answer
-
Answer.Text = ""
-
End Sub
-
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
Dim sum As String
-
x = Answer.Text
-
sum = Val(Text1.Text) + Val(Text2.Text)
-
-
If x = sum Then
-
score = score + 1
-
MsgBox("Good Job!")
-
'put random number in textbox 1
-
Text1.Text = Int((10 - 0 + 1) * Rnd() + 0)
-
'put random number in textbox 2
-
Text2.Text = Int((10 - 0 + 1) * Rnd() + 0)
-
'clear textbox 3 for the answer
-
Answer.Text = ""
-
-
Else
-
MsgBox("wrong")
-
' put random number in textbox 1
-
Text1.Text = Int((10 - 0 + 1) * Rnd() + 0)
-
' put random number in textbox 2
-
Text2.Text = Int((10 - 0 + 1) * Rnd() + 0)
-
' clear textbox 3 for the answer
-
Answer.Text = ""
-
End If
-
-
txtscore.Text = score
-
End Sub
-
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. -
Dim a As String
-
a = System.DateTime.Now.Millisecond
-
MABY THIS WILL WORK UNLESS SOMEONE CAN SUGGEST ANY BETTER: -
Dim score As Integer = 0
-
Dim x As String = Nothing
-
Dim a As String
-
Dim b As String
-
-
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
a = Mid(System.DateTime.Now.Millisecond, 1, 1)
-
System.Threading.Thread.Sleep(CInt(a) + 284)
-
b = Mid(System.DateTime.Now.Millisecond, 1, 1)
-
'put random number in textbox 1
-
Text1.Text = a 'Int((10 - 0 + 1) * Rnd() + 0)
-
'put random number in textbox 2
-
Text2.Text = b 'Int((10 - 0 + 1) * Rnd() + 0)
-
'clear textbox 3 for the answer
-
Answer.Text = ""
-
End Sub
-
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
a = Mid(System.DateTime.Now.Millisecond, 1, 1)
-
System.Threading.Thread.Sleep(CInt(a) + 284)
-
b = Mid(System.DateTime.Now.Millisecond, 1, 1)
-
-
Dim sum As String
-
x = Answer.Text
-
sum = Val(Text1.Text) + Val(Text2.Text)
-
-
If x = sum Then
-
score = score + 1
-
MsgBox("Good Job!")
-
'put random number in textbox 1
-
Text1.Text = a 'Int((10 - 0 + 1) * Rnd() + 0)
-
'put random number in textbox 2
-
Text2.Text = b 'Int((10 - 0 + 1) * Rnd() + 0)
-
'clear textbox 3 for the answer
-
Answer.Text = ""
-
-
Else
-
MsgBox("wrong")
-
' put random number in textbox 1
-
Text1.Text = Int((10 - 0 + 1) * Rnd() + 0)
-
' put random number in textbox 2
-
Text2.Text = Int((10 - 0 + 1) * Rnd() + 0)
-
' clear textbox 3 for the answer
-
Answer.Text = ""
-
End If
-
-
txtscore.Text = score
-
End Sub
-
NOTE: i did this in vb2005 but should work in vb6
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
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.
...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()).
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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;
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
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++....
|
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,...
|
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...
| |
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...
|
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...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
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...
| |