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 3396
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: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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: 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,...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |