How Can I Remove two random buttons (1 Viewer)

murray83

Games Collector
Local time
Today, 19:10
Joined
Mar 31, 2017
Messages
728
Good Morning

i have the attached at the moment and am trying to think of how to add lifeline style buttons

on Q1 i have added a button ( not yet coded ) but when this is pressed i would like it to remove to wrong answers but leave the right and one wrong

I'm thinking i may need to assign the buttons numbers and then say something like

Code:
Private Sub cmd_5050_Click()

select number between 1 and 3 

if number = 1 then 
cmd_Q1a.visble = false
  if number = 3 then
  cmd_Q1d.visible = false
end if 
  end if 

End Sub

but i admit this is all back of the envelope thinking and may not be possible as i'm not sure how i would assign a number to a command button

help much appreciated

cheers
 

Attachments

  • Quiz.mdb
    628 KB · Views: 48

missinglinq

AWF VIP
Local time
Today, 14:10
Joined
Jun 20, 2003
Messages
6,423
I'm going to take a wild guess here that the reason 30+ members have read this post, but none have responded, is because, like myself, they have no idea what this means:

murray83 said:
...i would like it to remove to wrong answers but leave the right and one wrong...
Linq ;0)>
 

isladogs

MVP / VIP
Local time
Today, 19:10
Joined
Jan 14, 2017
Messages
18,209
Hi linq

Think about the quiz show "Who wants to be a millionaire" where they remove two wrong answers to reduce the list leaving one correct and one wrong.
 

murray83

Games Collector
Local time
Today, 19:10
Joined
Mar 31, 2017
Messages
728
Hi linq

Think about the quiz show "Who wants to be a millionaire" where they remove two wrong answers to reduce the list leaving one correct and one wrong.

yes just like that
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:10
Joined
Feb 28, 2001
Messages
27,146
The trick is that if it is truly random, your first iteration of trying to select a random number might pick NONE of the buttons - or ALL of them. Random numbers are unpredictable like that. ;)

I might build an array and load it with four random numbers. Each member of the array would correspond to one of the buttons. Then I would block the "right" answer by changing the random number generated for that slot to 0. Then I would pick the largest of the three remaining numbers, "vanish" the other two buttons, and done!

You could do this with a loop to find the maximum slot followed by a SELECT CASE statement that would look maybe like...

Code:
   Randomize
   ...
   For I = 1 to 4
      RSlot(I) = Rnd()
   Next I
   RSlot(CorrectSlot) = 0
   MaxSlot = 1
   For I = 1 to 4
     If RSlot(I) > RSlot(MaxSlot) Then MaxSlot = I
   Next I
   Select Case MaxSlot
      Case 1
         If RSlot(2) <> 0 then Button2.Visible = False
         If RSlot(3) <> 0 then Button3.Visible = False
         If RSlot(4) <> 0 then Button4.Visibe = False
      Case 2
         If RSlot(1) <> 0 then Button1.Visible = False
         If RSlot(3) <> 0 then Button3.Visible = False
         If RSlot(4) <> 0 then Button4.Visibe = False
      Case 3
         etc.
      Case 4
         etc.
   End Select
 

murray83

Games Collector
Local time
Today, 19:10
Joined
Mar 31, 2017
Messages
728
have made this addition to my code (see attached) as suggested by you good folk, but errors and i'm not sure why.

after a google search i'm none the wiser, if you could just help with whats wrong but not fix it for me (for know, until i beg for help) that would be ace

as i need to learn more

ta
 

Attachments

  • fault.jpg
    fault.jpg
    91.9 KB · Views: 46

isladogs

MVP / VIP
Local time
Today, 19:10
Joined
Jan 14, 2017
Messages
18,209
Add Option Explicit as the 2nd line in your module
Debug and define RSlot as a suitable variable type
Fix any other errors that debug finds


Sent from my iPhone using Tapatalk
 

murray83

Games Collector
Local time
Today, 19:10
Joined
Mar 31, 2017
Messages
728
Add Option Explicit as the 2nd line in your module
Debug and define RSlot as a suitable variable type
Fix any other errors that debug finds


Sent from my iPhone using Tapatalk

ok thanks for that have managed to drag it a bit further but hit another wall :banghead:

here is my current code

Code:
Option Compare Database
Option Explicit
RSlot As Integer


Private Sub cmd_5050_Click()

Randomize ' Initialize random-number generator.

 For i = 1 To 4
      RSlot(i) = Rnd()
   Next i
   RSlot(CorrectSlot) = 0
   MaxSlot = 1
   For i = 1 To 4
     If RSlot(i) > RSlot(MaxSlot) Then MaxSlot = i
   Next i
   Select Case MaxSlot
      Case 1
         If RSlot(2) <> 0 Then cmd_Q1a.Visible = False
         If RSlot(3) <> 0 Then cmd_Q1c.Visible = False
