Results 1 to 7 of 7

Thread: Spot the error

  1. #1
    Join Date
    Aug 2002
    Posts
    6,223
    Rep Power
    0

    Default Spot the error

    Here's some actual VB6 code. Can you spot the error that will cause the program to malfunction?
    The premise here: There are five locations, but the data is stored both in remote computers (locations 0-5) or on the local hard drive (6-11). Check_Stores contains the code to run on the data and is not part of the problem

    Code:
    Private Sub cmdStart_Click()
    
    StatusBar1.Panels(1).Text = "Please wait....."
    On Error GoTo ErrorHandler
    
    StartNumber = 0 ' 1'st Number (0 or 6)
    EndNumber = 5 ' 6th Item (Last Item 5 or 11)
    LocationNumber = 0 ' Location Index (0-5)
    optIndex = 0 ' Indicates location and whether remote (0-5) or local (6-11)
    
    If chkAllStores.Value = Checked Then ' Do All Stores
        If chkLocal.Value = Checked Then  ' Use local files
            StartNumber = StartNumber + 6
            EndNumber = EndNumber + 6
        End If
        For optIndex = StartNumber To EndNumber
            Option1(LocationNumber).Value = True
            Call Check_Stores
            LocationNumber = LocationNumber + 1
        Next optIndex
    
    Else 'Single Location
        If chkLocal.Value = Checked Then optIndex = optIndex + 6 ' Use local files
        Call Check_Stores
    End If
    
    ErrorHandler:
    Select Case Err.Number
        Case 0
            ' Do Nothing
        Case 20
            ' Do Nothing
        Case Else
            MsgBox (Err.Number & "  " & Err.Description)
            Err.Clear
    End Select
    Resume Next
    
    End Sub
    .
    PC - Ubuntu 15.04 64bit Desktop
    HP Pav G60-236US 3GB RAM Laptop, Ubuntu 15.04 64bit and Win7 Home

    "So Daddy, how come you telling me stealing not right when YOU copying DVDs? How come? How Come?"


    RIP Ramesh ...

  2. #2
    Join Date
    Aug 2002
    Posts
    6,223
    Rep Power
    0

    Default

    The error is in this line:
    Code:
    optIndex = 0 ' Indicates location and whether remote (0-5) or local (6-11)
    The optIndex variable does not need to be initialised as zero, as it is needed to identify the location chosen in the case of the single location.
    In the case of the multiple location call to Check_Stores optIndex will be incremented from StartNumber to EndNumber.

    Thanks to all who participated.

    Yes, I know I'm being sarcastic.....
    .
    PC - Ubuntu 15.04 64bit Desktop
    HP Pav G60-236US 3GB RAM Laptop, Ubuntu 15.04 64bit and Win7 Home

    "So Daddy, how come you telling me stealing not right when YOU copying DVDs? How come? How Come?"


    RIP Ramesh ...

  3. #3
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    Quote Originally Posted by ramesh View Post
    The error is in this line:
    Code:
    optIndex = 0 ' Indicates location and whether remote (0-5) or local (6-11)
    The optIndex variable does not need to be initialised as zero, as it is needed to identify the location chosen in the case of the single location.
    In the case of the multiple location call to Check_Stores optIndex will be incremented from StartNumber to EndNumber.

    Thanks to all who participated.

    Yes, I know I'm being sarcastic.....
    It does not "need" to be initialized but I don't see where it would prevent the program from running.

    For the multiple location, the optIndex will start at StartNumber and be incremented.
    For the single location, it will add 6 to the number.

    In both situations, if the value of optIndex is 0, it won't prevent the program from executing.

    I looked the code over and over and couldn't see a problem with it, so I didn't respond.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  4. #4
    Join Date
    Aug 2002
    Posts
    6,223
    Rep Power
    0

    Default

    Point taken AA, but even if the program continued running it can still malfunction.

    My boss considered it an epic fail when it didn't deliver the expected results. He'll remember that more than when I corrected the problem code and it actually gave proper results.
    .
    PC - Ubuntu 15.04 64bit Desktop
    HP Pav G60-236US 3GB RAM Laptop, Ubuntu 15.04 64bit and Win7 Home

    "So Daddy, how come you telling me stealing not right when YOU copying DVDs? How come? How Come?"


    RIP Ramesh ...

  5. #5
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    Quote Originally Posted by ramesh View Post
    Point taken AA, but even if the program continued running it can still malfunction.
    Malfunction how? Unless you're using the optIndex somewhere else in your code?

    You're saying you removed the code that initialized the optIndex and the code produced the results you were looking for?
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  6. #6
    Join Date
    Aug 2002
    Posts
    6,223
    Rep Power
    0

    Default

    It was not mentioned explicitly, I know, but the optIndex variable was assigned elsewhere. The user would choose the location from a set of six option buttons that are indexed 0-5 in a frame.

    If you read the note beside the incorrect command, it basically implies this.
    Code:
    ' Indicates location and whether remote (0-5) or local (6-11)
    .
    PC - Ubuntu 15.04 64bit Desktop
    HP Pav G60-236US 3GB RAM Laptop, Ubuntu 15.04 64bit and Win7 Home

    "So Daddy, how come you telling me stealing not right when YOU copying DVDs? How come? How Come?"


    RIP Ramesh ...

  7. #7
    Join Date
    Sep 2003
    Posts
    603
    Rep Power
    0

    Default

    There are five locations but the code is looking at 6 indexes (0,1,2,3,4,5 for remote) and (6,7,8,9,10,11 for local).

Posting Permissions

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