Data Grids & Global Variables

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
karina_r
Posts: 3
Joined: Thu Feb 04, 2016 4:18 pm

Data Grids & Global Variables

Post by karina_r » Thu Feb 04, 2016 4:33 pm

Hi all, I'm doing my project for advanced higher, which requires me to use cards which are navigated through buttons. When you press the button, it asks you to enter a, b, c, or d that will be assigned to a global variable, or instance "question1". There are 10 cards, each containing a question that will be answered when pressing the 'continue' button. Finally, when the questions are answered it should go to a card "overview" that would display your answers in a data grid. However, my problem is that it doesn't display anything in the data grid. I have tried numerous codes, but nothing works. What I initially need it do be able to do is gather answers in forms of global variables and put them into a data grid. All, and any help would be greatly appreciated. :)

-Karina.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Data Grids & Global Variables

Post by Klaus » Thu Feb 04, 2016 5:14 pm

Hi Karina,

1. welcome to the forum! :D
2. Please check this thread, maybe this already helps:
http://forums.livecode.com/viewtopic.php?f=7&t=26478

If not, we need to look at your script(s)!


Best

Klaus

karina_r
Posts: 3
Joined: Thu Feb 04, 2016 4:18 pm

Re: Data Grids & Global Variables

Post by karina_r » Mon Feb 08, 2016 10:01 am

Klaus wrote:Hi Karina,

1. welcome to the forum! :D
2. Please check this thread, maybe this already helps:
http://forums.livecode.com/viewtopic.php?f=7&t=26478

If not, we need to look at your script(s)!


Best

Klaus
Thanks Klaus! I got the global variables in each card like this:

global question1

on mouseUp
repeat until (question1 ="a") or (question1 ="A") or (question1 ="b") or (question1 ="B") or (question1 ="c") or (question1 ="C") or (question1 ="d") or (question1 ="D")
ask "Please enter your choice"
put it into question1
//If the result is cancel, exiting the procedure
if the result is cancel then exit to top
if (question1 <>"a") and (question1 <>"A") and (question1 <>"b") and (question1 <>"B") and (question1 <>"c") and (question1 <>"C") and (question1 <>"d") and (question1 <>"D") then
//Error message
answer "Please enter a, A, b, B, c, C, d, D. Thank you."
end if
end repeat
go to card "L1-2"
end mouseUp

I'm not sure if that is correct ^ As well as I initialized the variable type in a different card and now I'm not too sure how to put the content of the cards with the same code, but different variables into a data grid on a different card from these. :( Thank you for taking your time to answer my question! :)

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Data Grids & Global Variables

Post by Klaus » Mon Feb 08, 2016 11:10 am

Hi Karina,

here is a slightly shorter and better readable version of your script.
Advice: If the user does not enter the correct answer, do not trap him in an endless repeat loop, just have him click the button again!

Code: Select all

global question1 
on mouseUp
   put "a,A,b,B,c,C,d,D" into tAnswers
   ask "Please enter your choice"
   put it into question1 
   ## If the result is cancel, exiting the procedure 
   if the result = cancel then 
      exit mouseup
   end if
   if question1 is not in tAnswers then
      ## Error message 
      answer "Please enter a, A, b, B, c, C, d, D. Thank you." 
      exit mouseup
   end if 
   go to card "L1-2"
end mouseUp
But sorry, still dont understand what and how you want to fill your datagrid with?
Could you give a little example in pseudocode?


Best

Klaus

karina_r
Posts: 3
Joined: Thu Feb 04, 2016 4:18 pm

Re: Data Grids & Global Variables

Post by karina_r » Mon Feb 08, 2016 9:58 pm

Hey Klaus,
I managed to sort my data gird problem, thank you for the help with the variables! All your help is kindly appreciated! :D

Post Reply