'      Case 2
'         If RSlot(1) <> 0 Then Button1.Visible = False
'         If RSlot(3) <> 0 Then Button3.Visible = False
'         If RSlot(4) <> 0 Then Button4.Visibe = False
'      Case 3
'
'      Case 4
         
   End Select

End Sub

but then it says what is in the attached

i believe i still am missing some defention as if i put this

Code:
Option Compare Database
Option Explicit
Dim RSlot As Integer


Private Sub cmd_5050_Click()

Randomize ' Initialize random-number generator.

instead of the above i get 'varibale not defiend error' also attached
 

Attachments

  • erro1.png
    erro1.png
    23.7 KB · Views: 44
  • variable not defiend.png
    variable not defiend.png
    33 KB · Views: 34

murray83

Games Collector
Local time
Today, 19:10
Joined
Mar 31, 2017
Messages
728
Update just added
Code:
Dim I As Integer
and now shouting at me expected array brb
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:10
Joined
Feb 28, 2001
Messages
27,146
Sorry, I should have added DIM statements. What I gave you was "air" code. I sometimes do that when shooting from the hip.

Dim RSlot(1 to 4) As Single
Dim MaxSlot As Integer


Substitute for "correctslot" with the slot number for the correct answer, which would have to be known before you begin this exercise. You ALSO need to make all four buttons visible LONG before you call this code.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:10
Joined
May 7, 2009
Messages
19,229
dim RSlot(1 to 4) As Double

for integer, you need to cast it:

Dim RSlot(1 to 4) As Integer
Dim I As Integer
Dim j As Integer
Dim k As String
Randomize
For I = 1 to 4
j=CInt((Rand()*4)+1)
While Instr(k, j & ",") <> 0 Or j=0
j=CInt((Rand()*4)+1)
Wend
k = k & j & ","
RSlot(I)=j
Next
 

murray83

Games Collector
Local time
Today, 19:10
Joined
Mar 31, 2017
Messages
728
Sorry, I should have added DIM statements. What I gave you was "air" code. I sometimes do that when shooting from the hip.

Dim RSlot(1 to 4) As Single
Dim MaxSlot As Integer


Substitute for "correctslot" with the slot number for the correct answer, which would have to be known before you begin this exercise. You ALSO need to make all four buttons visible LONG before you call this code.

cheers, ok almost working but having some fun with the correct slot, which i will work on later

and yes the buttons are visible on form open/load
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:10
Joined
Feb 28, 2001
Messages
27,146
Might need them visible "OnCurrent" if the form doesn't close between questions.

And the RSlot can be Single because RND() returns a Single. And all you do is compare it or set it to zero, so it will not be a problem as a Single.
 

murray83

Games Collector
Local time
Today, 19:10
Joined
Mar 31, 2017
Messages
728
tried this

Code:
RSlot(RSlot(4)) As Single

and got the attached named "Today's Error"


then tried this

Code:
RSlot(RSlot(4) As Single) = 0

and got the expected end of statement :(
 

Attachments

  • todays error.png
    todays error.png
    30.5 KB · Views: 41

isladogs

MVP / VIP
Local time
Today, 19:10
Joined
Jan 14, 2017
Messages
18,209
Not sure what you wrote is correct but you forgot the Dim statement anyway
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:10
Joined
Feb 28, 2001
Messages
27,146
Code:
Dim RSlot(1 to 4) As Single

The reason I suggested single is to minimize other manipulation since you don't care what it contains as long as it is declared properly and assigned a value in that loop that loads it for each set of questions. This would go in the declaration area of the function (i.e. between the Function declaration and the first executable instruction.)
 

JHB

Have been here a while
Local time
Today, 20:10
Joined
Jun 17, 2012
Messages
7,732
You do not have to create a form for each question, it is a painless act to maintain such a application, (wonder why some of the other members here, haven't told you that?).
Instead you should use one form for all questions, and have all the choices in a table.
And then the data (questions and choices) should be stored vertically and not horizontally, (as you do for the questions).
A sample database is attached, I have written some comments in the code.
 

Attachments

  • Quiz.zip
    87.4 KB · Views: 36

murray83

Games Collector
Local time
Today, 19:10
Joined
Mar 31, 2017
Messages
728
You do not have to create a form for each question, it is a painless act to maintain such a application, (wonder why some of the other members here, haven't told you that?).
Instead you should use one form for all questions, and have all the choices in a table.
And then the data (questions and choices) should be stored vertically and not horizontally, (as you do for the questions).
A sample database is attached, I have written some comments in the code.

thanks shall check it out
 

murray83

Games Collector
Local time
Today, 19:10
Joined
Mar 31, 2017
Messages
728
one question how do i change the questions as i tried to change it so uses my questions which you have still in there but complains due to some linking of the tables
 

JHB

Have been here a while
Local time
Today, 20:10
Joined
Jun 17, 2012
Messages
7,732
Change the "Question Round No" to 1, then your questions will be active!
 

Attachments

  • QuestionRound.jpg
    QuestionRound.jpg
    37.8 KB · Views: 184

Users who are viewing this thread

Top Bottom