This content has been marked as final. Show 10 replies
You'll want to use the syntax:
<cfset form[finalarray] = "#finalArray#">
to correctly set the form variable
FORM is a basically ColdFusion structure, form field values as structure keys.
You can only pass simple values in form fields. Thus it makes no sense being able to have arrays as form field variables. Thus, I don't see why your code should work...
If you create a myStruct structure and replace "form." with "mystruct.", does your code work then?
Btw, you gain nothing by using "#finalArray#", compared to finalArray. Don't use # signs or quotes in your code example, they are bad coding practice.
Edited: And yes ,see the answer above this reply. There the form key value is actually evaluated, because the key name finalArray[x][y] is wrapped within the 's. It's the same as form['#finalArray[x][y]#'] if that makes it clearer to you. But again,ditch the # and "s.
> Basically I have an array, the second element contains
> the name of the variable, and the 3rd element contains the data.
What does the FIRST element contain?
And how come you're not using an array of structures, as there seems to be
more a key/value relationship here, rather than an indexed one, which
suggests some numeric signficance in the order of the elements (which there
isn't, between "name" and "value" which seems to be your siutation).
Thank you all so much for your replies. I know this peice of code looks insane and like it serves no prupose, but trust me it does. The first element of the array conaints a number, that frequency of how many times the letter in element 2 occures in a block of text in the form. For those interested, the project I am working on is a tool that will help the cracking of monoalphebetic substitution ciphers using frequency analysis. That array is what holds the frequencies of every letter in the block of text given. It gives the freq in the first element, the actual letter in the second element, and the letter it probably originally was in the 3rd element. I am trying to fill in some form fields with the data from the array. Again, I know this all sounds insane, but there is method to the madmess. If you care to look, this project in progress can be found at http://www.digitalswordsmen.com/Codebreaker.cfm. Its free to fool around with. Lots of diagnostic info is displayed, and the source is downloadable if you want to check it out. Thanks again for all your help, Ill let you know how it goes.
> It gives the freq in
> the first element, the actual letter in the second element, and the letter it
> probably originally was in the 3rd element.
Right, so you're describing a struct, not an array. There is no
*sequential* relationship between "freq", "cipher letter", and "probable
letter", is there? So an indexed array is not the most sensible/obvious
data construct to store the data in.
What's more, you've got uniform key names, right there:
Although as you have a collection of them, rejog that slightly:
(given the cipher chars would be unique, I should think, in your system).
Did you suss out your problem with the AAAAAA thing, from last night? I
suspect I saw what the problem was, but wondered if a bit of
experimentation would lead you to the same conclusion I did... [plus it was
late when I saw the thread, and I'd want to run some test code to check my
theory, and I... well... couldn't be bothered, to be honest. Oops].
Ah. Yeah. See I am a really terrible programmer, and I don't even know the difference between a structure and array. I don't even know how I have made as much as I have. The AAAAA problem is partially fixed, sometimes it still freaks out and puts a bunch of one letter for no good reason that I can think of. If you know why, please let me hear it. I wish i was better at coding.
Oh yeah also that fix provided worked for my dynamic vars. Now I just need to save them back to the form for the replacement alphabet. So thanks for that.
Well After some work, I got it going. It puts the correct values in the correct form boxes. However my replace statements are messed up. I think its because one replace statement is change another. I need some way to do them all at the same time. Basically I just want to change every letter in "Text" to whatever values the user has specified in the form. So whatever they put for Form.A should replace any A that occurs in the text. Attached is the code for my replace statements.
This image here http://www.digitalswordsmen.com/img/cipher_tool_output.gif Really shows what is going on better than i can explain it. Everything is all set up right, but the results of the replace are completely unpredictable.
> The AAAAA problem is partially fixed, sometimes it still freaks
> out and puts a bunch of one letter for no good reason that I can think of.
Let's take a smaller sample, in which the alphabet is only three
Your cipher mapping is:
Now, decipher "CAB":
Change the Cs to As:
Change the As to Bs:
Change the Bs to Cs:
That approach is never going to work, is it? You're always going to
accidentally decipher some letters more than once.
> you know why, please let me hear it. I wish i was better at coding.
This ia more a debugging issue. Had you ever actually manually followed
your logic through (with pen and paper, if need be, to track results),
you'd've seen this. When something is wrong, don't sit there going "it
SEEMS right, I can't see it", have the point of view: "it's clearly
All this comes with practice.
> That approach is never going to work, is it? You're always going to
> accidentally decipher some letters more than once.
If it's any consolation, CF falls into the same trap:
<cfoutput>#replaceList("cab", "c,a,b", "a,b,c")#</cfoutput>
Ha, I found a solution. I use a case sensitive replacement. Before replacement I set the variable to uppercase, then I replace with lowercase letters. That way nothing gets replaced more than once, because it will always change case! It seems to work perfectly. The whole thing works now, if you get a change you should check it out. Thanks for everyones help. If you care to try for yourself, here is the code. It's not to shabby if I do say so myself.