Results 1 to 4 of 4

Thread: Code Review

  1. #1

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    I am reading in lines from a comma seperated text file and then validating the information against a database. I do a lot of validate steps before I actually update any values in the database row.

    Now for the question. Is there a way to goto the bottom of the loop without using a a goto statement or should I used the nested ifs as I have already done.

    In Case 1 is where things get nested pretty good.

    Thanks for any input!
    Code:
        Do While Not EOF(AttrFile)  'Loop until end of file.
            Line Input #AttrFile, TempString
            
            'If there is a blank row in the data file bypass it
            'and go on to the next row.
            If TempString <> "" Then
                
                AttrValues = Split(TempString, AttrDelim)
                
                ' If the are there more then 1 object with this
                ' name in the database then we cannot process
                ' it.  Report back to the error log
    
                Select Case CountObjectsNamed(Session, AttrValues(0))
                    Case 0
                        ErrorMessage = "Not able to update " & AttrValues(0) & _
                                       " because no object was found with this name."
                        PrintErrorMessage (ErrorMessage)
                        
                    Case 1
                        ObjectID = GetObjectId(Session, AttrValues(0))
    
                        ' Here is what I want but I am forced
                        ' to used a nested if.
                        ' If ObjectID = "" Then goto the end of
                        ' the loop
    
                        If ObjectID <> "" Then
                        
                            Set TempObject = New DObject
                            
                            With TempObject
                                .ID = ObjectID
                                .Session = SessionID
                            End With
    
                            ' Here is what I want
                            ' If TempObject.LockOwner <> ""
                            ' Then goto the end of the loop
    
                            If TempObject.LockOwner = "" Then
                        
                                For i = 2 To UBound(AttrNames)
                                    ' Start processing attributes
                                Next i
                            
                                MaxObjectsFound = MaxObjectsFound + 1
                                
                                TempInteger = dmAPIExec("flushcache," & Session)
                            
                            End If
                        
                        End If
                    
                    Case Else
                        ErrorMessage = "Not able to update " & AttrValues(0) 
                        PrintErrorMessage (ErrorMessage)
                        
                End Select
            End If
        Loop
    This space for rent...

  2. #2

  3. #3
    Addicted Member
    Join Date
    Jul 2000
    Location
    Scotland
    Posts
    184
    Could you not simply "Exit Do" If TempObject.LockOwner <> "" ?

    Or set a blnFlag to True If TempObject.LockOwner <> "" and use AND in the Do While to check it?


    If you want to stay in the Loop, perhaps raise a user defined error, trap it and resume where you want.

  4. #4

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    Originally posted by Steven McGarva
    Or set a blnFlag to True If TempObject.LockOwner <> "" and use AND in the Do While to check it?


    If you want to stay in the Loop, perhaps raise a user defined error, trap it and resume where you want.
    I will probably set a flag up. Thanks
    This space for rent...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width