944,044 Members | Top Members by Rank

Ad:
Aug 21st, 2006
0

Runtime Error 5 - Need help please

Expand Post »
Hi

I have a procedure which I have pasted below. I am using the VBe Enterprise environment and all test machines are Windows XP Pro SP2 with the latest hotfixes. On my machine (the one with the dev env) I have no issues running the application I have written. The machine is a Sony Vaio.

I have tested it on a Dell Dimension 3100 and it runs there also.

When I try it on another Sony Vaio and also on a couple of other laptops, all of the same XP PRo SP2, I get Error #5.

The line in question is:


470 BigString$ = Left(BigString$, Len(BigString$) - 1)


It is always this line. If I move it the error moves.

The routine essentially scans through a INF file and retrieves drivers that are used on the PC.

I have read elsewhere in newsgroups that adding DoEvents solves this. But not for me. I have also tried altering the line to use MID, but that also does not work.

Can someone please help, as I cannot move to .Net due to the fact that users will be foced to install .NET framework just for this app and a lot of them refuse as it is a live network.


Function ReadINF(fname As String, InfSec As String)

' !!!!!!!!!!!!! REMEMBER TO PASS INF SECTION VALUE

Dim LineFromFile$, cfSTR$, cfPOS As Variant, cfTRIM$
Dim INF$() ' Load the INF File into this array
Dim cfCOMPS$() 'define cf components array
Dim CompFiles$() ' This is the array that will hold the actual file names
Dim cnt, cnt2
Dim j As Variant, i As Variant, k As Variant, L As Variant, M As Variant
Dim InfSecPos As String, ktemp As String
Dim foundFlag As Boolean, FirstTimeFind As Boolean
Dim BigString$ ' Used to make up a delimited String to populate an array to avoid ERR 9
Dim eqPOS ' Position of Equals sign in CopyFiles String
Dim LBoundOfArray, UBoundOfArray, ArrayCounter

10 On Error GoTo ReadINF_Error

20 foundFlag = False
30 FirstTimeFind = False

' Attach the []
40 InfSec = "[" + InfSec + "]"

' Set up the filesystem object
50 fname = Environ$("WINDIR") + "\inf\" + fname
60 Set fs = CreateObject("Scripting.FileSystemObject")
70 Set A = fs.OpenTextFile(fname, 1, 0)

' Read the inf file in and start process of query
80 cnt = 1
90 While Not A.AtEndOfStream
100 ReDim Preserve INF(cnt) As String
110 INF(cnt) = A.ReadLine
120 cnt = cnt + 1
130 DoEvents
140 Wend
150 A.Close

' First find the section
160 cfSTR$ = ""
170 For Each j In INF
180 If (InStr(1, j, InfSec, 1) = 1) And (foundFlag = False) Then foundFlag = True
190 If (foundFlag = True) And j = "" Then GoTo FoundEndOfSection
200 If (foundFlag = True) And (Mid(j, 1, 9) = "CopyFiles") Then
210 cfSTR = j
220 GoTo FoundEndOfSection
230 End If
240 Next

FoundEndOfSection:

' Trim the "CopyFiles = " away
250 eqPOS = InStr(1, cfSTR, "=", vbTextCompare)

260 cfTRIM$ = Mid$(cfSTR, eqPOS + 1)

'Parse cfSTR into the individual components
270 cfCOMPS$() = Split(cfTRIM$, ",", -1)

' ******************************************************

' Now find each section at a time and copy the files
280 foundFlag = False
290 cnt2 = 1
300 For Each k In cfCOMPS
310 BigString$ = ""
320 ktemp = k
330 ktemp = Mid(ktemp, 2)
340 InfSec = "[" + ktemp + "]"
350 LBoundOfArray = LBound(INF)
360 UBoundOfArray = UBound(INF)
370 ArrayCounter = 0
380 For Each L In INF
' Form1.Print (L)
390 If (InStr(1, L, InfSec, 1) = 1) And (foundFlag = False) Then foundFlag = True
400 If (foundFlag = True) And L = "" Then Exit For
410 If (foundFlag = True) And L <> "" Then
420 If L <> InfSec Then
430 BigString$ = BigString$ + L + ","
440 End If
450 End If
460 Next
' Finished scanning that aection - now remove trailing comma
470 BigString$ = Left(BigString$, Len(BigString$) - 1)

