Field Help

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
quinntk
Posts: 4
Joined: Fri Nov 30, 2007 8:02 am

Field Help

Post by quinntk » Mon Dec 03, 2007 4:32 pm

Hi guys...i got my button issue sorted out but now I need a bit of help with some fields.

I have a bunch of fields on a card and each of them are named Q1A, Q1B, through Q1E and continues Q2A, Q2B...Q2E all the way to field Q5E

The Number in the field name is related to the question number and the letter is related to the answer choice.
So for example if on question 3, they user picked choice D, I would need a 1 to be put into field "Q3D"

I haven't been able to figure out how to change the field name based on the question and answerchoice
I've tried:

Code: Select all

add 1 to field "Q" & QuestionNumber & LetterChoice of card gender
but it returns an error. I have this statement in a switch

this is my current script

Code: Select all

on RecordResults
  switch
    case (Gender = "Male")
      add 1 to field "Q" & QuestionNumber & LetterChoice of card Gender
      break
  end switch
end RecordResults
any ideas on how i can get a 1 put into field "Q1A" on card "Male"?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon Dec 03, 2007 5:18 pm

quinntk,

What is the error message?

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

quinntk
Posts: 4
Joined: Fri Nov 30, 2007 8:02 am

Post by quinntk » Mon Dec 03, 2007 5:21 pm

this is the error i'm getting


Type switch: not a command
Object: Submit.png
Line: add 1 to field "Q" & QuestionNumber & LetterChoice of card "Male"
Hint: &

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon Dec 03, 2007 5:53 pm

quinntk

Does this work?

Since the variable Gender always contains "Male" for this switch, I replaced card name Gender with "Male".

Code: Select all

on RecordResults
  switch
    case (Gender = "Male")
      put "Q" & QuestionNumber & LetterChoice into myFld
      if there is a fld myFld then
        add 1 to field myFld of card "Male"
      else
        -- you can disable next line later
        answer error "Error: can't find fld" && myFld
      end if
      break
  end switch
end RecordResults
Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

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

Post by Klaus » Mon Dec 03, 2007 6:58 pm

Hi quinntk

always use QUOTES when you are concatenating strings especially when using with names of controls!

This will probably work:
...
add 1 to field ("Q" & QuestionNumber & LetterChoice) of card gender
...

This way, the engine will first evaluate the expresion inside the QUOTES and will then find the correct field:
("Q" & QuestionNumber & LetterChoice) -> "Q1A" of cd XYZ


Best from germany

Klaus

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Post by malte » Mon Dec 03, 2007 6:59 pm

Hi,

a few things to note here. Are your variables declared in the scriptyou are using? Second as mark already showed you can construct the resulting field name in an extra variable or use parans around the construction you are using. e.g. field ("q"&QuestionNumber & LetterChoice). However, QuestionNumber and LetterChoice must be declared in the script you are working with them. Assuming those are global variables your script could read like this:

global QuestionNumber, LetterChoice

on mouseUp
--rest of script here
end mouseUp

Hope that helps,

Malte

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Post by malte » Mon Dec 03, 2007 7:00 pm

Klaus was quicker again. :( But I think he meant Parans instead of quotes. <g>

ATB,

Malte

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

Post by Klaus » Mon Dec 03, 2007 7:32 pm

Ah, damn, sure I mean these round halfmoon-like thingies -> ( and )
Whatever they are called :-)

Post Reply