Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Creating stuff :)

 [1/12] from: stefan:falk:slg:se at: 24-Apr-2001 22:01


Hi list, I'm having a huge problem, I can't for my life figure out how to do this. I have a form posting an X number of questions and answers, and I need to know how many and create a loop. Eg. if there are two questions and answers, I'll do this: question1: data/question1 answer1: data/answer1 question2: data/question2 answer2: data/answer2 append block-to-save question1 append block-to-save answer1 append block-to-save question2 append block-to-save answer2 Now, the number of Q and A's is in a variable so I know the number of Q and A's. I would like to create a loop that would look something like this (and this is fantasy): for count 1 number-of-questions 1 [ question[count]: data/question[count] answer[count]: data/answer[count] append block-to-save question[count] append block-to-save answer[count] ] Now, without using my wild imagination, how is this done? /Best Regards Stefan "Syke" Falk - www.amigaextreme.com

 [2/12] from: al:bri:xtra at: 25-Apr-2001 10:11


Stefan wrote:
> question[count]: data/question[count]
Try: poke question count data/question/:count I hope that helps! Andrew Martin ICQ: 26227169 http://members.nbci.com/AndrewMartin/

 [3/12] from: stefan:falk:slg:se at: 25-Apr-2001 8:11


Hi, I'm not quite sure what you mean with this, The line it should replace (if count = 1) is: question1: data/question1 /Regards Stefan "Syke" Falk - www.amigaextreme.com

 [4/12] from: stefan:falk:slg:se at: 26-Apr-2001 12:51


Hi, the closest I've come to solving this is to print out everything in to a file and "do" the file, but there has to be a better solution? /Regards Stefan Falk - www.amigaextreme.com

 [5/12] from: joel:neely:fedex at: 26-Apr-2001 6:26


I guess I'm unclear what you're trying to do. Did you mean the square brackets as metalanguage, or were you trying to manipulate the contents of an array of counters? -jn- [stefan--falk--slg--se] wrote:

 [6/12] from: stefan:falk:slg:se at: 26-Apr-2001 13:32


I have some POST-data from a CGI script, with a different number of questions and answers every time, and I want to do this with the data (if for example there are 2 questions and answers): -------------------------------- question1: data/question1 answer1: data/answer1 question2: data/question2 answer2: data/answer2 append file-to-save question1 append file-to-save answer1 append file-to-save question2 append file-to-save answer2 ------------------------------- However, since there are a different number of questions depending on what the user chose, I would like to create a loop, I know the number of questions through a value in the data like this: number-of-questions: 2 and then I'd like to create a loop, but replace the Q and A numbers with a counter, that, in my wild fantasy would look like this: for count 1 number-of-questions 1 [ question[count]: data/question[count] answer[count]: data/answer[count] append file-to-save question[count] append file-to-save answer[count] ] But of course the [count] way doesn't work, is there any way to simply replace a char in the code for variable? /Regards Stefan Falk - www.amigaextreme.com

 [7/12] from: arolls:bigpond:au at: 27-Apr-2001 2:54


Show us an example of the POST-data, and the corresponding output that you would like. Anton.

 [8/12] from: ingo:2b1 at: 26-Apr-2001 22:19


Hi Stefan, I thought I already saw the answer, but seems I just dreamt, so here it is (translating your fantasy example to rebol, the way I understand it ...) Once upon a time [stefan--falk--slg--se] spoketh thus:
> for count 1 number-of-questions 1 [ > question[count]: data/question[count] > answer[count]: data/answer[count] > append file-to-save question[count] > append file-to-save answer[count] > ]
for count 1 number-of-questions 1 [ set question/:count data/question/:count ; you have to use set, question/:count: won't work set answer/:count data/answer/:count append file-to-save question/:count append file-to-save answer/:count ] kind regards, Ingo

 [9/12] from: stefan:falk:slg:se at: 27-Apr-2001 16:58


Hi, that's good except for: ** Script Error: question has no value. ** Where: set question/:count data/question/:count I would like to set (for the first iteration) question1: data/question1 and I guess set question/:count data/question/:count isn't quite the same, I don't want it in a block, but in a word or variable or whatever it's called in rebol :) /Regards Stefan Falk - www.amigaextreme.com

 [10/12] from: mike:yaunish:home at: 28-Apr-2001 17:15


