i have sharepoint with question and option 1,2,3,4 columns and Answer column as well.
i want to display random question in Label control and 4 options in buttons.
when user select correct answer it will verfiy with Answer colum,n and display message as Correct Answer through label.
how to do this any idea?
Hi @venky232,
Step 3 issue:
Since the collection is only fetched during the OnStart, make sure the OnStart has ran. I expect that your collection was empty at the time of the error.
Button DisplayMode:
Ok to allow this, we might need to change our varEnableButtons variable and DisplayMode of the buttons slightly. Instead of storing true/false, we will store the question linked to the button that is pressed. This way we can uniquely identify which button was actually pressed and disable the other buttons.
(1) Remove the varEnableButtons code from the OnStart
(2) The question buttons OnSelect will look similar to (please adjust if necessary)
//If you show the question text in the button text use Self.Text
//Otherwise use QuestionLabelName.Text of the label which the button corresponds to
Set(varEnableButtons, Self.Text)
(3) Change the varEnableButtons code of the Next Question button:
Set(varEnableButtons, Blank())
(4) DisplayMode of the buttons
If(
//Similar remark here, change to question label text if needed
IsBlank(varEnableButtons) || varEnableButtons = Self.Text,
DisplayMode.Edit,
DisplayMode.Disabled
)
Button Fill property (change button colors):
(1) Fill property of question buttons
If(
IsBlank(varEnableButtons),
Color.Orange,
//Similar remark as before, change to question label text if needed
varEnableButtons = Self.Text,
Color.Green,
Color.Red
)
(2) Optional HoverFill code change (of the question buttons) to improve the app UI:
ColorFade(Self.Fill, -20%)
Reset Timer Control:
You will need to use the Reset(TimerControlName) function when selecting the 'Next Question' button. Additionally, you will have to restart the timer control via variables. How to start, stop & reset a Timer Control via a button is well explained in this blog post.
If this solves your question, would you be so kind as to accept it as a solution.
Thanks!
it shows error as
2nd argument to the randbetween function must be greater than or equal to first argument.
on Timer End : i added below code but it is continuing for next question also but not restarting again when click on next question
Set(Audio, Audio3);Notify("Time Up,better Luck Next Time",NotificationType.Information);Navigate(Screen2)
Hi @venky232,
First of all, my apologies for the delay between my answers!
The code you showed is correct. However, keep in mind that you have to change LISTNAME to your actual list name and the upper boundary of RandBetween(1, 100) to your list length - you stated 20 questions so this would be 20. However, we will change this function slightly in our code below and changing it to 20 is no longer needed.
Now looking back on my initial code, we have 1 issue: we might get duplicate questions, which is not something we want. To resolve this issue, we will need to (1) fetch all SP rows to a collection during the onstart, (2) fetch a random question from the collection and (3) make sure we remove the question from the collection when selecting a new one.
(1) OnStart - locally store the questions & save a random one
//Change LISTNAME
ClearCollect(colQuestions, LISTNAME);
//Save random question to a var
Set(
varRandomQ,
Index(
colQuestions,
//Random number between 1 and the amount of rows in colQuestions
RandBetween(1, CountRows(colQuestions))
)
)
(2) My previous code for showing the question & validating is still the same (see previous comment)
(3) Selecting a new question & removing duplicate:
//Remove the question from our collection in order to avoid duplicates
Remove(colQuestions, varRandomQ);
//Save a new random question to a var
Set(
varRandomQ,
Index(
colQuestions,
//Random number between 1 and the amount of rows in colQuestions
RandBetween(1, CountRows(colQuestions))
)
)
(4) Disabling buttons:
For this requirement you would need to create a variable that starts of as 'true' and changes to 'false' once one of the buttons is pressed. The variable is reset to 'true' once a new question is selected.
OnStart of the app:
Set(varEnableButtons, true)
Add the following to the OnSelect of the buttons:
Set(varEnableButtons, false)
OnSelect of the 'Next Question' button:
Set(varEnableButtons, true)
The DisplayMode of all question buttons would be:
If(
varEnableButtons,
DisplayMode.Edit,
DisplayMode.Disabled
)
(5) Save the score:
To save the score of a person, create a variable in the OnStart and every time the correct button is pressed (see my previous code with the Notify) you add 1 to that variable:
OnStart
Set(varScore, 0)
Correct Answer
Set(varScore, varScore + 1)
(6) Save the answer time
This requirement will need a Timer control that starts once the first question is displayed and saves (to a collection) & resets when a new question is selected. I will link a video that will go into more detail.
(7) Stop after 10 questions
This solution will be very similar to the varScore. Start with a variable set to 0 and add 1 every time the 'Next Question' button is pressed (let's call it varAnswers).
The DiplayMode of the Next Question button would be:
If(
varAnswers <> 10,
DisplayMode.Edit,
DisplayMode.Disabled
)
You could also show a label depicting the end of the quiz when varAnswer equals 10.
If this solves your question, would you be so kind as to accept it as a solution.
Thanks!
its working but need some improvement.
the following code i added in both Onstart properties of the screen and also Next question button is it right?
Set(
varRandomQ,
//Change listname
Index(
LISTNAME,
//Random number between 1 and 100 -> change 100 to your last row number
RandBetween(1,100)
)
)
i want only 1 time user can select option & other buttons should disable..
is there any change to capture score and time for answers?
user can take 10 questions as quiz from the SharePoint list with contain 20 questions in random order.
Hi @venky232,
To fetch a random question, we could use the Index() & RandBetween() functions to fetch a random row from your SP list. On the OnStart of the app, you would set a variable to a random question row. We save it to a variable, so we can change the value later - e.g. when the user wants to see another question.
(1) OnStart of the app (and when you want to show another question e.g. OnSelect of a Next button):
Set(
varRandomQ,
//Change listname
Index(
LISTNAME,
//Random number between 1 and 100 -> change 100 to your last row number
RandBetween(1,100)
)
)
(2) Your question label would show the question of that random row:
//Change questioncolumn
varRandomQ.QuestionColumn
(3) Validate answer
Now I am not exactly sure what column types the options and answer columns are, but let's say Text fields for the sake of the example. In the OnSelect of those buttons you could write:
//If you show the option text on the button itself, use Self.Text
//Otherwise use the control you show the text in (e.g. labelName.Text)
If(
Self.Text = varRandomQ.AnswerColumn,
Notify("Correct Answer!", NotificationType.Success),
Notify("Incorrect Answer, try again.", NotificationType.Error)
)
If this solves your question, would you be so kind as to accept it as a solution.
Thanks!
WarrenBelz
637
Most Valuable Professional
stampcoin
570
Super User 2025 Season 2
Power Apps 1919
473