480 If foundFlag = True Then
490 DoEvents
' BigString$ = Mid(BigString$, 1, Len(BigString) - 1)
500 foundFlag = False
' Now pass BigString$ to the FileCopier.
' Form1.Print (BigString$)
510 CopyDrivers regroot$, BigString$
520 End If
530 Next

540 On Error GoTo 0
550 Exit Function

ReadINF_Error:

560 MsgBox "Error " & Err.Number & " at line:" & Erl & vbCrLf & " (" & Err.Description & ") in procedure ReadINF of Form Form1"


End Function



In Anticipation

Jay
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jsavoor is offline Offline
2 posts
since Aug 2006
Aug 21st, 2006
0

Re: Runtime Error 5 - Need help please

Hi,

You havent done a check to see if BigString contains anything in it.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. lenBigString = len(BigString)
  2. if lenBigString <=1 then
  3. msgbox "Invalid String"
  4. end if

pG
Last edited by Comatose; Aug 21st, 2006 at 9:49 am.
Reputation Points: 24
Solved Threads: 6
Junior Poster in Training
purplegerbil is offline Offline
78 posts
since Apr 2005
Aug 21st, 2006
0

Re: Runtime Error 5 - Need help please

PG's Right. You should test if the string is empty (or how long the string actually is) before trying to get the left value from it....
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Aug 21st, 2006
0

Re: Runtime Error 5 - Need help please

The problem is not that I feel. The way that the previous area of the code works ensures that BIGSTRIN$ has always got the list of filenames seperated by commas. The reason for the LEFT was to remove the trailing comma.

380 For Each L In INF
' Form1.Print (L)
390 If (InStr(1, L, InfSec, 1) = 1) And (foundFlag = False) Then foundFlag = True
400 If (foundFlag = True) And L = "" Then Exit For
410 If (foundFlag = True) And L <> "" Then
420 If L <> InfSec Then
430 BigString$ = BigString$ + L + ","
440 End If
450 End If
460 Next


I have since removed this line altogether and put checking for a blank entry in the array when I split BIGSTRING$.

The issue therefore is something else.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jsavoor is offline Offline
2 posts
since Aug 2006
Aug 21st, 2006
0

Re: Runtime Error 5 - Need help please

Its a strange one this. I cannot recreate the error on my pc.

what about
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. lenBigString = len(BigString)-1
  2. BigString = Left(BigString, lenBigString)


have you got BigString defined?




pG
Reputation Points: 24
Solved Threads: 6
Junior Poster in Training
purplegerbil is offline Offline
78 posts
since Apr 2005
Aug 21st, 2006
0

Re: Runtime Error 5 - Need help please

The problem with the line (470) is without a doubt, the fact that the length is equal to 0 in the left function. Check this:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 'BigString$ = Left(BigString$, Len(BigString$) - 1)
  2. BigString$ = Left(BigString$, Len(BigString$))
I removed the -1 (since the length of bigstring$ was 0) and the left function didn't flip out. It flips out (and returns an invalid procedure call or argument) when left is being called with a negative value. The second argument (parameter) to left, MUST BE a positive value (or 0, which I suppose is also positive). Check the length of bigstring$ first, such as:
if len(bigstring$) < 0 then if you are having problems after removing that line, then there is more than 1 problem in the code, and I'm guessing it has to do with the length of bigstring$ being less than 0 also....
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Dial-up a connection through modem using VB6
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Javascript/VBScript within VB6 application





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC