Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic (http://www.programmingforums.org/forum18.html)
-   -   Completely new, please help (http://www.programmingforums.org/showthread.php?t=13594)

verion24 Jul 20th, 2007 2:57 AM

Completely new, please help
 
Hi everyone,

I am making a quiz program in Visual Basic 6.0, where the question is answered in a text box, and, if correct, a certain number of marks is added to the displayed score as you go. However, i am confused about what coding for this needs to be done, and what the scored is displayed in (a label perhaps?). So, I ask, could someone give me so example code so i get the idea how to approach this? I know its a amatuer question, but I am having trouble getting my head around what coding to use in certain situations ('if' statements, calculations, etc). Also, could someone give me a good site to learn about this stuff?

Many Thanks in advance :)

PhilBon Jul 20th, 2007 3:21 AM

This sounds like homework. but it's not the school year, at least not for me. The whole point of programming, is taking a problem, splitting it up into smaller problems, then solving those small problems and then putting all the solutions together to solve the big problem. Separate your problems. i.e. score, display of score, etc. Make sure to read the forum rules, there is a link on the right under "site navigation"

verion24 Jul 20th, 2007 4:51 AM

Hi there, thanks for your response. We have been doing programming at school, however this was not set work. I have done a couple of vb "how-to" sheets, and created a few programs this way. I want to create a couple of programs myself at home, to learn it, and have a deeper knowledge of it. I would like to create a quiz, since I think it would be fun and satisfying to test others on a program i've created. If your still not comfortable giving me an example, any hints would be useful.

Duck Jul 20th, 2007 7:54 AM

Do you know how to create a 'Hello World' program? Are you using MS Visual Studio?

big_k105 Jul 20th, 2007 10:32 AM

Well for each question you would have an if statement checking to see if they selected the right answer and if they didn't then it would be wrong. For displaying the score, a label would work fine. More or less the program would just be a bunch of if statements checking to see if they selected the right answer and then part that figures out the score.

verion24 Jul 21st, 2007 12:59 AM

@ Duck: I have heard of the 'hello world' expression before, don't know what it means. Yes, I have Microsoft Visual Studio 6.0.

@ bigk_105: Thanks for your help.

Anyway, now having more of an idea, i gave it another shot, but I must have done something wrong. I have coded for question 1 textbox:

[HTML]

Private Sub txtquestion1_Change(Index As Integer)
If txtquestion1.Text = Beijing Then
lblscore.Caption = Format(txtquestion1.Text + 1)
End If
End Sub

[/HTML]

The answer is supposed to be beijing, but the first line is yellow, and nothing happens when i enter Beijing, and an error comes up. Also, is the third line what you call a calculation?

PhilBon Jul 21st, 2007 1:47 AM

it sees Beijing as a variable, rather than a string. Whenever you want to evaluate a string you must put quotes around it. As well as it should change to a different color. When using VB or VB.Net use [*highlight=vb] Vb Code[/highlight] or [*highlight=vbnet] VB.Net Code[/highlight] without the *. Why are you doing:
:

  1. lblscore.Caption = Format(txtquestion1.Text + 1)

. Is lblscore a Label? If so you might want to check if it should be Text or Caption, In Vb.Net it's Text.

verion24 Jul 21st, 2007 2:56 AM

I have put quotation marks around Beijing now, thanks for that. lblscore.caption is a label, correct. Just so you know, i'm not using VB.net, just the normal version.

With the third line i'm attempting to make lblscore.caption display 1 mark higher than it is currently. I've just realised i've absentmindedly put "txtquestion1.text" in. What should I put instead?

Once again, thanks, I know I'm a bit tedious to deal with since I'm so unfamiliar with vb at the moment.

crawforddavid2006 Jul 21st, 2007 3:41 AM

well as far as scoring, it would probobly be a good idea for a label. Now to keep score, you would want to create a variable and everytime someone gets a question correct you add to the score.

Example
:

  1. Dim Score As Integer
  2.  
  3. Private Sub Command1_Click()
  4.     If Text1.Text = "Test" Then
  5.         Score = Score + 1
  6.         Label1.Caption = Score
  7.     End If
  8. End Sub
  9.  
  10. Private Sub Form_Load()
  11.     Label1.Caption = Score
  12. End Sub


verion24 Jul 21st, 2007 7:43 AM

Hey there. Thanks for the example. Does this mean i need a command button to execute the calculation of the score?:
:

  1.  
  2. Private Sub Command1_Click()


Thanks


All times are GMT -5. The time now is 2:48 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC