Private Sub cmd1back_Click()
fmeMain.Visible = True
fmeMain.ZOrder
fmeQ1.Visible = False
End Sub
Private Sub cmd2back_Click()
fmeQ2.Visible = False
fmeQ1.ZOrder
fmeQ1.Visible = True
End Sub
Private Sub cmd2next_Click()
Dim q2 As Integer
Select Case True
Case q2 = 0
If opt2a.Value = True Then
q2 = 1
fmeQ2.Visible = False
fmeQ3.ZOrder
fmeQ3.Visible = True
Else
fmeQ2.Visible = False
fmeQ3.ZOrder
fmeQ3.Visible = True
End If
Case q2 = 1
fmeQ2.Visible = False
fmeQ3.ZOrder
fmeQ3.Visible = True
End Select
End Sub
Private Sub cmd3back_Click()
fmeQ3.Visible = False
fmeQ2.ZOrder
fmeQ2.Visible = True
End Sub
Private Sub cmd3finish_Click()
Dim q3 As Integer
If opt3c.Value = True Then
q3 = 1
MsgBox ("Your score is " & q1 + q2 + q3), vbExclamation + vbOKOnly, "Congrats"
End
Else
MsgBox ("Your score is " & q1 + q2 + q3), vbExclamation + vbOKOnly, "Congrats"
End
End If
End Sub
Private Sub cmdStart_Click()
fmeMain.Visible = False
fmeQ1.ZOrder
fmeQ1.Visible = True
End Sub
Private Sub cmd1next_Click()
Dim q1 As Integer
Select Case True
Case q1 = 0
If opt1b.Value = True Then
q1 = 1
fmeQ1.Visible = False
fmeQ2.ZOrder
fmeQ2.Visible = True
Else
fmeQ1.Visible = False
fmeQ2.ZOrder
fmeQ2.Visible = True
End If
Case q1 = 1
fmeQ1.Visible = False
fmeQ2.ZOrder
fmeQ2.Visible = True
End Select
End Sub
this is my entire code for the program.. this is an mock exam i made in vb6. as the title says i want it to place the exact score in the title box. however it only tells the score in the last frame
8 3390
Is it possible to attach your vb codes in bytes? (go to "adavced" * "additional options" - "manage attachments", ...)
there are some irregularities:
- select case: ??? - Select Case True
-
Case q2 = 0
Must be:
- End in If Then ??? - MsgBox ("Your score is " & q1 + q2 + q3), vbExclamation + vbOKOnly, "Congrats"
-
End
-
Else
PS:
Always use indents :
- easier to discover errors.
- Reads faster.
Hi,
Declare a Form Level Variable, say Dim MyScore As Integer.
Adda Textbox/Label Control on the top of the form...(Not inside frame)
@ the beginning, initialize it with Zero.
Keep adding score, in Next button, and deisplay in the Text/label...
Regards
Veena
Do what QVeen72 said, which is an easy and reusable way of coding, or try changing your messagebox statement to - MsgBox ("Your score is " & (q1 + q2 + q3))
.
I get the feeling that when you invoke the message box object, it joins (&) the text with q1 before adding and joining q2 and q3. Do you get a partial score that is equal to score- q1? Experiement around with some easy numbers and check your result with the expected value to see if this is the case. Good luck!:)
There are various issues, as others have pointed out.
However, I believe your fundamental problem is that the variables q1, q2 and q3 are defined as local to the routines where they're used. That means they only exist within that routine. For example, q1 exists only within the method cmd1next_Click. That means that when you display your message box, no variables called q1 or q2 exist. Because you have your VB options set to allow this, VB helpfully creates them for you - but obviously these new variables don't contain any values. So what you're effectively calculating there is "q3 + 0 + 0".
There are two things you should do. - To correct the immediate problem, define q1, q2 and q3 in the declarations section of the form (and remove them from the individual methods).
- To prevent this sort of problem and save yourself a lot of headaches in the future, go to Tools | Options | Editor and turn on the option "Require Variable Declaration". This will prevent you from using variables which don't exist, by adding the line "Option Explicit" at the start of each new form and module. Since that applies when forms/modules are created, you should manually enter it at the top of the declarations section of this current form.
Hope this helps.
P.S. I think the "q1 + q2 + q3" is actually working alright, kiseitai2 (once we allow for the variable-scope issue described above). But adding the parentheses certainly won't hurt, and does make it a bit more obvious what's intended.
Haha! I totally missed the scope issue. How noobish of me! I guess it's my coding style, but I usually use a minimal number of redundant parentheses to make sure the statement is explicit. After all, a compiler follows logic and an ambiguous statement (an statement with more than one way to interpret) can be dangerous since you can't predict how the compiler will handle it (unless you have already tested the code and confirmed the result). Also, it helps human readers.
that single line of code u posted kiseitia2 saved me a tone of time on my work
That's the great thing about these archives, of course. Here it is almost three years later, and this answer is still helping people.
Nice! I never thought that the few times I have been able to contribute helped others this much!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: VB Programmer |
last post by:
I would like my error handler to pop up a message on my webform. How do you
do this?
Currently I'm using System.Web.HttpContext.Current.Response.Write("MY
ERROR")
Any ideas? Thanks!
|
by: Roland Hall |
last post by:
Since I'm not getting any response from the community, I'm reposting this
under my managed account.
I've turned my web.config friendly error messages off and it may be easier
to view what I'm...
|
by: Andy Sutorius via DotNetMonster.com |
last post by:
I have a legacy dll built in C++ 6.0 (not a com dll, just a plain dll without
a type library). I am using Interop Services to call this dll from an aspx.cs
page (). However when I place the dll in...
|
by: Taras_96 |
last post by:
Hi everyone,
We' ve come to the conclusion that we wish the user to be directed to
an error page if javascript is disabled <enter comment about how a
webpage shouldn't rely on javascript here :)...
|
by: =?Utf-8?B?U3RldmVU?= |
last post by:
Under Vista, my program, when reading the system event log, will not show the
message saying I don't have the right permission. All I wisht to do is read
the event log and show the error messages....
|
by: =?Utf-8?B?VG9ueQ==?= |
last post by:
Can anyone tell me in easy terms how I stop the error messages i'm getting
starts off with winzip extrctor cant creat output file then a run time error
429 then lots of regsvr32 please help
|
by: cpptutor2000 |
last post by:
Could someone please help me? I have the following C struct.
typedef struct
_FIREWALL_RULE_INFO
{
ULONG Precedence;
BOOL bEnabled;
BOOL ...
|
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: axapta |
last post by:
Hi Group,
I've got a search screen whereby it could take a couple of seconds or
minutes for the results to be returned. Is there a way to place a "working
message" in the taskbar area, so the...
|
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: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |