473,406 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

infinite loops

atksamy
91
Heré is the code I am working on. I am using this to validate the values of tables in a database.
i am almost done but i have a infinite loop goin towards the end loop s not ending and the program is runnin over and over again

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Sub UpdateNulls()
  4.   Dim rs As DAO.Recordset
  5.   Dim rs2 As DAO.Recordset
  6.   Dim rs3 As DAO.Recordset
  7.   Dim tdf As DAO.TableDef
  8.   Dim db As Database
  9.   Dim varii As Variant, strField As String
  10.   Dim strsql As String, strsql2 As String, strsql3 As String
  11.   Dim astrFields As Variant
  12.   Dim intIx As Integer
  13.   Dim field As Variant
  14.   Dim astrvalidcodes As Variant
  15.   Dim found As Boolean
  16.   Dim v As Variant
  17.  
  18.  
  19.   Open "C:\Documents and Settings\TAYYAPP\Desktop\testfile.txt" For Input As #1
  20.   varii = ""
  21.   Do While Not EOF(1)
  22.     Line Input #1, strField
  23.     varii = varii & "," & strField
  24.   Loop
  25.   Close #1
  26.   astrFields = Split(varii, ",")  'Element 0 empty
  27.  
  28.  
  29.   'OPEN WORD DOCUMENT FOR WRITING REPORT
  30.  
  31.                      Dim objWord As Word.Application
  32.                      Dim docWord As Word.Document
  33.                      Dim docExists As Boolean
  34.                      Set objWord = CreateObject("Word.Application")
  35.                      objWord.Visible = True
  36.                      On Error GoTo OpenDoc
  37.                      docExists = False
  38.                      Set docWord = objWord.Documents.Open("C:\Documents and Settings\TAYYAPP\Desktop\test folder\ERROR REPORT1.doc")
  39.                      docExists = True
  40. OpenDoc:
  41.  
  42.                      On Error GoTo 0
  43.                      If Not docExists Then
  44.                      Set docWord = objWord.Documents.Add
  45.                      End If
  46.  
  47.  
  48.  
  49.     For Each tdf In CurrentDb.TableDefs
  50.     If Left(tdf.Name, 4) <> "MSys" Then
  51.     strsql = "Select t.* From [" & tdf.Name & "] t Inner Join 01UMWELT On t.fall = [01UMWELT].fall Where [01UMWELT].Status = 4"
  52.  
  53.     Set rs = CurrentDb.OpenRecordset(strsql)
  54.  
  55.     Do While Not rs.EOF
  56.         For intIx = 1 To UBound(astrFields)
  57.  
  58.          strsql2 = "SELECT label.validcode FROM variablen s INNER JOIN label ON s.id=label.variablenid WHERE varname='" & astrFields(intIx) & "'"
  59.          strsql3 = "SELECT s.[" & astrFields(intIx) & "], s.fall from [" & tdf.Name & "] s Inner Join 01UMWELT on s.fall = [01UMWELT].fall Where [01UMWELT].Status = 4"
  60.  
  61.             Set db = OpenDatabase("C:\Documents and Settings\TAYYAPP\Desktop\GIDAS_Codebook.mdb")
  62.             Set rs2 = db.OpenRecordset(strsql2)
  63.  
  64.                 With rs2
  65.                 .MoveLast
  66.                 .MoveFirst
  67.                  astrvalidcodes = rs2.GetRows(.RecordCount)
  68.                 .Close ' assuming you want to do this
  69.                 End With
  70.  
  71.             Set rs3 = CurrentDb.OpenRecordset(strsql3)
  72.  
  73.                 With rs
  74.                     On Error Resume Next   'Ignore field if table doesn't have it
  75.                     Call Err.Clear
  76.                      If Err.Number <> 3265 Then          ' Field not found in table
  77.  
  78.                     With rs3
  79.                     While Not rs3.EOF
  80.                         found = False
  81.                         For Each v In astrvalidcodes
  82.                         If v = .Fields(0) Then
  83.                         found = True
  84.                         Debug.Print .Fields(0)
  85.                         Debug.Print .Fields(1)
  86.                         Exit For
  87.                         End If
  88.                         Next
  89.                     If Not found Then
  90.                     If tdf.Name <> "01umwelt" Then
  91.  
  92.                     docWord.Content.InsertAfter "Variable     " & astrFields(intIx) & "     " & "in   record" & "     " & .Fields(1) & "    contains invalid  value  not  prescribed  in  code  book "
  93.                     docWord.Content.InsertParagraphAfter
  94.  
  95.                     End If
  96.                     End If
  97.                     .MoveNext
  98.  
  99.  
  100.                     Wend
  101.                     End With
  102.                     End If
  103.  
  104.  
  105.                On Error GoTo 0        'End of special handling
  106.           End With
  107.         Next intIx
  108.         rs.MoveNext
  109.       Loop
  110.     End If
  111.   Next
  112.  
  113.  
  114.   objWord.Visible = True
  115.   docWord.Content.InsertParagraphAfter
  116.   docWord.SaveAs ("C:\Documents and Settings\TAYYAPP\Desktop\test folder\ERROR REPORT2.doc")
  117. End Sub
  118.  
  119.  
Nov 7 '08 #1
3 2118
Stewart Ross
2,545 Expert Mod 2GB
We can't debug more than 100 lines of code for you - it is unreasonable to expect us to do so without any indication of what you have done to restrict the range of your problem and debug for yourself.

At a glance, your indentation of the FOR loops, WHILE loops and IF statements is incorrect throughout and is actively misleading to you about where one loop begins and the next ends. You should go back through your code and re-indent every part consistently.

When you have done that, you should set a breakpoint and step through your code line by line, checking the values of all local variables set and cleared within your loops. Systematic working is needed here, as well as systematic logic.

-Stewart
Nov 7 '08 #2
atksamy
91
I have started debugging and have removed the do while loop at line 55.

now when control goes to next table at line 71 i get an runtime error 3061.I know i am getting this because the sql cannot be executed as teh field is not present in the table. I want to ignore this error and goto next table

how do i ignore this error
Nov 7 '08 #3
Stewart Ross
2,545 Expert Mod 2GB
To ignore errors in the short term use
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
You have a number of On Error statements in your code; comment them out temporarily and use a single On Error Resume Next placed after the DIM statements.

-Stewart
Nov 7 '08 #4

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

Similar topics

43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
8
by: bob | last post by:
periodically, my program seems to get stuck in an infinite loop. i have a lot of loops though, so i don't know which one. any ideas how to find out? i'm using dev-cpp. i think having the...
7
by: Andrej Hocevar | last post by:
Hello, what is the best way of solving cases where one has to wait (forever, until killed or instructed otherwise) for some event to occur? E.g., wait for data, monitoring a file? In fact, that...
2
by: psg | last post by:
Hello! I am developing Windows application which after sending a request to a server will listen to response, a response will be infinite in length, but will not be continuous in time. What I...
59
by: rami | last post by:
please everybody ,can anyone tell me how to do an infinite loop in C
13
by: Vector | last post by:
Is any infinite loop better than other? Is there any difference between there efficiency?
10
by: Steven Woody | last post by:
i have a program which always run dead after one or two days, i think somewhere a piece of the code is suspicious of involving into a infinite loop. but for some reason, it is very hard to debug....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...
0
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...

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.