473,563 Members | 2,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to know if loop contains a fixed number of iterations

124 New Member
According to the thread "For...Next vs Do...Loop, and the Winner is?" you should use a For...Next loop if it has a fixed number of iterations and doesn't contain any logical conditions. This may be a dumb question but how do I know if my loop contains a fixed number of iterations? The majority of my loops consist of opening a recordset with a string expression equating to a query. Example:

Expand|Select|Wrap|Line Numbers
  1.         strRstClass = "SELECT C.* FROM StdDegReqClass C INNER JOIN StdDegReqDisc D ON C.StdDegReqDiscId = " _
  2.                     & "D.StdDegReqDiscId WHERE C.StdDegReqDiscId = " & lngDiscId & " ORDER BY C.SortOrder"
  3.         Set rstClass = CurrentDb.OpenRecordset(strRstClass, dbOpenSnapshot)
  4.  
or

Expand|Select|Wrap|Line Numbers
  1. Set rstDegReqDisc = CurrentDb.OpenRecordset("SELECT * FROM DegReqDisc WHERE DegReqId = " & lngDegReqId, dbOpenSnapshot)
  2.  
The recordset type is always Snapshot. (If I do any updating/deleting I usually do a CurrentDb.Execu te "UPDATE..." , not on the recordset.) I want to loop through the recordset until EOF or until another condition is met if not at EOF. Here's an example of a For...Next loop that I have that illustrates this:

Expand|Select|Wrap|Line Numbers
  1.         For intClass = 0 To rstClass.RecordCount
  2.  
  3.             If rstClass.EOF Then
  4.                 Exit For
  5.             End If
  6.  
  7.             If sngDiscCredits >= rstDisc!CreditMin And lngDiscCourses >= rstDisc!CourseMin Then
  8.                 lngTakenDiscId = lngDiscId
  9.                 Exit For
  10.             End If
  11.  
  12.             'more code....
  13.             rst.MoveNext
  14.         Next
  15.  
So, from what I described, which looping structure should I use?
May 21 '10 #1
1 2234
ADezii
8,834 Recognized Expert Expert
Personally, this is the Looping Structure that I always use and find to be very concise, and efficient:
Expand|Select|Wrap|Line Numbers
  1. 'The Recordset rst has previously been defined
  2.  
  3. With rst
  4.   Do While Not .EOF
  5.     'processing example
  6.     Debug.Print ![FirstName] & " " & ![LastName]
  7.       .MoveNext
  8.   Loop
  9. End With
  10.  
  11. rst.Close
  12. Set rst = Nothing
May 21 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
48359
by: Michael | last post by:
Hi, I am using w2000+sp4 server with IIS running, how can I know my IIS version number, is it iis5.0 or 5.1 or 6.0? I must know this, since I want to download patches from MS web site, urgent... Thx Michael
10
8102
by: Aaron Smith | last post by:
If I have a datagrid and the bound data file only have 4 rows in it, the grid will show the 4 rows. However, there is blank space below that until it reaches the bottom of the grid. Is there a way to have a fixed number of rows regardless of what data is in the bound table? Thanks, Aaron -- --- Aaron Smith
18
12318
by: Michel Rouzic | last post by:
I can't think of a simple way to print integers with a fix number of digits, in order to obtain something like 0001 for 1 and 0100 for 100 automatically just by specifying in a variable the number of desired digits. I thought about printing to a variable using for example %4d and then replace ' ' by '0', but I don't know if i can print to...
0
901
by: Kiran_Juikar | last post by:
Hi, My application needs to be installed on machines across the network. But I want to restrict these installations to a fixed number provided with license file. How should I do it.
4
2237
by: Jack E Leonard | last post by:
I'm looping through the keys and values of a form submission using foreach($_POST as $key => $value) echo "$key = $value<br>"; No problems there. All works as expected. But seveal of the values are arrays and the echo comes out like: subjectone = Array subjecttwo = Array
0
1863
by: pomeroymiles | last post by:
I have a pivotchart which I cause to take a huge list of people's test percentiles and calculate the average for each year. I then display the average above each bar. The problem is that there are too many numbers after the decimal place for each figure. I went into the properties and changed the number format to "fixed" but it doesn't give me...
2
1060
by: raulverde | last post by:
I have an element declared like this : <xs:element name="class"> <xs:complexType> <xs:sequence> <xs:element name="name" type="className" minOccurs="0" /> <xs:element name="students" type="student" minOccurs="0" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType>
0
6175
by: sysmanint1 | last post by:
I am a total neophyte at Visual Basic but found the following post and reply from Clint concerning a dynamic range. Also, have never "posted" to a discussion I have made a macro that works on a template spreadsheet with a fixed number of columns to be "macro'd" bounded by data that changes in its number of rows. That is, the bounding...
19
107886
Frinavale
by: Frinavale | last post by:
Filtering user input is extremely important for web programming. If input is left unfiltered users can input malicious code that can cripple your website. This article will explain how to make sure that the user only submits a number to your .NET web application and also demonstrate how to add JavaScript to your ASPX pages. Upon popular...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.