Issue in skill

  • Thread starter sridhartv25@gmail.com
  • Start date
S

sridhartv25@gmail.com

Guest
Hello all especially Andrew,

I want to know a way for creating fields which are similar,except
the change in the name and the prompt.

For ex:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
procedure(example()

r1 = hiCreateRadioField(
?name 'r1
?prompt "1)abc: "
?value "yes"
?choices list("yes" "no")
)
r2 = hiCreateRadioField(
?name 'r2
?prompt "2)def: "
?value "yes"
?choices list("yes" "no")
)
r3 = hiCreateRadioField(
?name 'r3
?prompt "3)ghi: "
?value "yes"
?choices list("yes" "no")
)
r4 = hiCreateRadioField(
?name 'r4
?prompt "4)jkl: "
?value "yes"
?choices list("yes" "no")
)
r5 = hiCreateRadioField(
?name 'r5
?prompt "5)mno: "
?value "yes"
?choices list("yes" "no")
)
r6 = hiCreateRadioField(
?name 'r6
?prompt "6)pqr: "
?value "yes"
?choices list("yes" "no")
)

exampleform=hiCreateAppForm(?name gensym('exampleform)
?formTitle "Example form"
?fields list(r1 r2 r3 r4 r5 r6)
)
hiDisplayForm(exampleform)
)
example()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

In the above example instead of creating 6 different fields , How
can I create a single radio field
and pass the names (r1 to r6) and also the corresponding prompts to
that field , given that the names and the fields are stored in the
variables.

Eagerly waiting for the replies,

Regards,
Sridhar.
 
Hi Sridhar,

You can use foreach looping to create the fieldList for the form. For
example:

procedure( Example()
let((buttonList itemList itemText item)

buttonList = list("abc" "def" "ghi" "jkl" "mno" "pqr")

for( i 0 length(buttonList)-l
itemText = sprintf(nil "%L) %L" i nth(i buttonList))

item = hiCreateRadioField(
?name stringToSymbol
(sprintf(nil "%L" i))
?prompt itemText
?value "yes"
?choices list("yes" "no")
)

itemList = cons(item itemList)
)

hiCreateAppForm( ?name 'exampleForm
?formTitle Example Form"
?fields reverse(itemList)
)

hiInstantiateForm(exampleForm)
hiDisplayForm(exampleForm)
);let
);proc


Regards,
How
 
Hi How,
Thanks for your reply,
I am getting syntax errors in your script , I tried to correct this
but I couldn't doso can you please help me on this.
Regards,
Sridhar.
 
Hi How,
I got it, the error was in hiCreateAppForm( ?formTitle
ExampleForm" you missed double qoutes on one side for ExampleForm,
since it was not closed the icfb was expecting some more i/p from the
user.And the other was in the for loop I changed the variable "l" to
1.
After this changes I got an error as *WARNING* hiCreateForm: **
stringToSymbol ** illegal duplicate field symbol in list of fields
and only one field was generated in the form, so to generate the
symbol I used gensym('stringToSymbol) which solved the problem.
One more thing is you used the sprintf statement in hiCreateRadioField
( (sprintf(nil "%L" i)) but I am getting an error as it is not a
function so I made that line as a comment, how can I clean that.
Thanks How for your help.
Regards,
Sridhar.
 
Hi How.
I have one more issue here , I am saving the form data to a file ,
previously since I used different names for the fields I could access
the value simply exampleform->r1->value = "no" for the first field
value and similarly exampleform->r2->value = "yes" for the second
field value and so on, but how can I access it now.
When I check icfb the no after the stringToSymbol is changing foe
every execution , now here itis 82 exampleForm->stringToSymbol82-
value = "no".
Regards,
Sridhar.
 
Hi Sridhar,

Q1:
I think u added additional bracket to it, try to take out the bracket
and run again. "sprintf" is a function that format the output and
assigns the resultant string to the variable given in the first
arguments.


Q2:
 
Hi Sridhar,

I believe there is number of typo since i didn't do any testing for
the code. Please try this.

procedure( Example()
let((buttonList itemList itemText item)


buttonList = list("abc" "def" "ghi" "jkl" "mno" "pqr")


for( i 1 length(buttonList)
itemText = sprintf(nil "%L) %L" i nth(i-1 buttonList))


item = hiCreateRadioField(
?name stringToSymbol
(sprintf(nil "item_%d" i))
?prompt itemText
?value "yes"
?choices list("yes" "no")
)


itemList = cons(item itemList)
)


hiCreateAppForm( ?name 'exampleForm
?formTitle "Example Form"
?fields reverse(itemList)
)


hiInstantiateForm(exampleForm)
hiDisplayForm(exampleForm)
);let
);proc



This script was tested and works well.

Q1:
I think u added additional bracket to it, try to take out the bracket
and run again. "sprintf" is a function that format the output and
assigns the resultant string to the variable given in the first
arguments.


Q2:
I did minor change in setting the name of the field from number to
string, so now you can call the value.
Example:
exampleForm->item_1->value

Regards,
How
 
Thanks How,
The main problem wasin your code the statement (sprintf(nil "item_%d"
i)) is printed in the next line ( may be this could be copy problem)
that's why I got an error as unbound variable stringToSymbol .
To make my script consistent with the field names I had done this....

;;;;;;;;;;;;;;;
procedure( Example1()
let((buttonList itemList itemText item)

buttonList = list("abc" "def" "ghi" "jkl" "mno" "pqr")

for( i 1 length(buttonList)
itemText = sprintf(nil "%L) %L" i nth(i-1 buttonList))


item = hiCreateRadioField(
?name makeSymbol(strcat
("r"sprintf(nil "%L" i)))
?prompt itemText
?value "yes"
?choices list("yes" "no")
)

itemList = cons(item itemList)
)

hiCreateAppForm( ?name 'exampleForm
?formTitle "Example Form"
?fields reverse(itemList)
)

hiInstantiateForm(exampleForm)
hiDisplayForm(exampleForm)
);let
);proc
-------------------------

Once again thanks How.

Regards,
Sridhar.
 
Hi Sridhar,

Can you send me the error message. It seem ok on my side.

Regards,
How
 

Welcome to EDABoard.com

Sponsor

Back
Top