Looping over a structure of arrays
Hi Guys, I am trying to loop over a structure of simple
arrays. The structure's second column contains a 1 dimentional
array.
I can't seem to get the proper syntax for my loop.
I want to be able to dynamically loop over my query and
decrypt it as I pass it into my structure. I have figured the code
out to loop over the query and pass it to the structure. My problem
now is whn I go to decrypt it I get this Error.
There has been an error while trying to encrypt or decrypt
your input string: Input length (with padding) not multiple of 16
bytes.
How can I fix this?
Here is my code could it be because my varchar columns were
not long enough. Here is my code.
Similar Messages
-
How do I loop over this structure to populate it with a Query
Recordset?
<cfset myStruct =
objImage.getSize("images/products/largeImages/#Recordset1.elink#")>
I really appreciate your help.I would like to populate the structure with the image file
names that are coming from the query. The structure is built from a
java object. Here is the function to create it.
<cfcomponent>
<cffunction name="getSize" returntype="struct"
access="public" output="No">
<cfargument name="Image" required="Yes" type="string">
<cfset myImage = createObject("java",
"javax.swing.ImageIcon")>
<cfset myImage.init(expandpath(arguments.Image))>
<cfset myStruct = StructNew()>
<cfset myStruct.width = myImage.getIconWidth()>
<cfset myStruct.height = myImage.getIconHeight()>
<cfreturn myStruct>
</cffunction>
</cfcomponent>
<cfobject component="imageSize" name="objImage">
<cfset myStruct =
objImage.getSize("/images/someimage.jpg")>
<cfoutput>
width: #myStruct.width#
height: #myStruct.height#
</cfoutput>
Right now the structure only gives me the first row of the
query. I have tried using the cfquery loop to populate the
structure with now results. I suspect I am using the wrong
syntac. -
Hello,
Can someone please demonstrate how I would use a cfLoop to
loop over and output the contents of this fictious nested
structure?
Thank You!mletson wrote:
> I figured it out. If anyone has a better solution,
please let me know.
>
> <cfloop from="1" to="#structCount(student)#"
index="x">
>
> <cfset variables.studentID = "student00" & x>
>
> <tr>
>
<td><cfoutput>#student[studentID]["firstName"]#</cfoutput></td>
>
<td><cfoutput>#student[studentID]["lastName"]#</cfoutput></td>
>
<td><cfoutput>#student[studentID]["phone"]#</cfoutput></td>
> </tr>
>
> </cfloop>
>
A slightly simpler version using the structure form of the
<cfloop...>
tag. It also demonstrates both array notation, that you used,
as well
as dot notation. Finally it puts a single <cfoutput...>
block around
the entire loop. This can provide a small but accumulative
performance
improvement.
<cfoutput>
<cfloop collection="#student#" item="aStudent">
<tr>
<td>#aStudent["firstName"]# OR
#aStudent.firstName#</td>
<td>#aStudent["lastName"]# OR
#aStudent.lastName#</td>
<td>#aStudent["phone"]# OR #aStudent.phone#</td>
</tr>
</cfloop>
</cfoutput> -
Hey Guys,
I have a component that returns a structure. The structure is
called ContactQuery. ContactQuery has to elements, one called
Results, and one called Success. Results contains the data I want
to loop over. If you try looping over the ContactQuery by using
CFLoop and specify the ContactQuery as the collection, of course it
only loops twice (once for Results, once for Success). How can I
loop over the Results structure withing ContactQuery? You can see
the dump of the structure at:
http://www.digitalswordsmen.com/cfschedule/admin/Create_Tokens_Table.cfm
Attached is the code I have. I am just unsure of the syntax
for looping over the Results section of the structure.
Thank you.Nope. I am dumb and didn't really think about it. The fact
that it is a query nested in a structure threw me off. The code
that works was
<cfloop query="ContactQuery.Results">
<tr>
<td></td><td>#firstname#</td><td>#lastname#</td><td>#email#</td><td>#randrange(10000,9999 9)#</td>
</tr>
</cfloop>
Thanks for the help, sorry about that dumb question. -
Looping over an array avoiding scriptlets
Hello,
I want to loop over an array avoiding java scriptlets. Here is the code I would like to "clean".
<%
int rowCol=0;
for(int i=0; i<countryArray.length; i++){
rowCol++;
Country country = (Country)countryArray;
out.println("<tr " + ((rowCol%2==0)?("class=\"evenRow\""):("class=\"oddRow\"")) + ">");
out.println("<td class=\"countryName\">" country.getName() "</td>");
out.println("<td class=\"countryCapital\">" country.getCapital() "</td>");
out.println("<td class=\"number\">" + country.getFormattedLandArea() + "</td>");
out.println("<td class=\"number\">" country.getFormattedPopulation() "</td>");
out.println("<td class=\"number\">" country.getFormattedGdp() "</td>");
out.println("<td class=\"number\">" country.getFormattedGdp_per_head() "</td>");
out.println("<td><a class=\"more\" href=\"pais.jsp?countryID=" + country.getId() + "\">m?s...</a></td>");
out.println("</tr>");
%>
Can anyone give me some guidelines please?
Thanks in advance,
Julien.you mean this:
<%
int rowCol=0;
for(int i=0; i<countryArray.length; i++){
rowCol++;
Country country = (Country)countryArray;
%>
<tr class="<%= rowCol%2==0? "evenRow" : "oddRow" %>">
<td class="countryName"><%= country.getName() %></td>
<td class="countryCapital"><%= country.getCapital() %></td>
<td class="number"><%= country.getFormattedLandArea() %></td>
<td class="number"><%= country.getFormattedPopulation() %></td>
<td class="number"><%= country.getFormattedGdp() %></td>
<td class="number"><%= country.getFormattedGdp_per_head() %></td>
<td><a class="more" href="pais.jsp?countryID=<%= country.getId() %>">m?s...</a></td>
</tr>
<%
%> -
I've got a form. The form asks the visitor their address
(first name, last name, street address, apartment number, city,
state, and zip code... each a separate text field). This form is
repeated 10 times on the page, allowing the visitor to enter
multiple addresses. I've given each form field a unique name by
just appending "_1" or "_2" after it. For example, my fields are
named...
FIRST FORM BLOCK
first_name_1
last_name_1
SECOND FORM BLOCK
first_name_2
last_name_2
Each form block (address) will be inserted into a table in my
database as a new row. Is there a quick and easy way to loop over
the insert 10 times, rather than have 10 separate INSERT statements
in my code? A CFLOOP would work just fine if not for dynamic form
field names, but I would have to take into account the "_X". I want
to say I've done this before; I'm just overthinking.<cfloop from="1" to="10" index="i">
<cfquery ...>
INSERT INTO ...
(aCol,bCol,cCol...)
<!--- The important part, accessing the form structure
with array
notation --->
#form['first_Name_' & i]#,
#form['last_Name_' & i]#
</cfquery>
</cfloop>
The array notation for a complex variables is a very powerful
concept.
Many advance techniques can be used with it. -
Sort values of structure with arrays
Hi
For a shopping cart I'm using a structure with arrays to store the items in the cart. I tried to use StructSort but did not work...
This is how I store the items in the cart:
<cfscript>
if (not(isdefined("session.cart"))) { // Check to make sure that the Shopping cart structure exists.
session.cart = structnew();
// The item structure we are going to use to store the items in the cart
// is going to have four parts...
// 1. The item id
// 2. The item name
// 3. The price per unit
// 4. The quantity
tempvalue = listtoarray('#attributes.id#,#attributes.name#,#attributes.price#,#attributes.quantity#') ;
// if the item is not yet in the cart, simply add it to the cart
if (not(structKeyExists(session.cart, attributes.name))) {
StructInsert(session.cart,attributes.name,tempvalue);
// if the item is already in the cart, update the item quantity
else {
tempvalue[4]=session.cart[attributes.name][4]+attributes.quantity;
StructUpdate(session.cart,attributes.name,tempvalue);
</cfscript>
Any help will be appreciated.
Thank you.
TJTo loop over an array one has two options:
<cfloop index="i" from="1" to="#arrayLen(a)#">
Or:
<cfloop index="someVar" array="#a#">
Personally I use the former because I think the implementation of array-looping with <cfloop> is cocked-up as it's not the index that gets put into "someVar", it's the array element itself. So by way of pedantic protest, I don't use that syntax.
But anyway...
The reason why your struct is unordered is because structs are - innately, and by definition - unordered. If you want an ordered data structure, you use an array.
However what you are wanting to do is to sort your array by a subkey value of the structs the array contains. If you want to do that, you will need to roll your own sorting solution.
Personally I'd stick with using an array and just use its intrinsic ordering (the order in which items are added to it). However if you wanted to sort on one of the inner struct keys, you could maintain a separate struct keyed on the value you wish to sort on, containing a reference to the array element in the original array. Then you could extract a structKeyArray() from that, and use arraySort() to order those index keys in whichever order you like.
Adam -
Value Mapping: how to loop over a nested context in a adv. user function
Hello,
i have the following source structure:
<rec> (1:1)
<field1>aaa</field1> (1:1)
<field2>bbb</field2> (1:1)
<b><struc> <u>(1:unbounded)</u>
<name>myName</name>
<value>myValue</value>
</struc></b>
</rec>
Destination structure:
<rec> (1:1)
<field1>aaa</field1> (1:1)
<field2>bbb</field2> (1:1)
<b><field3>bbb</field2> (1:1)</b>
</rec>
In order to fill the destination field3 i have to loop over the input-structure struc.
My problem is, that i don't know how to get access to the name/value pair with a
extended user-defined function. Since each occurrence in struc i not a simple string but consists of 2 fields, i guess it is not enough simply to loop over input String Array.
Please help.just like u have a loop stmt in java prgm. a simple code:
Here a and b are the strings that comes to the udf
for(int i=0;i<a.length;i++)
boolean found = false;
int j = 0;
for(j=0;j<b.length;j++)
if (a<i>.equals(b[j]))
found = true;
break;
if (found == true)
result.addValue(c[j]);
else
result.addValue("");
Message was edited by:
Prabhu S -
Problem with Message-Mapping: Loop over Elements possible?
Hi all,
I want do create a Message-Mapping for an IDoc-to-File Scenario. In the Source Structure there are some Elements which can appear more than once (1..unbounded). I need a mechanism which loops over these elements and search for specified values. From the Element which contains an element with this specified value the mapping should write a value in the target structure.
Here a simple example (source structure) for better understanding:
<root>
<invoice>
<number> 10 </number>
<sum> 200.00 </sum>
</invoice>
<invoice>
<number> 20 </number>
<sum> 150.00 </sum>
</invoice>
<invoice>
<number> 30 </number>
<sum> 120.00 </sum>
</invoice>
</root>
Now the duty of the Mapping should be to search in the elements <invoice> for the number 30. And then the sum of the invoice with the number 30 should be written in a field of the target structure.
I tried it out with a constant togehter with an equalsS-function and an ifWithoutElse-function, but it is working only then, if the invoice with the number 30 has the first position in the root context.
Can anybody help me? Thanks
With kind regards
ChristopherHi,
Write a UDF to sum the required values and map to target node.
See while writing the UDF select the type as queue.
number -- removecontext-UDF targetnode
sum----removecontext--/
number abd sum or the two inputs
in UDF
int nsum = 0;
for(int i;i < number.length;i++){
if number(i).equals("30") then
nsum = nsum + valueOf(sum(i));
result.addValue(nsum); // convert the nsum into string
Regsrds
Chilla -
Message-Mapping: nested Loops over Elements
Hi Experts,
I have problems with my Message-Mapping in the IR. I have a source and a target structure. In the following I will give you easy examples of these structures:
<u>source structure:</u>
<E1EDP01>
<E1EDP19>
<QUALF> ... </QUALF>
<IDTNR> ... </IDTNR>
</E1EDP19>
<E1EDP19>
<QUALF> ... </QUALF>
<IDTNR> ... </IDTNR>
</E1EDP19>
</E1EDP01>
<E1EDP01>
<E1EDP19>
<QUALF> ... </QUALF>
<IDTNR> ... </IDTNR>
</E1EDP19>
<E1EDP19>
<QUALF> ... </QUALF>
<IDTNR> ... </IDTNR>
</E1EDP19>
</E1EDP01>
<u>target structure:</u>
<LineItem>
<IDTNR></IDTNR>
</LineItem>
<LineItem>
<IDTNR></IDTNR>
</LineItem>
That means:
For every <E1EDP01> in the source structure I create one <LineItem> in the target structure. One E1EDP01-Element can contain more than one E1EDP19-Elements. I have to loop over these E1EDP19-Elements, because I have to locate the Element <QUALF> with a given (fixed) value. The Mapping should put the value from the Element <IDTNR> from the source structure - where the QUALF-Element has this given value - in the IDTNR-Element of the target structure.
I tried it with a UDF, but only the first <IDTNR> in the target structure got filled.
Thanks for your help
ChristopherThank you,
but how I can set the Elements IDTNR and QUALF to the context E1EDP01?
In the splitByValue-Function do I need "each value"?
best regards
Christopher -
How to stop a while loop of event structure from a main vi
Hello;
sorry for my english
I have to stop a subvi from my main vi, the subvi contains a while loop and an event structure so I need to stop this loop while directly from my main vi I have tried global variable but it did not work
any help please or example !!!
Solved!
Go to Solution.
Attachments:
stop a while loop and event structure from main vi.png 16 KBIYED wrote:
Hello;
sorry for my english
I have to stop a subvi from my main vi, the subvi contains a while loop and an event structure so I need to stop this loop while directly from my main vi I have tried global variable but it did not work
any help please or example !!!
If this is an example of how your code looks, I'd clean it up before the developer who has to work on it next hits you over the head with his LabVIEW Style Book.
Bill
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all. -
Looping over fields from internal table
In a FM I have to check records of two ITABs against each other. Most fields can be checked 1:1 but some must be checked according to some business logic.
I first want to check field-by-field and then I want to deal with exceptions.
Question: How can I loop over fields in an ITAB in such a manner that I can compare fields?Hi, you can loop thru the columns(fields) of an internal table like so.
field-symbols: <fs>.
loop at itab.
do.
* Here you can use the field name instead of SY-INDEX
assign component sy-index of structure itab to <fs>.
if sy-subrc <>.
exit.
endif.
* Now that you have access to the field via field symbol, you can compare
* this value.
Write:/ <fs>.
enddo.
endloop.
Regards,
Rich Heilman -
I have two queries. One is a main query that we pull from a form submission. The second is a small query resultset that lists different subgroups in my company and what main group they belong to. I pull several QoQ from the main query. In the main query results, there is a column that holds the subgroup information. I am trying to do a Q0Q where I group the data from the main query into the main groups for analysis. Here is an example...
Main Query
record 1 - subgroup 1
record 2 - subgroup 2
record 3 - subgroup 3
Second Query
Subgroup 1 - Main Group 1
Subgroup 2 - Main Group 2
Subgroup 3 - Main Group 1
So I am trying to loop over a QoQ on the main query where the result set would contain the information only from Main Group 1. So record 2 would be eliminated. I have tried using an IN clause with a cfloop, but I run into syntax trouble with the comma. I also tried looping over the QoQ as a whole and the resulting dump is only the last record.
If there is anything else you need, let me know.
Any thoughts?
Clay
P.S. Here is a code sampling...
<cfquery name="rsGroup" datasource="nps">
SELECT *
FROM "GROUP"
WHERE GROUP.PrimaryGroup = '#form.primarygroup#'
</cfquery>
rsGroup - <cfdump var="#rsGroup#">
<cfloop query="rsGroup" startrow="1" endrow="#rsGroup.RecordCount#">
<cfquery name="rsGroupQoQ" dbtype="query">
SELECT *
FROM rsNPS
WHERE rsNPS.grp = '#rsGroup.group#'
</cfquery>
</cfloop>
rsGroupQoQ - <cfdump var="#rsGroupQoQ#"><cfabort>ok...I figured it out. I thought I would post my solution in case anyone else runs into this. Also, if anyone out there has a better way, let me know.
<!---Dummy array to house 'blank' value for adding of column to main query--->
<cfset GroupArray = ArrayNew(1)>
<!---Variable that adds mainGroup column to main query with blank data from dummy array--->
<cfset addMainGroup = QueryAddColumn(rsNPS,'mainGroup',GroupArray)>
<!---Loop that sets value on added mainGroup column based off of main query grp column value--->
<cfloop query="rsNPS" startrow="1" endrow="#rsNPS.RecordCount#">
<cfif rsNPS.GRP EQ "xxxxx"><cfset rsNPS.mainGroup = "yyyyy"></cfif>
<cfif rsNPS.GRP EQ "xxxxxxxxxx"><cfset rsNPS.mainGroup = "yyyyyyyyyy"></cfif>
<cfif ...etc. ...
</cfloop> -
Hi, I have a structure of arrays as follows.
The Structure is session.cart
my arrays are session.cart.foodname[ ]
session.cart.comments[ ]
session.cart.name[ ]
session.cart.price[ ]
All of these arrays correspond to each other, so
session.cart.name[1] may be John, who ordered a cheeseburger
(session.cart.foodname[1]). So i need to sort these by the persons
name and have the other 3 arrays sort with them, so they still
correspond to each other. Can anyone help me with this? Ive looked
over the structsort function but cant figure out how to apply it to
a structure of arrays. Thanks for the help.I would avoid using multiple arrays, which have to refer to
each other - without really having a proper way to execute the
plan. Structures are better for this. I created an example, which
you might try out, and see if it fits your needs:
<cfscript>
session.cart.item = structnew();
// use the name also as a key
session.cart.item["john"]=structnew();
session.cart.item["john"]["name"] = "john";
session.cart.item["john"]["foodname"] = "Ribs";
session.cart.item["john"]["price"] = "13.99";
session.cart.item["john"]["comments"]="Johncomment";
session.cart.item["mary"]=structnew();
session.cart.item["mary"]["name"] = "mary";
session.cart.item["mary"]["foodname"] = "Apple";
session.cart.item["mary"]["price"] = "0.49";
session.cart.item["mary"]["comments"]="Marycomment";
session.cart.item["adam"]=structnew();
session.cart.item["adam"]["name"] = "adam";
session.cart.item["adam"]["foodname"] = "Cake";
session.cart.item["adam"]["price"] = "4.99";
session.cart.item["adam"]["comments"]="Adamcomment";
// the following line actually does all you ever wanted.
arrayToList() is just a bonus
// for easy-to-understand-output in the end. More elegant
solutions may exist. :-)
nameList =
arrayToList(structSort(session.cart.item,"textnocase","asc","name"));
</cfscript>
<cfoutput>
<cfloop list="#nameList#" index="currentName">
#session.cart.item[currentName].name#<BR>
#session.cart.item[currentName].foodname#<BR>
#session.cart.item[currentName].price#<BR>
#session.cart.item[currentName].comments#<BR>
<HR>
</cfloop>
</cfoutput> -
CFScript Math expression - Summing up looped over data
If I loop over numeric data and I want to sum that data I am looking for the correct manner to do so. Of course I want to do this in cfscript.
I know that I could go the route of doing a one demensional array and using the array sum function and I could also use stauctures.
I am interested in different solutions to this problem.
My end state is that I need to sum and average looped dynamic data for reporting purposes.
For purposes of example static values will be helpful for better understanding.
Thanks in advance.Owain,
This is what I came up with and it outputs the looped data. Now I am trying to add it up and average the results.
BTW Adam,
Be delusional on a Microsoft or Oracle forum board.
Now that would be some fun reading cutting through those flames! (In a patronising Kinda Way!).
Maybe you are looking for
-
Gallery Photo sharing feature not supported on Nok...
Hi, I upgraded my N8-00 with Belle but now I cant able to share my Gallery images on my social network, when ever I click on the share button in gallery it gives message 'Feature not supported'.. please provide necessary fix asap.. waiting for fix an
-
Flash and IE7 & Firefox ~ Display PROBLEM!!!
Hi Everybody, Hope some one can help: Recently, in IE7 and Firefox, I noticed my Flash SWF files which had black Bkgrnds [ya know, on the stage] didn't show as "black" but as a white or "no" color. Yesterday [11/28/07], Firefox did an update to versi
-
Installation errors for LR4 using disc on iMac OX X Lion
I'm trying to install an upgrade of LR4 on my iMac running OS X Lion 10.7.5 from a disc. Every time I try to install I get the following error: "The Installer encountered an error that caused the installation to fail. Contact the software manufacture
-
Regarding extraction using LO cockpit
We need to extract data from GL Accounting(eg. datasource like 0FI_GL_10) using LO cockpit. We have activated the above datasource using RSA5. Where is this datasource available in "LBWE" at the R3 side?
-
HELP, Black with white Apple
Hi there, I just bought my 30gb video ipod yesterday (have an old 3rd generation 20gb one ... needed a new one)and plugged it into the pc today. I dowloaded this ephed2 (sorry for the spelling, can´t remember it) programme an dowloaded the songs from