VB6 application throwing an error when loading ini file

Status
Not open for further replies.
I'm dealing with a 10 year old production machine at work that runs on an old Beckhoff CX. Runs XP, a simple HMI monitors a hand scanner, when a barcode is scanned the HMI goes to a network folder and loads a corresponding .ini file. At times, this occurs:

LZn4Q.png


The .ini files exist, aren't corrupt, and contain ~10 lines that determine test conditions on the PLC.

Here is the relevant portion of the code:

(example .ini file)

Code:
Pnum=905-3166
Tape= True
Foam= True
Diffuser = False
Mask= False
camera_product=S891G3775601
Clip_Fixture=CF016
ElementFixture=EF005
top_wire_color=N/A
bottom_wire_color=N/A

Code:
Public Sub Read905(l$)

 On Local Error GoTo readerror
 fn$ = l$
 
 While InStr(l$, "\")
  locs = InStr(l$, "\")
  l$ = Mid$(l$, locs + 1)
 Wend
 locs = InStr(l$, ".")
 l$ = Left$(l$, locs - 1)
  
 'build path to ini file
 If InStr(l$, "\") = 0 Then fn$ = "\\Server\PartNumbers\" + l$
 If InStr(l$, ".") = 0 Then fn$ = fn$ + ".ini"
 PN$ = l$
 
 Open fn$ For Input As #1
 While Not EOF(1)
  Line Input #1, l$
  Linenum = Linenum + 1
  locc = InStr(l$, "'")
  If locc = 1 Then                              'If line is commented out, skip
    FieldName = "skip"
  ElseIf locc Then                              'else just trim off comment
    l$ = Left$(l$, locc - 1)
    l$ = LTrim$(RTrim(l$))
    loce = InStr(l$, "=")
    FieldName = RTrim$(Left$(l$, loce - 1))
    FieldValue$ = LTrim$(Mid$(l$, loce + 1))
  Else                                          'No comment
    loce = InStr(l$, "=")
    FieldName = RTrim$(Left$(l$, loce - 1))
    FieldValue$ = LTrim$(Mid$(l$, loce + 1))
  End If
  Select Case LCase$(FieldName)
  Case LCase("pnum")
     Pnum$ = FieldValue$
     cmdPNum.Caption = Pnum$
   Case LCase("tape")
     Tape$ = FieldValue$
   Case LCase("foam")
     Foam$ = FieldValue$
   Case LCase("diffuser")
     Diffuser$ = FieldValue$
   Case LCase("mask")
     Mask$ = FieldValue$
   Case LCase("camera_product")
     CamProd$ = FieldValue$
   Case LCase("clip_fixture")
     ClipFixture$ = FieldValue$
     txtClipFixture.Text = ClipFixture$
   Case LCase("elementfixture")
     ElementFixture$ = FieldValue$
     txtElementFixture.Text = ElementFixture$
   Case "skip"                               'for those lines commented out(first char = "'")
   Case Else
     GoTo badfile
  End Select
    
 Wend
 Close #1
 If LCase(Tape$) = "true" Then
    lblTape.Visible = True
 Else
    lblTape.Visible = False
 End If
  If LCase(Foam$) = "true" Then
    lblFoam.Visible = True
 Else
    lblFoam.Visible = False
 End If
  If LCase(Mask$) = "true" Then
    lblMask.Visible = True
 Else
    lblMask.Visible = False
 End If
  If LCase(Diffuser$) = "true" Then
    lblDiffuser.Visible = True
 Else
    lblDiffuser.Visible = False
 End If
 
 If cameraIP <> "" Then
    camera.SendProductSelectByName CamProd$
 End If
 
 If Tape$ = "" And Foam$ = "" And Diffuser$ = "" And Mask$ = "" Then
    PLC.AdsSyncWriteBoolVarReq H(3), 1, TrueVar
    frmFPD.BackColor = vbRed
    lblBypassed.Visible = True
 Else
    PLC.AdsSyncWriteBoolVarReq H(3), 1, FalseVar
    frmFPD.BackColor = &HE9EBED
    lblBypassed.Visible = False
 End If
Exit Sub
readerror:
 MsgBox "Error reading file: " + Err.Description
 Resume badfile
badfile:
 MsgBox "Error reading test description file: '" + fn$ + "' on line number" + Str$(Linenum)
  Close #1
End Sub

I am not a code guru myself but am required to fix the problem when it arises (restarting the OS is the only fix ATM). So I turn to the experts...what are your thoughts? How do I prevent this from happening? Any advice is much appreciated!
 
Only the values below are "legal" in that code.
Code:
pnum
tape
foam
diffuser
mask
camera_product
clip_fixture
elementfixture
The values 'top_wire_color' and 'bottom_wire_color' are not legal.

To fix the code, add a case for all values - even if they just skip them, or just skip any unknown values in the "Case else" clause.

---

My consultant bill: 5 dollars.
 
Status
Not open for further replies.