The Student Room Group

Computer Science problem GCSE

Hi everyone! so for a practise CA (in visual basic 2010), we had to design this flash card type game having been given a task brief. The idea is that a keyword is displayed along with three definitions two which are random and one matching one. My programme works apart from the fact that sometimes I click on the correct definition but it tells me that it's wrong.

I created a variable called labeldecider which is a randomly generated integer between 1 and 3.

This is what I wrote in my code:


Sub WriteCorrectAnswer()

Randomize()
labeldecider = Int((3 * Rnd()) + 1) ' this random number decides where the correct definition will go

Select labeldecider

Case Is = 3
Label4.Text = matchdef 'matchdef is the correct definition
Case Is = 2
Label3.Text = matchdef
Case Is = 1
Label2.Text = matchdef
End Select
End Sub

The programme will work normally and then 'randomly' when you click the correct answer, it will tell you that it is incorrect. I have tested the label decider by showing it in a label. When the correct answer is deemed 'incorrect' the labeldecider is not the value it should be. (sorry i can't explain it very well)

E.g.

keyword: alveoli

option1: tiny air sacs
option2: smallest microbe
option3: dead form of microbe

By looking at the options the labeldecider should be 1 but when testing, it will show 2 or 3 even though my code is specific to each number labeldecider could be.

N.B: the rest of the programme seems ok and I have already tried resetting the the labeldecider to 0 before it is randomised to prevent any overwriting.

My teacher and I have tried a lot of things but nothing seems to be working.
If you need any more code snippets just ask :smile:


Thank you to everyone in advance
Reply 1
Do you have TeamViewer or Join.Me?
If you grab one then just PM me, I'll try to walk you through it :smile:
Reply 2
Original post by bleekbaz
Hi everyone! so for a practise CA (in visual basic 2010), we had to design this flash card type game having been given a task brief. The idea is that a keyword is displayed along with three definitions two which are random and one matching one. My programme works apart from the fact that sometimes I click on the correct definition but it tells me that it's wrong.

I created a variable called labeldecider which is a randomly generated integer between 1 and 3.

This is what I wrote in my code:


Sub WriteCorrectAnswer()

Randomize()
labeldecider = Int((3 * Rnd()) + 1) ' this random number decides where the correct definition will go

Select labeldecider

Case Is = 3
Label4.Text = matchdef 'matchdef is the correct definition
Case Is = 2
Label3.Text = matchdef
Case Is = 1
Label2.Text = matchdef
End Select
End Sub

The programme will work normally and then 'randomly' when you click the correct answer, it will tell you that it is incorrect. I have tested the label decider by showing it in a label. When the correct answer is deemed 'incorrect' the labeldecider is not the value it should be. (sorry i can't explain it very well)

E.g.

keyword: alveoli

option1: tiny air sacs
option2: smallest microbe
option3: dead form of microbe

By looking at the options the labeldecider should be 1 but when testing, it will show 2 or 3 even though my code is specific to each number labeldecider could be.

N.B: the rest of the programme seems ok and I have already tried resetting the the labeldecider to 0 before it is randomised to prevent any overwriting.

My teacher and I have tried a lot of things but nothing seems to be working.
If you need any more code snippets just ask :smile:


Thank you to everyone in advance


Have you stepped through the code running one line at a time to try to find exactly where the problem arises?

Quick Reply

Latest

Trending

Trending