At 04:58 PM 27/04/01 +0200, you wrote: Are you maybe looking for something like this;
>> question1: 0 ; initialize the word "question1"
== 0
>> set 'question1 99
== 99
>> print question1
99 I think this may answer some questions - but probably not solve your problem. In your example you are setting two variables when I don't think that is neccesary. From your example it looks like your real target action is to get the questions and answers into the "file-to-save". How about: for count 1 number-of-questions 1 [ ;question[count]: data/question[count] ;answer[count]: data/answer[count] append file-to-save data/question/:count append file-to-save data/answer/:count ] If you are using the psuedo variables "question[count]" and "answer[count]" somewhere after the loop then you can just use normal variable assignments like: last-question: data/question/:count last-answer: data/question/:count because that is all that those variable will be holding after the loop anyway.
>Hi, >that's good except for:
<<quoted lines omitted: 51>>
>[rebol-request--rebol--com] with "unsubscribe" in the >subject, without the quotes.
Mike Yaunish [mike--yaunish--home--com]

 [11/12] from: stefan:falk:slg:se at: 29-Apr-2001 10:35


That's not quite it, so here comes a quite lengthy description of what I'm trying to do: First, I have a form asking how many questions and answers there is (the whole script is for adding an interview to a webpage, without having to deal with HTML), this is then sent to a rebol script that prints the following form (noq = number of questions): ;--------------- Only a small part of the form for count 1 noq 1 [ print rejoin [{ <tr> <td colspan="2"> <font face="Verdana" size="2"><b>Question } count {</b><br></font><textarea cols="60" rows="10" name="question} count {"></textarea><p> </td> </tr> <tr> <td colspan="2"> <font face="Verdana" size="2"><b>Answer } count {</b><br></font><textarea cols="60" rows="10" name="answer} count {"></textarea><p> </td> </tr> }] ] ;-------------------------------- after that, this form is sent to another rebol script that will add everything to a file: ;------------------------------------------------------------- create-interview: func [][ noq: data/noq date: now/date name: data/name nop: data/nop short: data/short short: replace/all short newline "<br>" intro: data/intro intro: replace/all intro newline "<br>" append feature-file 'type append feature-file type ; type: data/type was done earlier in the script append feature-file 'name append feature-file name append feature-file 'nop append feature-file nop append feature-file 'short append feature-file short append feature-file 'intro append feature-file intro url: data/url homepage: data/homepage append feature-file 'url append feature-file url append feature-file 'homepage append feature-file homepage append feature-file 'date append feature-file date noq: to-integer noq for count 1 noq 1 [ questionX: data/questionX answerX: data/answerX append feature-file 'QuestionX append feature-file questionX append feature-file 'AnswerX append feature-file answerX ] ;------------------------- And then it goes on to save the file. The problem is (I think) the way the form sends the data, as it sends it with the name(s) question1 question2 question3 etc.. answer1 answer2 answer3 etc.. This mean that even if I know the number of questions, I still have to change the number in a line of code to get the data. (Maybe I could use some sort of for loop to count through the data?) After this I need a script to print the questions, which would be easy to make if I can get this thing running. Hope this makes everything clearer! /Regards Stefan Falk

 [12/12] from: stefan:falk:slg:se at: 29-Apr-2001 12:21


Also, an addition that I forgot, the saved file should look something like this: type "Interview" name "Mama" nop "1" short "erpokgepokg" intro pokwporkpwork url "pokpok" homepage "pokpok" date 28-Apr-2001 question1 Blah answer1 "Bloh" question2 "Blah" answer2 "Bloh" etc.. and it's loaded using: interview: load %filename.r And so it can be displayed using print interview/name print interview/question1 etc... /Regards Stefan Falk

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted