If you want to produce good quality code in VBA do the following:
- Option Explicit (From the start!)
- NO ERROR CONTROL! (Do not use error control to avoid making things correctly..)
- Goto is banned.
If you follow these simple instructions you've already got a fairly good standard of code.. then just write.. optimize... test... write... optimize...
Look at this:
Open sz For Input As #7
ERRLINS = 0
THISLIN$ = "**END**"
On Error Resume Next
Line Input #7, THISLIN$
If THISLIN$ = "**END**" Then Exit Do
If THISLIN$ <> "" Then
ERRLINS = ERRLINS + 1
If ERRLINS > 0 Then IMPERR$ = " (Import errors: " & ERRLINS & ")"
Label1 = "Status: IDLE (" & ListView1.ListItems.Count & " ranges)" & IMPERR$
Some of the variables where defined.. but worse is the use of error control to handle the EOF! Here is how it SHOULD have been done:
Dim FreeStream%, THISLIN$
FreeStream = FreeFile
Open sz For Input As FreeStream
Do while NOT EOF(FreeStream)
Line Input #FreeStream, THISLIN$
If NOT THISLIN = "" Then
Label1.caption = "Status: IDLE (" & ListView1.ListItems.Count & " ranges)"