Nested Repeat Loops in Applescript
The following code has two lists: myURLs and myIMGs. I want to loop through the sites listed in myURLs, take a screenshot, then save them in my Shared folder as the file name listed in myIMGs. So, google.com's image will be saved as "google.jpg", and so forth. The list in myIMGs corresponds to the list in myURLs.
This is what I have, but it doesn't quite work. It loads the first URL from myURLs, takes a screenshot of it, but then loops through each file name in myIMGs and saves that one screenshot with all those various file names. Then, it loads the next URL in myURLs and does the same thing. How do I set the file names in the myIMGs list to correspond to the URLs being loaded from myURLs? I'm having trouble with the nested loops.
set myURLs to {"https://google.com", "https://wikipedia.org", "https://bing.com", "https://apple.com"}
set myIMGs to {"google.jpg", "wikipedia.jpg", "bing.jpg", "apple.jpg"}
-- Sets settings of Safari without interferring with user's settings.
repeat with myURL in myURLs
tell application "Safari"
set myDoc to front document
set windowID to id of window 1
do JavaScript ("window.open('" & myURL & "','_blank','titlebar=0');") in document 1
close window id windowID
set the bounds of the front window to {0, 20, 915, 812}
delay 5
end tell
-- Screengrab, crop and save to Shared folder
repeat with myIMG in myIMGs
do shell script "screencapture -o -l$(osascript -e 'tell app \"Safari\" to id of window 1') /Users/Shared/" & myIMG
set this_file to "Macintosh HD:Users:Shared:" & myIMG
try
tell application "Image Events"
-- start the Image Events application
launch
-- open the image file
set this_image to open this_file
-- get dimensions of the image
copy dimensions of this_image to {W, H}
-- Crops off the Safari header
crop this_image to dimensions {W, H - 50}
-- save the changes
save this_image with icon
-- purge the open image data
close this_image
end tell
end try
end repeat
end repeat
Switch to an indexed loop and you don't need the extra repeat loop; you can run the two lists in parallel. See my changes in red:
set myURLs to {"https://google.com", "https://wikipedia.org", "https://bing.com", "https://apple.com"}
set myIMGs to {"google.jpg", "wikipedia.jpg", "bing.jpg", "apple.jpg"}
-- Sets settings of Safari without interferring with user's settings.
repeat with i from 1 to (count of myURLs)
tell application "Safari"
set myDoc to front document
set windowID to id of window 1
do JavaScript ("window.open('" & item i of myURLs & "','_blank','titlebar=0');") in document 1
close window id windowID
set the bounds of the front window to {0, 20, 915, 812}
delay 5
end tell
-- Screengrab, crop and save to Shared folder
do shell script "screencapture -o -l$(osascript -e 'tell app \"Safari\" to id of window 1') /Users/Shared/" & (item i of myIMGs)
set this_file to "Macintosh HD:Users:Shared:" & myIMG
try
tell application "Image Events"
-- start the Image Events application
launch
-- open the image file
set this_image to open this_file
-- get dimensions of the image
copy dimensions of this_image to {W, H}
-- Crops off the Safari header
crop this_image to dimensions {W, H - 50}
-- save the changes
save this_image with icon
-- purge the open image data
close this_image
end tell
end try
end repeat
Similar Messages
-
Nested Repeat Regions in Dreamweaver 8
I am waying the option of upgrading from MX to 8 or just
getting MX Looper to do nested repeat regions. Any advice? Are
nested repeat regions built into Dreamweaver 8?SmellyPete wrote:
> I've got a problem with nested templates in my site. I
don't think it's an
> error or bug as such, just a really strange limitation,
that I hope there is a
> work around for.
>
> I've setup a menubar with a repeating table region in a
template. Then I laid
> out the content (editable) regions in a nested template.
The system works
> really well in dreamweaver, if you want to add a menu
item, you do so to the
> parent template, and then it filters through out the
site.
>
> The problem is that when I try to edit the pages as a
client with contribute
> (even as an administrator) it will not allow access to
edit a .dwt file, even
> if it has editable regions in it. This means I can't use
contribute to add an
> item to the menubar, because I need to be able to edit
the nested template. I'm
> sure it's possible, because a .dwt is just an .htm file
with a different hat on.
>
> There must be some way of doing this. As soon as I read
about the template
> system I immediately thought this would be one of it's
strengths, and would be
> very surprised if the contribute user were limited to
making changes on every
> individual page.
>
> PS. I'm sure someone will suggest that I just move the
repeating region into
> the nested template. I could do this, but the whole
point is that with one
> change I want it to will filter down through the whole
site. I thought maybe
> SSI might be the answer, but would that just confuse
contribute even more?
>
It seems to me the whole point of using Contribute is to keep
users from
changing basic site configurations such as the menu. Use
Dreamweaver or
one of the simple HTML editors around. -
Repeat Loop times out and I don't want it to
Maybe there is a better way to do this but I want an action to take place whenever the modification date of a certain file changes. This is what I use but it errors because of a timeout after about 10 mins if the mod date doesn't change. I need this to be checking all the time.
on idle
tell application "Finder"
set UpdatedOLD to modification date of file aFile
set UpdatedNEW to modification date of file aFile
end tell
repeat while UpdatedOLD = UpdatedNEW
tell application "Finder"
set UpdatedNEW to modification date of file aFile
end tell
end repeat
end idle
How can I get this to work?Hello
I think you have stepped on a land mine set by OSX 10.6.
There's a fatal bug in Apple Event Manager in 10.6 such that one event in every 65535 events will be lost and never be replied, which will result in Apple Event timeout error on sender. This bug has been reported shortly after the 10.6 release and has not yet been fixed as of 10.6.2.
In your current script, you're continuously sending event to Finder and sooner on later send an event with the specific event id that is doomed to be lost. Judging from the time till you see the time out error, that is 10 min, you're at most sending 65535 / 600 = 109.225 events / sec to Finder. You can reduce the number of events by inserting some delay, e.g. 'delay 1' in your repeat loop but it can only defer the failure.
cf.
Re: Timed Out (Silence)
http://lists.apple.com/archives/applescript-users/2009/Oct/msg00117.html
Re: spurious timeout on nth Apple event on Snow Leopard
http://lists.apple.com/archives/applescript-users/2009/Nov/msg00041.html
A better way to achieve your task would be to let a launchd agent watch the file.
A recipe is as follows.
1) Save a compiled script in :
~/Library/Scripts/launchd/watchdog.1.scpt
with contents :
--SCRIPT
-- Here put your script that is to be triggered when the file is modified.
-- e.g.
tell application "System Events"
display dialog "The file is modified." giving up after 10
end tell
--END OF SCRIPT
2) Save a UTF-8 plain text file in :
~/Library/LaunchAgents/watchdog.1.plist
with contents :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>watchdog.1</string>
<key>Disabled</key>
<false/>
<key>Program</key>
<string>/usr/bin/osascript</string>
<key>ProgramArguments</key>
<array>
<string>osascript</string>
<string>/Users/USER_NAME/Library/Scripts/launchd/watchdog.1.scpt</string>
</array>
<key>WatchPaths</key>
<array>
<string>POSIX_PATH_TO_THE_FIILE</string>
</array>
</dict>
</plist>
*Change USER_NAME to your user name and POSIX_PATH_TO_THE_FIILE to the POSIX path to the file to be watched.
3) Issue the following command in Terminal to load the launchd agent :
launchctl load ~/Library/LaunchAgents/watchdog.1.plist
Or
3a) Log-out and re-log-in to load the launchd agent.
*The name 'watchdog.1.plist' and 'watchdog.1.scpt' and the script's location '~/Library/Scripts/launchd/' are mere examples. You may change them as you see fit.
cf.
http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/m an5/launchd.plist.5.html
http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/m an1/launchctl.1.html
Good luck,
H
Message was edited by: Hiroto (fixed typo) -
Dreamweaver CS3
ASP / VBScript
Hi,
I'm trying to create a nested repeat region to display a list
of categories
and, in brackets afterwards, a count of the number of
sub-categories
contained in it E.g.
Cats (12)
Dogs (43)
Fish (92)
Etc
I have managed to create my repeat region ok because as soon
as I drop a
field in from the recordset, it loops through them all and
displays them
correctly. However, when I try and simply write out the total
number of
records found, it doesn't display anything.
Recordset 1 is a straighforward select from the table.
Recordset 2 adds a
WHERE clause usinga variable based on the 1st recordset. Here
is the code
i'm using for the 2 recordsets:
Recordset 1 :
<%
Dim Level1
Dim Level1_cmd
Dim Level1_numRows
Set Level1_cmd = Server.CreateObject ("ADODB.Command")
Level1_cmd.ActiveConnection = MM_SemiDirectory_STRING
Level1_cmd.CommandText = "SELECT * FROM TBL_Level1 ORDER BY
[Description]
ASC"
Level1_cmd.Prepared = true
Set Level1 = Level1_cmd.Execute
Level1_numRows = 0
%>
Recordset 2 :
<%
Dim Level2__varLink
Level2__varLink = "1"
If (level1.fields.item("Level1_ID").value <> "") Then
Level2__varLink = level1.fields.item("Level1_ID").value
End If
%>
<%
Dim Level2
Dim Level2_cmd
Dim Level2_numRows
Set Level2_cmd = Server.CreateObject ("ADODB.Command")
Level2_cmd.ActiveConnection = MM_SemiDirectory_STRING
Level2_cmd.CommandText = "SELECT * FROM TBL_Level2 WHERE
Level1_ID = ? ORDER
BY Level1_ID ASC"
Level2_cmd.Prepared = true
Level2_cmd.Parameters.Append
Level2_cmd.CreateParameter("param1", 5, 1, -1,
Level2__varLink) ' adDouble
Set Level2 = Level2_cmd.Execute
Level2_numRows = 0
%>
Now for the repeated code :
<%
While ((Repeat1__numRows <> 0) AND (NOT Level1.EOF))
%>
<li><a
href="category.asp?level1=<%=(Level1.Fields.Item("Level1_ID").Value)%>"><%=(Level1.Fields .Item("Description").Value)%>
(<%=(Level2_total)%>)
</li></a>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Level1.MoveNext()
Wend
%>
Can anyone tell me what I need to do to this code to make it
display the
number of sub-categories?
Thanks!!!Ok folks,
I found a way to get what I want. It's not pretty as I had to
make an extra
query in the database (that select of the count of all child
table results
for each parent category) and am pulling from that but it
works and that's
the main thing. I'm sure there is a more effective way of
doing it but
that's life!
I'm still interested in knowing the 'proper' way (if there is
such a thing)
so if you have the time to show me, i'm all ears!
Cheers!
"Mintyman" <[email protected]> wrote in message
news:[email protected]...
> Ok,
>
> So I closed the <li> code before the <a>
code. D'oh!
>
> Anyway, it returns a number now........the problem now
is that it returns
> the same value for each parent repeat!!!
>
> "Mintyman" <[email protected]> wrote in message
> news:[email protected]...
>> Dreamweaver CS3
>> ASP / VBScript
>>
>> Hi,
>>
>> I'm trying to create a nested repeat region to
display a list of
>> categories and, in brackets afterwards, a count of
the number of
>> sub-categories contained in it E.g.
>>
>> Cats (12)
>> Dogs (43)
>> Fish (92)
>> Etc
>>
>> I have managed to create my repeat region ok because
as soon as I drop a
>> field in from the recordset, it loops through them
all and displays them
>> correctly. However, when I try and simply write out
the total number of
>> records found, it doesn't display anything.
>>
>> Recordset 1 is a straighforward select from the
table. Recordset 2 adds a
>> WHERE clause usinga variable based on the 1st
recordset. Here is the
>> code i'm using for the 2 recordsets:
>>
>> Recordset 1 :
>>
>> <%
>> Dim Level1
>> Dim Level1_cmd
>> Dim Level1_numRows
>>
>> Set Level1_cmd = Server.CreateObject
("ADODB.Command")
>> Level1_cmd.ActiveConnection =
MM_SemiDirectory_STRING
>> Level1_cmd.CommandText = "SELECT * FROM TBL_Level1
ORDER BY [Description]
>> ASC"
>> Level1_cmd.Prepared = true
>>
>> Set Level1 = Level1_cmd.Execute
>> Level1_numRows = 0
>> %>
>>
>> Recordset 2 :
>>
>> <%
>> Dim Level2__varLink
>> Level2__varLink = "1"
>> If (level1.fields.item("Level1_ID").value <>
"") Then
>> Level2__varLink =
level1.fields.item("Level1_ID").value
>> End If
>> %>
>> <%
>> Dim Level2
>> Dim Level2_cmd
>> Dim Level2_numRows
>>
>> Set Level2_cmd = Server.CreateObject
("ADODB.Command")
>> Level2_cmd.ActiveConnection =
MM_SemiDirectory_STRING
>> Level2_cmd.CommandText = "SELECT * FROM TBL_Level2
WHERE Level1_ID = ?
>> ORDER BY Level1_ID ASC"
>> Level2_cmd.Prepared = true
>> Level2_cmd.Parameters.Append
Level2_cmd.CreateParameter("param1", 5,
>> 1, -1, Level2__varLink) ' adDouble
>>
>> Set Level2 = Level2_cmd.Execute
>> Level2_numRows = 0
>> %>
>>
>>
>> Now for the repeated code :
>>
>>
>> <%
>> While ((Repeat1__numRows <> 0) AND (NOT
Level1.EOF))
>> %>
>> <li><a
>>
href="category.asp?level1=<%=(Level1.Fields.Item("Level1_ID").Value)%>"><%=(Level1.Fields .Item("Description").Value)%>
>> (<%=(Level2_total)%>)
>> </li></a>
>>
>>
>> <%
>> Repeat1__index=Repeat1__index+1
>> Repeat1__numRows=Repeat1__numRows-1
>> Level1.MoveNext()
>> Wend
>> %>
>>
>> Can anyone tell me what I need to do to this code to
make it display the
>> number of sub-categories?
>>
>> Thanks!!!
>>
>>
>>
>
> -
Repeat loop in filemaker Pro 7 database
How can I get my script to loop through a large FM database of records and change the data in a particular field as in the script below? I cannot figure out the syntax for the repeat loop...
with timeout of "3000" seconds
tell application "FileMaker Pro"
go to database "CPA FM Log Copy"
show every record of database "CPA FM Log Copy"
set theCount to number of record of database "CPA FM Log Copy" as integer
repeat with i from record theCount of database "CPA FM Log Copy"
if field "ph" of record i of database "CPA FM Log Copy" is "NG" then
set data field "ph" of current record of database "CPA FM Log Copy" to "Nice Going"
else if field "ph" of record i of database "CPA FM Log Copy" is "EC" then
set data field "ph" of current record of database "CPA FM Log Copy" to "Everything Cool"
end if
end repeat
end tell
end timeoutDepending on the number of records in the database, this isn't the most efficient way of doing this.
You should use a 'whose' clause in your script to narrow the FileMaker results to the subset of records you want to change, then change them all at once. This is far more efficient than looping through thousands of records in AppleScript looking for the ones you want.
This should get you on the right track:
<pre class=command>tell application "Filemaker Pro"
go to database "CPA FM Log Copy"
set theResults to every record of database "CPA FM Log Copy" whose field "ph" is "NG"
set data field "ph" of every item of theResults to "Nice Going"
set theResults to every record of database "CPA FM Log Copy" whose field "ph" is "EC"
set data field "ph" of every item of theResults to "Everything Cool"
end tell</pre>
In this way you let Filemaker do the searching (which is what it's optimized for), and your script does the least work necessary.
BTW, just so you know why your original script fails, it's because you say:
<pre class=command>set data field "ph" of current record of database "CPA FM Log Copy" to "Nice Going"</pre>
Note that you're always setting the 'current record'. This means that even if there are 1000 records in the database, you only ever set the first field. If you wanted to maintain the repeat approach this would have to change to something like:
<pre class=command>set data field "ph" of record i of database "CPA FM Log Copy" to "Nice Going"</pre>
so now it uses the loop iterator to track which record to change. An even better model that does use a scalar index is to do something like:
<pre class=command>repeat with curRecord in every record of database "CPA FM Log Copy"
if field "ph" of curRecord is "NG" then
set data field "ph" of curRecord to "Nice Going"
end if
end repeat</pre>
This nice thing about this model is that it uses FileMaker's internal references for records so that you know you're changing the right thing. This can be crucial if working in a multi-user database where there might be someone else is editing the data in parallel, changing theCount. -
Nested Repeat Region (How to convert from table to list)
Sorry, i am really no PHP hero :-(
i created a menu with the "nested repeat region" wizzard. Now i want to change the HTML from TABLE to LIST.
I thought i just need to delete <table>- and <td>-tags, replace <tr> with <ul> and that's it. (But ist's NOT!)
This is my code:
------- START ----------------
<ul id="nav">
<?php do { ?>
<li><?php echo $row_master1waa_page_top['top_name']; ?></li>
<?php
if ($totalRows_master1waa_page_top>0) {
$nested_query_detail2waa_page_sub = str_replace("123456789", $row_master1waa_page_top['id_top'], $query_detail2waa_page_sub);
mysql_select_db($database_WAA);
$detail2waa_page_sub = mysql_query($nested_query_detail2waa_page_sub, $WAA) or die(mysql_error());
$row_detail2waa_page_sub = mysql_fetch_assoc($detail2waa_page_sub);
$totalRows_detail2waa_page_sub = mysql_num_rows($detail2waa_page_sub);
$nested_sw = false;
if (isset($row_detail2waa_page_sub) && is_array($row_detail2waa_page_sub)) {
do { //Nested repeat
?>
<ul>
<li> <?php echo $row_detail2waa_page_sub['sub_head']; ?></li>
</ul>
<?php
} while ($row_detail2waa_page_sub = mysql_fetch_assoc($detail2waa_page_sub)); //Nested move next
?>
<?php } while ($row_master1waa_page_top = mysql_fetch_assoc($master1waa_page_top)); ?>
</ul>
------- END -----
The problem is located in line 3. the result is a list like this:
<ul id="nav">
<li>xxx</li>
<li>xxx</li>
<ul>
<li>xxx</li>
<li>xxx</li>
</ul>
<li>xxx</li>
</ul>
Of course it will not work. I need the nested list inserted like this:
<ul id="nav">
<li>xxx</li>
<li>xxx
<ul>
<li>xxx</li>
<li>xxx</li>
</ul>
</li>
<li>xxx</li>
</ul>
Can someone please help me changing my code to get this result?Hi,
I had trouble replying. I may be of some assistance until one of the Guru's get on.
The whole thing works on loops based inside do and while
EX.
<?php
do{ //end php, use html
?>
I can repeat anthing here in HTML!
<?php } while ( /* some critera exist ex: i<5 */ ); ?>
so, your 'options' tag or LI' tags should only exist inside the first loop, check your { }
The entire LIST would repeat if you add the UL tags inside the nested loop area
You may find it easier to reaplace the table with div tags and then indent the sub or nested loop with a class
I don't have time to test this but try this:
<ul id="nav">
<ul>
<?php do { ?>
<li><?php echo $row_master1waa_page_top['top_name']; ?></li>
<?php
if ($totalRows_master1waa_page_top>0) {
$nested_query_detail2waa_page_sub = str_replace("123456789", $row_master1waa_page_top['id_top'], $query_detail2waa_page_sub);
mysql_select_db($database_WAA);
$detail2waa_page_sub = mysql_query($nested_query_detail2waa_page_sub, $WAA) or die(mysql_error());
$row_detail2waa_page_sub = mysql_fetch_assoc($detail2waa_page_sub);
$totalRows_detail2waa_page_sub = mysql_num_rows($detail2waa_page_sub);
$nested_sw = false;
if (isset($row_detail2waa_page_sub) && is_array($row_detail2waa_page_sub)) { ?>
<ul>
<?php do { //Nested repeat ?>
<li> <?php echo $row_detail2waa_page_sub['sub_head']; ?></li>
<?php } while ($row_detail2waa_page_sub = mysql_fetch_assoc($detail2waa_page_sub)); //Nested move next ?>
</ul>
<?php
?>
<?php } while ($row_master1waa_page_top = mysql_fetch_assoc($master1waa_page_top)); ?>
</ul>
Hit me back if its close but wonky..
J -
Beginner Question: Won't execute index to nested while loop
Problem:
I have a nested while loop inside a for loop. The for loop runs over and over from 0 to 587. I want the while loop to only execute when the for loop hits 587 by means of a continue condition which is on when 587 = [ i ], the for loop iteration number. However when I try to change the value sent to the while loop from 588 none of the probes execute. This is bad because the index only runs from 0 to 587 and never equals 588.
Context:
This is for real time video analysis. Trying to convert a 658 x 492 color video feed frame by frame into low resolution grayscale video. With this index error the output is currently the top left 1/4 of the image, repeated in a 2x2 grid on the image display.
The VI is attached. I'm very appreciative of your thoughts on this.
Attachments:
Bin.vi 237 KBThe for loop is responsible for processing a frame. At the completion of the execution of [ i ] from 0 to 587, the replace array VI outputs the final product of the frame. So every time [ i ] = 587, the replace array VI needs to send its array to the arraytoimage, which in turn must send the image to the image display.
I got rid of the while loop and replaced it with the case structure.
Maybe the problem is with the false case of the case structure? I want to continue outputting the same image for the next [0, 586] each time after it sends an updated image on the [ i ] = 587 iteration.
Attachments:
Bin.vi 238 KB -
Interrupt repeat loops with buttons
Hi,
How do I make buttons available to the user while I run a repeat loop?
I'm doing a shell script in the background and I'm using a repeat loop to read out the log of the results. Meanwhile, I want to have a Cancel button available to the user.
The button however doesn't respond while the repeat loop runs, while the rest of my UI is in fact updating (based on the incoming log). I'm even using a one second delay at the beginning of the loop.
I'm using AppleScript Studio in Xcode/Interface Builder.
Thanks,
JW1. Create a control in the window which has some sort of boolean property (if you are using a progress bar, then you already have one, since a progress bar can be indeterminate, and you can check this).
2. Set the handler which shows the window (or alters the window when the process begins) to set this boolean property to a particular value
3. Have the "Cancel" button handler invert the property
4. Have the repeat loop check the property as part of its boolean condition (as in "repeat while x is true")
Note that if the window is going to go away anyway when the process is complete, then you can use the window's title to indicate the status: set the title to "Cancelling..." and have the repeat loop check whether the title of the window is "Cancelling...".
You could also just create a global within the script file, and have the repeat loop check the status of the global, but that tends to lead, sooner or later, to overlapping reuse of a single global value, which is a bug. -
Real Instruments play beyond end of repeated loop
I've tried every google-fu trick I could think of to see if anyone else has had this problem.
I record a real instrument (say an electric guitar riff). I drag/repeat/loop it 3 or 4 times. It plays properly.
Then at some point I select it, and move it left or right.
The part starts at the right time, but will repeat an extra time beyond the visible onscreen loop. Once this glitch occurs, neither resaving, shrinking/re-repeating, moving it around and then back to where I want it make the track end when it's supposed to.
The only way I've found around it, is to end the repeat early and let the erroneous repeat play out, or just end the repeat entirely, and use cut'n'paste instead.
This happens to me *all the time*... anyone else seen this or have a resolution?Thanks for the suggestions. I can't remember deleting any tracks... however, how would i check for "hidden" tracks?
The funny thing is i can hear the effect returns for the real instrument tracks...tracks that are heavily reverbed i can hear a faint echo of the track. and like i mentioned the drum loop and software piano still play fine.
And, I also see monitor activity in the real instrument tracks when i play the song. Everything looks normal, but of course, the sound isn't there.
Thanks again for your help!
Message was edited by: Ike the Longshoreman
P.S. I just tried Unsolo all tracks and Unmute all tracks... still the same problem. -
Issues with nested for loops - saving images from a camera
Hi all,
I've written a vi. to capture a specific number of images ('Image No') and save these images, outputted to a folder of my choice. Each image is identified sequentially. However, I wish to do a number of iterations ('Run') of this capture sequence, such that the filename of each image would be 'Filename (Run)_(Image No).png', e.g. run 5, image 10 would be 'Filename 5_10.png'. I have tried a nested for loop for this but I receive an error 'Asynchronous I/O operation in progress' (I've attached a printscreen).
Can anyone assist me in solving this problem? I preiously posted this in machine Vision but got no response (http://forums.ni.com/t5/Machine-Vision/Capturing-image-sequences-issues-with-nested-for-loops/m-p/19...). Please find attached my vi.
Kindest regards and thanks,
Miika
Solved!
Go to Solution.
Attachments:
Labview problem.jpg 3841 KB
Image sequence save to file.vi 48 KBMiika,
the problem is not the filenam, but the name of the folder (AHHHHH!). You try to create the same folder in the outer for loop over and over again.... (it is the error message above the '======', not below )
Norbert
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it. -
hi all,
I need to implement nested for loop in Xquery, but not able to do. Please help.
Thanks in advance..
RajanNested for loops are simple in Xquery. Here is a very basic example:
Input:
<root>
<FirstLevel>
<SecondLevel>
<Value>1</Value>
</SecondLevel>
<SecondLevel>
<Value>2</Value>
</SecondLevel>
<SecondLevel>
<Value>3</Value>
</SecondLevel>
</FirstLevel>
<FirstLevel>
<SecondLevel>
<Value>4</Value>
</SecondLevel>
<SecondLevel>
<Value>5</Value>
</SecondLevel>
<SecondLevel>
<Value>6</Value>
</SecondLevel>
</FirstLevel>
</root>XQuery:
declare namespace ns0 = "http://temp.uri/OTM";
declare function ns0:NestedForLoop($input as element(*)) as element(*)
<ns0:Output>
for $firstLevel in $input/FirstLevel
for $secondLevel in $firstLevel/SecondLevel
return
<element>{ $secondLevel/Value/text() }</element>
</ns0:Output>
declare variable $input aselement(*) external;
ns0:NestedForLoop($input)Output:
<otm:Output xmlns:otm="http://temp.uri/OTM">
<element>1</element>
<element>2</element>
<element>3</element>
<element>4</element>
<element>5</element>
<element>6</element>
</otm:Output>Of course, this case is very simple and usually you wont even loop for this you can use a simple XPath like $input/FirstLevel/SecondLevel/Value/text() to achieve the above result. So, If you are having problems in a specific case of nested for loops, please post the input and output here and we can help out. -
Limit records in nested repeat region
I am using the nested repeat region behaviour and I need to limit the amount of records in the detail table.
in ADDT it guides you through a wizard for master and detail tables to use this nesting which works great but it also returns all the records in the detail. I would like to limit the amount.
I tried modifying the query by adding
$maxRows_detail4tbl_products = 4;
$pageNum_detail4tbl_products = 0;
if (isset($_GET['pageNum_detail4tbl_products'])) {
$pageNum_detail4tbl_products = $_GET['pageNum_detail4tbl_products'];
$startRow_detail4tbl_products = $pageNum_detail4tbl_products * $maxRows_detail4tbl_products;
still returns all rows. any help is greatly appreciated.In the Application Panel, select the tab Biddings
dbclick Recordset Detail. Click the Advanced button, in the last SQL command ORDER BY
You add LIMIT 0,4 -
URGENTLY NEED HELP WITH NESTED REPEAT REGION
Im using dreamweaver to deevelop a page that displays questions in ann assessment to the user. First of all the page shows the assessment name to the user and then it gets some information about the questions in the assessment from the table called Item. It gets the Question_ID and then there is a repeat region which uses the Question_ID to display the questions in the assessment. There is a nested repeat region inside this which displays the possible answers the user can respond to the question with It gets this information from a table called outcome. The page should display each question and then all the possible answers but i am having problems and im not sure wether i am doing this in the correct way. What is wrong with my code? PLEASE HELP! can someone tell me what is going wrong and how i can fix this problem thamks.
here is my code.
Driver DriverassessmentRecordset = (Driver)Class.forName(MM_connAssessment_DRIVER).newInstance();
Connection ConnassessmentRecordset = DriverManager.getConnection(MM_connAssessment_STRING,MM_connAssessment_USERNAME,MM_connAssessment_PASSWORD);
PreparedStatement StatementassessmentRecordset = ConnassessmentRecordset.prepareStatement("SELECT Assessment_ID, Assessment_Name, Time_Limit, Display_Random, Record_Answers FROM Assessment.assessment WHERE Assessment_ID = '" + session.getValue("AssessmentID") + "' ");
ResultSet assessmentRecordset = StatementassessmentRecordset.executeQuery();
boolean assessmentRecordset_isEmpty = !assessmentRecordset.next();
boolean assessmentRecordset_hasData = !assessmentRecordset_isEmpty;
Object assessmentRecordset_data;
int assessmentRecordset_numRows = 0;
%>
<%
Driver DriveritemRecordset = (Driver)Class.forName(MM_connAssessment_DRIVER).newInstance();
Connection ConnitemRecordset = DriverManager.getConnection(MM_connAssessment_STRING,MM_connAssessment_USERNAME,MM_connAssessment_PASSWORD);
PreparedStatement StatementitemRecordset = ConnitemRecordset.prepareStatement("SELECT Question_ID, Assessment_ID FROM Assessment.item WHERE Assessment_ID = '" + session.getValue("AssessmentID") + "' ");
ResultSet itemRecordset = StatementitemRecordset.executeQuery();
boolean itemRecordset_isEmpty = !itemRecordset.next();
boolean itemRecordset_hasData = !itemRecordset_isEmpty;
Object itemRecordset_data;
int itemRecordset_numRows = 0;
%>
<%
Driver DriverquestionRecordset = (Driver)Class.forName(MM_connAnswer_DRIVER).newInstance();
Connection ConnquestionRecordset = DriverManager.getConnection(MM_connAnswer_STRING,MM_connAnswer_USERNAME,MM_connAnswer_PASSWORD);
//PreparedStatement StatementquestionRecordset = ConnquestionRecordset.prepareStatement("SELECT Question_Type, Number_Outcomes, Question_Wording FROM Answer.question WHERE Question_ID = '" + (((itemRecordset_data = itemRecordset.getObject("Question_ID"))==null || itemRecordset.wasNull())?"":itemRecordset_data) +"' ");
//ResultSet questionRecordset = StatementquestionRecordset.executeQuery();
%>
<%
Driver DriveroutcomeRecordset = (Driver)Class.forName(MM_connAnswer_DRIVER).newInstance();
Connection ConnoutcomeRecordset = DriverManager.getConnection(MM_connAnswer_STRING,MM_connAnswer_USERNAME,MM_connAnswer_PASSWORD);
PreparedStatement StatementoutcomeRecordset = ConnoutcomeRecordset.prepareStatement("SELECT Outcome_Number, Outcome_Text, Score, Feedback FROM Answer.outcome WHERE Question_ID = '" +itemRecordset.getObject("Question_ID")+ "' ");
ResultSet outcomeRecordset = StatementoutcomeRecordset.executeQuery();
boolean outcomeRecordset_isEmpty = !outcomeRecordset.next();
boolean outcomeRecordset_hasData = !outcomeRecordset_isEmpty;Object outcomeRecordset_data;
int outcomeRecordset_numRows = 0;
%>
<%
int Repeat1__numRows = -1;
int Repeat1__index = 0;
itemRecordset_numRows += Repeat1__numRows;
%>
<%
int Repeat2__numRows = -1;
int Repeat2__index = 0;
assessmentRecordset_numRows += Repeat2__numRows;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/assessment.dwt.jsp" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Assessment</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="../css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="1000" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td height="190"><img src="../img/assessment_login.png" alt="" name="navigation" width="1000" height="190" border="0" id="navigation" /></td>
</tr>
<tr>
<td height="19"><!--DWLayoutEmptyCell--> </td>
</tr>
<tr>
<td height="19"><!-- InstanceBeginEditable name="main" -->
<table>
<tr>
<td width="990">Assessment Name:<%=(((assessmentRecordset_data = assessmentRecordset.getObject("Assessment_Name"))==null || assessmentRecordset.wasNull())?"":assessmentRecordset_data)%> </td>
</tr>
<tr>
<td><% int count = 1; %> </td>
</tr>
<tr>
<td valign="top"><table>
<% while ((itemRecordset_hasData)&&(Repeat1__numRows-- != 0)) { %>
<tr>
<td width="21">
</td>
<td width="86">Question:<%= count %></td>
</tr>
<tr>
<td></td>
<td>
<%
PreparedStatement StatementquestionRecordset = ConnquestionRecordset.prepareStatement("SELECT Question_Type, Number_Outcomes, Question_Wording FROM Answer.question WHERE Question_ID = '" +itemRecordset.getObject("Question_ID")+"' ");
ResultSet questionRecordset = StatementquestionRecordset.executeQuery();
boolean questionRecordset_isEmpty = !questionRecordset.next();
boolean questionRecordset_hasData = !questionRecordset_isEmpty;
Object questionRecordset_data;
int questionRecordset_numRows = 0;
%> <%= questionRecordset.getObject("Question_Wording") %></td>
</tr>
<tr>
<td></td>
<td>
</td>
</tr>
<tr>
<td></td>
<td>
<table>
<% while ((outcomeRecordset_hasData)&&(Repeat2__numRows-- != 0)) {%>
<tr>
<td><%=(((outcomeRecordset_data = outcomeRecordset.getObject("Outcome_Number"))==null || outcomeRecordset.wasNull())?"":outcomeRecordsetRecordset_data)%></td>
<td><%=(((outcomeRecordset_data = outcomeRecordset.getObject("Outcome_Text"))==null || outcomeRecordset.wasNull())?"":outcomeRecordsetRecordset_data)%></td>
<td><%=(((outcomeRecordset_data = outcomeRecordset.getObject("Score"))==null || outcomeRecordset.wasNull())?"":outcomeRecordsetRecordset_data)%></td>
<td><%=(((outcomeRecordset_data = outcomeRecordset.getObject("Feedback"))==null || outcomeRecordset.wasNull())?"":outcomeRecordsetRecordset_data)%></td>
<td><%=(((outcomeRecordset_data = outcomeRecordset.getObject("Question_ID"))==null || outcomeRecordset.wasNull())?"":outcomeRecordsetRecordset_data)%></td>
</tr>
<%
Repeat2__index++;
outcomeRecordset_hasData = outcomeRecordset.next();
%>
</table>
<table>
<tr> </tr>
<tr> </tr>
</table></td>
</tr>
<%
Repeat1__index++;
itemRecordset_hasData = itemRecordset.next();
count++;
//questionRecordset.close();
//StatementquestionRecordset.close();
//ConnquestionRecordset.close();
%>
Here is the exception i am gettingorg.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 115 in the jsp file: /delivery/session.jsp
Generated servlet error:
C:\Servers\Tomcat 5.0\work\Catalina\localhost\assessment\org\apache\jsp\delivery\session_jsp.java:220: cannot find symbol
symbol : variable outcomeRecordsetRecordset_data
location: class org.apache.jsp.delivery.session_jsp
out.print((((outcomeRecordset_data = outcomeRecordset.getObject("Outcome_Number"))==null || outcomeRecordset.wasNull())?"":outcomeRecordsetRecordset_data));
^
An error occurred at line: 116 in the jsp file: /delivery/session.jsp
Generated servlet error:
C:\Servers\Tomcat 5.0\work\Catalina\localhost\assessment\org\apache\jsp\delivery\session_jsp.java:223: cannot find symbol
symbol : variable outcomeRecordsetRecordset_data
location: class org.apache.jsp.delivery.session_jsp
out.print((((outcomeRecordset_data = outcomeRecordset.getObject("Outcome_Text"))==null || outcomeRecordset.wasNull())?"":outcomeRecordsetRecordset_data));
^
An error occurred at line: 117 in the jsp file: /delivery/session.jsp
Generated servlet error:
C:\Servers\Tomcat 5.0\work\Catalina\localhost\assessment\org\apache\jsp\delivery\session_jsp.java:226: cannot find symbol
symbol : variable outcomeRecordsetRecordset_data
location: class org.apache.jsp.delivery.session_jsp
out.print((((outcomeRecordset_data = outcomeRecordset.getObject("Score"))==null || outcomeRecordset.wasNull())?"":outcomeRecordsetRecordset_data));
^
An error occurred at line: 118 in the jsp file: /delivery/session.jsp
Generated servlet error:
C:\Servers\Tomcat 5.0\work\Catalina\localhost\assessment\org\apache\jsp\delivery\session_jsp.java:229: cannot find symbol
symbol : variable outcomeRecordsetRecordset_data
location: class org.apache.jsp.delivery.session_jsp
out.print((((outcomeRecordset_data = outcomeRecordset.getObject("Feedback"))==null || outcomeRecordset.wasNull())?"":outcomeRecordsetRecordset_data));
^
An error occurred at line: 119 in the jsp file: /delivery/session.jsp
Generated servlet error:
C:\Servers\Tomcat 5.0\work\Catalina\localhost\assessment\org\apache\jsp\delivery\session_jsp.java:232: cannot find symbol
symbol : variable outcomeRecordsetRecordset_data
location: class org.apache.jsp.delivery.session_jsp
out.print((((outcomeRecordset_data = outcomeRecordset.getObject("Question_ID"))==null || outcomeRecordset.wasNull())?"":outcomeRecordsetRecordset_data));
^
An error occurred at line: 119 in the jsp file: /delivery/session.jsp
Generated servlet error:
Note: C:\Servers\Tomcat 5.0\work\Catalina\localhost\assessment\org\apache\jsp\delivery\session_jsp.java uses or overrides a deprecated API.
An error occurred at line: 119 in the jsp file: /delivery/session.jsp
Generated servlet error:
Note: Recompile with -Xlint:deprecation for details.
An error occurred at line: 119 in the jsp file: /delivery/session.jsp
Generated servlet error:
Note: C:\Servers\Tomcat 5.0\work\Catalina\localhost\assessment\org\apache\jsp\delivery\session_jsp.java uses unchecked or unsafe operations.
An error occurred at line: 119 in the jsp file: /delivery/session.jsp
Generated servlet error:
Note: Recompile with -Xlint:unchecked for details.
5 errors
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)Hi,
Dont have much time to go through your code, but apparently i can see the error is becoz of the following reason.
In the following code, you have used "outcomeRecordset_data ", but its not declared. You need to declare the variable first before you can use it.
<% while ((outcomeRecordset_hasData)&&(Repeat2__numRows-- != 0)) {%>
<tr>
<td><%=(((outcomeRecordset_data = outcomeRecordset.getObject("Outcome_Number"))==null || outcomeRecordset.wasNull())?"":outcomeRecordsetRecordset_data)%></td>
<td><%=(((outcomeRecordset_data = outcomeRecordset.getObject("Outcome_Text"))==null || outcomeRecordset.wasNull())?"":outcomeRecordsetRecordset_data)%></td>
<td><%=(((outcomeRecordset_data = outcomeRecordset.getObject("Score"))==null || outcomeRecordset.wasNull())?"":outcomeRecordsetRecordset_data)%></td>
<td><%=(((outcomeRecordset_data = outcomeRecordset.getObject("Feedback"))==null || outcomeRecordset.wasNull())?"":outcomeRecordsetRecordset_data)%></td>
<td><%=(((outcomeRecordset_data = outcomeRecordset.getObject("Question_ID"))==null || outcomeRecordset.wasNull())?"":outcomeRecordsetRecordset_data)%></td>
</tr>
<%
Repeat2__index++;
outcomeRecordset_hasData = outcomeRecordset.next();
%>Try declaring the "outcomeRecordset_data " on top as an object
Hope it helps -
PDF template - Looking for syntax to handle non-nesting repeat groups
All,
I followed XML publisher documentation for the first repeat group using BODY_START, T1_G1, T1_G2,,,,BODY_END. It works as expected. Could anyone post the syntax to handle more than one repeat group within a PDF template. These are not nesting repeat groups.
Really appreciate any help to point me in the right direction.
Thanks in advance
GopalYour question was "... but the font on the footer is much larger than that of the template", yes?
I only can repeat, look at the difference of:
1. index.html (Font-size > medium) >
2. Calendar.html (Font-size > no entry):
> "... font on the footer is much larger than that of the template",
Hans-Günter
P.S.
See us again - maybe - at Monday > we will do a nice little trip to Austria. -
Nested For Loop Trouble?
Ok I need to have a nested for loop that asks a user to enter in a int number from 1-50. Whatever the number is, lets say 4 I need the program to count up asterisk and count down asterisks, like this.
This is my code:
import java.io.*;
public class Stars {
static int n;
static private InputStreamReader in = new InputStreamReader(System.in);
static private BufferedReader br = new BufferedReader(in);
public static void main(String[] Args)throws IOException
System.out.println("Please enter in a number to see display: ");
String num = br.readLine();
n=Integer.parseInt(num);
for(int i=1;i<=n;i++)
for(int j=1;j<=i;j++)
System.out.print("*");
for(int j=1;j<=i;j--)
System.out.print("*");
System.out.println();
Can someone tell me what I am doing wrong so I can figure out my mistake(s).Ok, well I know that the loop relies on the number entered in by the user. So if i pick 3 the three enter in the loop and counts up in a for loop and for every number it counts up to the three it does a print("*"); Now what I am getting confused about is where the other for loop comes into play. I know that I need to start from the number I have which is 3, so I need to have one less than that and then count down. The thing is that i'm not sure where or how the second for loop gets implemented into the code. Does it get nested with the first loop like this:
for(int i=1;i<=n;i++)
for(int j=1;j<=i;j++)
for(int j=n-1;j>=i;j--)
System.out.print("*");
System.out.println();
}Or is the second for loop on its own like this:
for(int i=1;i<=n;i++)
for(int j=1;j<=i;j++)
System.out.print("*");
for(int j=n-1;j>=i;j--)
System.out.print("*");
System.out.println();
}If someone can help me understand, for this is my first time with nested for loops.
Maybe you are looking for
-
Images in my Aperture 3 libraries have lost their original "date created"
Just made a very discouraging discovery regarding the "date created" field for my photos. Noticed that all photos in any project default to the same date created, even if they weren't shot on the same date. Not sure what date they're all defaulting t
-
Materialized views in 8i and 9i
Hi All, I wanted to know the differences/comparison of MVs in 8i and 9i versions. Can you please lead me to some documentation if available on this? Thanks in advance... BRK
-
Copy and paste stops working in OS10.8
I am on OS10.8.4 running on a 2010 Macbook Pro (2.53 GHZ Intel Core 2 Duo, 8GB Ram). While working on my laptop with several windows or programs open I will eventually loose the function of Copy-Paste, and click-drag. To get these functions to work
-
I just inherited a semi dead iMac. When booted it displays the OS 9 icon and never goes any further. The previous owner says he was running 10.3.X I ran Disk Warrior. It completed and the system was rebooted. The drive spun up but the screen remained
-
DeployJava.js ,Applet Deployment errors?
Some great work has been done on applet deployment. ref: [Applet deployment toolkit |http://blogs.sun.com/thejavatutorials/entry/deployment_toolkit_101 ] I've been trying to use this tool with considerable frustration. I'm serving internet applicatio