Looking for help with creating a quiz app

madmadhouse

Member
Licensed User
Longtime User
I have been watching a you tube video tutorial, and got this far, but it doesnt go on to say how to implement another question into the coding, I followed the tutorial all the way into later adding music and pictures and background etc, but part 6 is missing and i fell i shall never know, I am hoping there is someone out there that can help me please

B4X:
'Activity module
Sub Process_Globals
   

End Sub

Sub Globals
   Dim Button1 As Button
   Dim AnsText1 As EditText
   Dim Label2 As Label

End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("q1.bal")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
   If AnsText1.Text.ToLowerCase = "world wide web" Then
   Label2.TextColor = Colors.Green
   Label2.Text = "Correct"
   Else
   Label2.TextColor = Colors.Red
   Label2.Text = "Wrong"
   End If
End Sub
 

AllyAndroid

Member
Licensed User
Longtime User
You could try something like this if you only have a few question/answers.

  1. Add a second button for "Next Question".
  2. Create a variable to track number of questions.
  3. Create a variable for the questions.
  4. Create a variable for the answers.

B4X:
Sub Process_Globals
End Sub
Sub Globals
   Dim Label1 As Label
   Dim Label2 As Label
   Dim Button1 As Button
   Dim Button2 As Button
   Dim AnsText1 As EditText

   Dim qNo As Int
   Dim qText As String
   Dim aText As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("q1.bal")
End Sub
Sub Activity_Resume
   Button2_Click
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
   If AnsText1.Text.ToLowerCase = aText Then
      Label2.TextColor = Colors.Green
      Label2.Text = "Correct Answer"
   Else
          Label2.TextColor = Colors.Red
          Label2.Text = "Wrong Answer"
   End If
End Sub
Sub Button2_Click
   qNo = qNo + 1
      If qNo = 4 Then   qNo = 1

   Select Case qNo
      Case 1
         qText = "Question #1"
         aText = "answer 1"
      Case 2
         qText = "Question #2"
         aText = "answer 2"
      Case 3
         qText = "Question #3"
         aText = "answer 3"
   End Select

   Label1.Text = qText
   Label2.text = ""
End Sub
 
Upvote 0

madmadhouse

Member
Licensed User
Longtime User
Excellent thankyou!!!! I should be able to run off a quiz with 10 questions quite easily now thankyou
 
Last edited:
Upvote 0

madmadhouse

Member
Licensed User
Longtime User
Sorry another quick question..

I have done a few questions, think i'm getting good at this, good practice too.. I have gone through the tutorial pdf but am very lost, the auto sizing scaling and dips etc, i want my page to be able to be playable on the mobile phones, and also not look stupidly tiny on my partners nexus 10... but i dont understand from the tutorial and the files in the files examples how i can implement this into my file.. I have tried various bots of it but with no success... yeas i know thats because I dont know what i'm doing! lol

Thanks in advance :)
 
Upvote 0

madmadhouse

Member
Licensed User
Longtime User
That does the job thanks! How would I go about ending the quiz, as it is it never ends, so it possibly comes up with "play again"? and it restarts from question 1

I have a message box come up like this
B4X:
Msgbox2("You have done well", "Start Again, "", "Finish", "", Null)

But want to know how to implement when the button is pressed it either ends the application (finish) or starts again
 
Last edited:
Upvote 0

madmadhouse

Member
Licensed User
Longtime User
Firstly let me thank Erel for sorting out my licensing problem :)

Secondly in response to my query above

That does the job thanks! How would I go about ending the quiz, as it is it never ends, so it possibly comes up with "play again"? and it restarts from question 1

I have a message box come up like this
Code:
Msgbox2("You have done well", "Start Again, "", "Finish", "", Null)

I found i couldnt solve the restart problem, so just settled for the exit application only by using the code
B4X:
If Counter = 11 Then
      result = Msgbox2("You have done well", "Restart", "", "", "Exit", Null)
   If result = DialogResponse.NEGATIVE Then
            ExitApplication
        End If
      Counter = 0
   End If

Thanks all for your help in getting me to where i wanted to get to :)
 
Upvote 0

Geezer

Active Member
Licensed User
Longtime User
That does the job thanks! How would I go about ending the quiz, as it is it never ends, so it possibly comes up with "play again"? and it restarts from question 1

