There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
blue screen blue screen of death boot computer connection crash css dell display driver drivers email error excel firefox firefox 3 game hard drive internet internet explorer itunes laptop lcd linux malware monitor network networking nvidia outlook outlook 2003 outlook express partition password printer problem problems ram router security slow sound trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Solved: VB Dilema


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
Rutter's Avatar
Senior Member with 257 posts.
 
Join Date: Dec 2001
Location: Liverpool, UK
Experience: A Little . . .
07-Dec-2004, 05:49 PM #1
Question Solved: VB Dilema
I am currently tring to write code for a simple maths project, but I am having amazing difficulty trying to remember some of the stuff I learnt in VB when I last studied it, many moons ago (last year actually!).

My problem is I am trying to calculate how many unsucessful attempts have been made a question bfore getting it right.

I thought I could keep track of this by just using y=y+1 stating y as an variable at the begining, but all this does is add from 0 to 1. I have posted my code below and highlighted this problem in red.

My second problem is in trying to find out if the question is right from an answer entered into a text box. I orginally developed the programme to check the answer entered into the text box against the answer which was placed in a label caption.

I then thought, there is no need for that I should be able to just check the text against the Dim variable 'total', this just produces a permenantly wrong answer! This is highlighted in green .

Has anyone got any ideas?

Any Help greatly appreciated
Rutter
________________________________________________________________

Private Sub Form_Load()
Dim x, y, z, total, temp
Dim number1, number2 As Double
Label4.Caption = y
Call NewQ

End Sub

-------------------------------------------------------------------------

Private Sub Command2_Click()
If
Text1.Text = total Then
Randomize
z = Int(((4 - 1 + 1) * Rnd) + 1)
If z = 1 Then
MsgBox "Very Good!", vbOKOnly, "MathsTutor"
ElseIf z = 2 Then
MsgBox "Nice Work!", vbOKOnly, "MathsTutor"
ElseIf z = 3 Then
MsgBox "Brilliant!", vbOKOnly, "MathsTutor"
ElseIf z = 4 Then
MsgBox "Excellent!", vbOKOnly, "MathsTutor"
End If
y = 0

Call NewQ

ElseIf Text1.Text = "" Then
MsgBox "Please Enter A Number", vbOKOnly, "MathsTutor"

y = y + 1

Else:
MsgBox "Sorry Wrong Answer!", vbOKOnly, "MathsTutor"

End If
Text1.Text = ""
y = y + 1
Label4.Caption = y
End Sub
__________________
"Some day a computer intelligence will arrise that is capable of being aware of the entirety of human thought and expression stored on the web.. and it will be completely useless because no one will be able to get it to stop laughing."
John L Williams
Mosaic1's Avatar
Distinguished Member with 7,502 posts.
 
Join Date: Aug 2001
07-Dec-2004, 06:45 PM #2
Without going into a lot of detail, I would think you would need to remember that a variable and its new data is not remembered or accessible after a particular event is over unless you declare it with a greater scope.
Rutter's Avatar
Senior Member with 257 posts.
 
Join Date: Dec 2001
Location: Liverpool, UK
Experience: A Little . . .
08-Dec-2004, 12:50 PM #3
Sorry not really understanding, how do I decale a variable with greated scope? I presume by this you mean that I need to have VB remember both the variables each time they change . .

Thanks Rutter
Rutter's Avatar
Senior Member with 257 posts.
 
Join Date: Dec 2001
Location: Liverpool, UK
Experience: A Little . . .
08-Dec-2004, 04:57 PM #4
Managed to solve my problem, just in case anyone wanted to know -

I had to declare my variables at the Command1_click event as static variables.

Didn't manage to work out ehy but it works!
Mosaic1's Avatar
Distinguished Member with 7,502 posts.
 
Join Date: Aug 2001
08-Dec-2004, 06:00 PM #5
This is what scope means. By declaring as Static, the changes in the variable are carried over and available as changed the next time you click. Otherwise they would go back to their original value.
Rutter's Avatar
Senior Member with 257 posts.
 
Join Date: Dec 2001
Location: Liverpool, UK
Experience: A Little . . .
09-Dec-2004, 09:48 PM #6
Yeah, I got it, just while your on the subject or variables, I need to declare a variable that counts up from 0 to how ever many record there are in my text file, then goes back to 0 after the last file, because at the moment when I'm viewing my records they just keep gong up and up.

The problem I have is I need that value to be stored even when the program isn't running, so next time it starts up it can write the next record to the next avaliable space
__________________
"Some day a computer intelligence will arrise that is capable of being aware of the entirety of human thought and expression stored on the web.. and it will be completely useless because no one will be able to get it to stop laughing."
John L Williams
Mosaic1's Avatar
Distinguished Member with 7,502 posts.
 
Join Date: Aug 2001
10-Dec-2004, 10:56 AM #7
After you read the last one, reset. Do you have the code for how you are currently doing this?
If you want to store something, you can either store a number in a text file or preferably the registry. Write some code to retreive that variable when you need it and to reset it when you need to do that.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 02:41 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.