Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 5th, 2004, 12:29 PM
Registered User
 
Join Date: Jun 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mcedwards
Default For...Next Loop

Hi guys,

I am trying to use a For...Next loop to cycle through the rows in a DataRow to put them into an XML file. I have written the following code...
Code:
For count = 0 To 7
                writer.WriteStartElement("Day")
                writer.WriteElementString("Date", objWeeklyRow(count).Item("Date"))
                writer.WriteElementString("Maximum", objWeeklyRow(count).Item("Maximum"))
                writer.WriteElementString("Grass_Min", objWeeklyRow(count).Item("Grass_Min"))
                writer.WriteElementString("Ten_Soil", objWeeklyRow(count).Item("Ten_Soil"))
                writer.WriteElementString("Rainfall_Total", objWeeklyRow(count).Item("Rainfall_Total"))
                writer.WriteElementString("Max_Intensity", objWeeklyRow(count).Item("Max_Intensity"))
                writer.WriteElementString("Sunshine_Total", objWeeklyRow(count).Item("Sunshine_Total"))
                writer.WriteElementString("Prevailing_Direction", objWeeklyRow(count).Item("Prevailing_Direction"))
                writer.WriteElementString("Ave_Speed", objWeeklyRow(count).Item("Ave_Speed"))
                writer.WriteElementString("Max_Gust", objWeeklyRow(count).Item("Max_Gust"))
                writer.WriteElementString("Pressure", objWeeklyRow(count).Item("Pressure"))
                writer.WriteElementString("Comment", objWeeklyRow(count).Item("Comment"))
            writer.WriteEndElement()
         Next count
When the code is getting compiled i get an error saying "Index was outside the bounds of the array" If I put the numbers to reference the row in the parentheses (instead of the variable 'count') it works as it should but I wish to loop the procedure otherwise I will have pages and pages of repeated code.

Does anyone have any ideas what I am doing wrong??

Regards
Mark Edwards
 
Old March 5th, 2004, 01:15 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Are you trying to loop 7 times? Once for each Weekday?

In that case, change the loop to Count from 0 to 6, instead of 7....

If that doesn't help, make sure that objWeeklyRow contains 8 items, from 0 to 7....

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old March 5th, 2004, 01:33 PM
Registered User
 
Join Date: Jun 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mcedwards
Default

It works now! :-) Thank you! I am kicking myself that I forgot that the indexing started at 0, should know that being a C programmer primarily.

Mark





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with for-each loop athanatos XSLT 0 April 10th, 2006 07:20 PM
Do Until loop with IF crmpicco Classic ASP Databases 2 June 15th, 2005 05:35 PM
For....Loop kliu9 Excel VBA 5 February 10th, 2005 06:43 AM
Do Loop junemo Beginning PHP 8 July 28th, 2004 02:58 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.