I have a message box come up like this
B4X:
Msgbox2("You have done well", "Start Again, "", "Finish", "", Null)

But want to know how to implement when the button is pressed it either ends the application (finish) or starts again

B4X:
If Msgbox2("Do you want to play again ?", "You have done well", "Yes", "", "No", Null) = DialogResponse.POSITIVE Then
   ' PLAY AGAIN
Else
   ' DON'T PLAY AGAIN
End If
 
Upvote 0

Eric H

Active Member
Licensed User
Longtime User
I hope this is within the scope of this thread (if not, please feel free to move it, or let me know and I will start a new one)... I am interested in making a quiz game also. I am trying to look at a larger scope for the project to include, lets say... 1000 questions. I guess the piece of the puzzle that I am trying to figure out is the program flow that would make the most sense for this. I am pretty new to B4A, but I have spent quite a bit of time reading through different examples, tutorials, etc. My IDEA of how this might work is still a bit shaky at this point, but I do have some programming experience, so I'm hoping it will just be a matter of getting the pieces that are unique to this platform sorted out.

Here's what I think I've got so far:
Lets assume I want to make a logo quiz... so I go online and download 1000 different logos and put them in a folder. I rename them 1.png to 1000.png
Then I create a text file and put all the names of the logos in the same order as the image filenames from 1 to 1000.

So does this sound correct?:

- Create an activity (form) for a start/menu screen
- create an activity for a question screen with 4 random answers from a list (1 of which is actually the correct one)
- create an activity for a snazzy full screen animated Correct! sequence that shows the current score and a Next/Continue button
- create an activity for a really sad Incorrect :( sequence with the option to try again, enter your initials, share your score, etc...

How does this sound so far? So far so good? Problems?

Okay... lets go further then...

- I need to store 1000 answers that are tied to 1000 image files (logos).

Would it make sense to use something like a multi-dimensional array and a FOR loop to read the information into an array so that the first array entry would be equal to 1.jpg and the logo name which is in position 1 in the list, then 2.jpg for position 2, etc...

Can someone help me to fill in this bit of things and tell me if the activity list above makes sense?

Thanks!
Eric H
 
Last edited:
Upvote 0

AllyAndroid

Member
Licensed User
Longtime User
Lets assume I want to make a logo quiz... so I go online and download 1000 different logos and put them in a folder. I rename them 1.png to 1000.png
Then I create a text file and put all the names of the logos in the same order as the image filenames from 1 to 1000.

An alternative method to this would be to create an online database and store your names and images in it. The app could then pull down the information when needed. It would help to reduce the size of the app by not having the images compiled with the rest of the code. Plus you could update the information as needed without having to re-upload the app. Having said that, I have an app with over 500 images in it and I didn't use an online database. Add one more item to my todo list.

Create an activity (form) for a start/menu screen
- create an activity for a question screen with 4 random answers from a list (1 of which is actually the correct one)
- create an activity for a snazzy full screen animated Correct! sequence that shows the current score and a Next/Continue button
- create an activity for a really sad Incorrect :( sequence with the option to try again, enter your initials, share your score, etc...

I would create three activities:
  1. Start Activity
  2. Question Activity
  3. Answer Activity
The third activity could be for both Correct and Incorrect answers. You could just display different views depending on the answer.

- I need to store 1000 answers that are tied to 1000 image files (logos).

Would it make sense to use something like a multi-dimensional array and a FOR loop to read the information into an array so that the first array entry would be equal to 1.jpg and the logo name which is in position 1 in the list, then 2.jpg for position 2, etc...

Can someone help me to fill in this bit of things and tell me if the activity list above makes sense?

If you used a database, you could query the 1st record in the table to give you 1.jpg and the logo name associated with it.

Thankyou Geezer:)
Sorry madmadhouse, I kind of lost track of this thread and hadn't realized you still needed help. Glad Geezer was able to get you going again.
 
Upvote 0

Jimmy-1974

Member
Licensed User
Longtime User
An alternative method to this would be to create an online database and store your names and images in it. The app could then pull down the information when needed. It would help to reduce the size of the app by not having the images compiled with the rest of the code. Plus you could update the information as needed without having to re-upload the app. Having said that, I have an app with over 500 images in it and I didn't use an online database. Add one more item to my todo list.


If you used a database, you could query the 1st record in the table to give you 1.jpg and the logo name associated with it.

I did the same tutorial that madmadhouse did from You Tube and managed to achieve a very basic but fully functioning 10+ question Quiz App and am happy to continue to develop my knowledge of B4A by adding questions/ answers and generally playing around with it.

Having said that, I have seen a few posts on Quiz Apps and a few have referred to using databases and am interested how this works (I can do the basics of SQLite). I have searched for tutorials etc but to no avail.

Does anyone have any experience in using databases in Quizzes who could provide a simple example on how this function works to steer me in the right direction?

Many thanks
 
Upvote 0

AllyAndroid

Member
Licensed User
Longtime User
I did the same tutorial that madmadhouse did from You Tube and managed to achieve a very basic but fully functioning 10+ question Quiz App and am happy to continue to develop my knowledge of B4A by adding questions/ answers and generally playing around with it.

Having said that, I have seen a few posts on Quiz Apps and a few have referred to using databases and am interested how this works (I can do the basics of SQLite). I have searched for tutorials etc but to no avail.

Does anyone have any experience in using databases in Quizzes who could provide a simple example on how this function works to steer me in the right direction?

Many thanks

Are you wanting to create a database within the app using SQLite or an online database using something like MySQL and PHP?
 
Upvote 0

Jimmy-1974

Member
Licensed User
Longtime User
A database within the app. The idea is for it to contain a table with the Questions, Answers and Wrong Answers (e.g multiple choice). I have experimented with creating the database using SQLitestudio and then adding it to the asset folder.

Retrieving the information from that database is where I am stuck!
 
Upvote 0

AllyAndroid

Member
Licensed User
Longtime User
An internal database is a lot easier to code.

The first thing I do is check if I am able to write to the external memory (SD Card) or internal. Then I check if the database already exists or not. If it doesn't, I create it and add my default settings. If it does, then I read the settings from the database.

Declare my variables and give them default values:

B4X:
    Public flash_timer As Int: flash_timer = 10    ' In Seconds
    Public pulse_timer As Int: pulse_timer = 250 ' In Milliseconds

Check for database, external or internal:

B4X:
        '### Start SQLite DB Block ###
        Try
            If File.ExternalWritable=False Then
                If File.Exists(File.DirInternal, "settings.db") = False Then
                    SQL1.Initialize(File.DirInternal,"settings.db", True)

                    createTables
                Else
                    SQL1.Initialize(File.DirInternal,"settings.db", True)
                End If
            Else
                If File.Exists(File.DirRootExternal, "settings.db") = False Then
                    SQL1.Initialize(File.DirRootExternal,"settings.db", True)

                    createTables
                Else
                    SQL1.Initialize(File.DirRootExternal,"settings.db", True)
                End If
            End If

            db_check = True
        Catch
            db_check = False
        End Try

       If db_check = True Then
            getSettings
        End If

        '### End SQLite DB Block ###

Create tables and insert add default settings.

B4X:
Sub createTables
' Use if you want to preload setting values into the database.
Dim sqlString As String

    ' Deletes the table if it exists.
    sqlString = "DROP TABLE IF EXISTS setting_table"
        SQL1.ExecNonQuery(sqlString)

    ' Creates the table.
   sqlString = "CREATE TABLE setting_table(flashTimer INT, pulseTimer INT)"
        SQL1.ExecNonQuery(sqlString)

    ' Insert data into the table.
    sqlString = "INSERT INTO setting_table VALUES(" & flash_timer & ", " & pulse_timer & ")"
        SQL1.ExecNonQuery(sqlString)
End Sub

Get settings from database.


B4X:
Sub getSettings
Dim Cursor1 As Cursor
   
    Try
        Cursor1 = SQL1.ExecQuery("SELECT flashTimer, pulseTimer from setting_table")
        For i = 0 To Cursor1.RowCount - 1
            Cursor1.Position = i

            flash_timer = Cursor1.GetInt("flashTimer")
            pulse_timer = Cursor1.GetInt("pulseTimer")
        Next

        Cursor1.Close
    Catch
        createTables
    End Try   
End Sub
 
Upvote 0
Top