Page 1 of 1

Field Help

Posted: Mon Dec 03, 2007 4:32 pm
by quinntk
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"?

Posted: Mon Dec 03, 2007 5:18 pm
by Mark
quinntk,

What is the error message?

Best,

Mark

Posted: Mon Dec 03, 2007 5:21 pm
by quinntk
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: &

Posted: Mon Dec 03, 2007 5:53 pm
by Mark
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

Posted: Mon Dec 03, 2007 6:58 pm
by Klaus
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

Posted: Mon Dec 03, 2007 6:59 pm
by malte
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

Posted: Mon Dec 03, 2007 7:00 pm
by malte
Klaus was quicker again. :( But I think he meant Parans instead of quotes. <g>

ATB,

Malte

Posted: Mon Dec 03, 2007 7:32 pm
by Klaus
Ah, damn, sure I mean these round halfmoon-like thingies -> ( and )
Whatever they are called :-)