|
-
Apr 30th, 2007, 04:54 PM
#1
Thread Starter
Junior Member
Argh...Array Problems
Hi everyone, I'm new to the forums, and VB explorer didn't answer the question I have so now I'm here :-P
I have 3 arrays that are declared as such:
Code:
Dim marray() As Variant
Dim resArray() As String
Dim errText() As String
Then on Form Load it has this:
Code:
ReDim marray(1 To mcnt) As Variant
ReDim resArray(1 To mcnt) As String
ReDim errText(1 To mcnt) As String
marray works fine, all the for loops I have through the program it saves the data just fine. But the other two I'm having massive problems. They don't seem to save any data.
Code:
Private Sub RunTest_Click()
'Test all the machines on the network and tabulate results'
For i = 1 To mcnt
rMachine = marray(i)
rescnt = i
errtxtcnt = i
Call StartTest(rescnt, errtxtcnt, rMachine, lUsername, i)
Next
'Analyze all the data next.'
Call Finish
End Sub
Private Sub StartTest(ByRef rescnt As Integer, ByRef errtxtcnt As Integer, ByRef rMachine As String, ByRef lUsername As String, ByRef i As Integer)
....
If ErrorStatus = 1 Then
Call NetErrorHandling(rescnt, errtxtcnt, rMachine, lUsername, i, ErrorCode)
End If
testFile = FreeFile
Open "C:\SystemReq\testfile.txt" For Output As #testFile
Print #testFile, "Test Stuff"
Close #testFile
iFile4 = FreeFile
Open "C:\SystemReq\copyfile.bat" For Output As #iFile4
Print #iFile4, "cd\systemreq"
Print #iFile4, "copy testfile.txt \\" & rMachine & "\C$ /Y > copyfileresult1.txt"
Print #iFile4, "copy testfile.txt \\" & rMachine & "\C$ /Y 2> copyfileresult2.txt"
Close #iFile4
ret2 = ShellAndWait("C:\systemreq\copyfile.bat", vbHide)
iFile5 = FreeFile
Open "C:\SystemReq\copyfileresult1.txt" For Input As #iFile5
Do While Not EOF(iFile5)
Line Input #iFile5, temp3Text
TextData = temp3Text
If (InStr(1, TextData, "0 File", 1) = 8) Then
resArray(rescnt) = "F"
errText(errtxtcnt) = "Copy Failed"
Exit Do
End If
If (InStr(1, TextData, "1 File", 1) = 8) Then
resArray(errtxtcnt) = "P"
errText(rescnt) = "No error!"
Exit Do
End If
Loop
Close #iFile5
Then I have MsgBoxes in the Finish function like this
Code:
For x=1 to mcnt
MsgBox (marray(x))
MsgBox (resArray(x))
MsgBox (errText(x))
Next
Marray(x) shows up fine for each value of x but resArray and errText are blank. I can't figure it out, I'd be much obliged for any help...
Or check out my full project at:
http://www.tammuz.us/vb/SystemReq.zip
-
May 1st, 2007, 02:06 AM
#2
Member
Re: Argh...Array Problems
I suspect these lines:
Code:
If (InStr(1, TextData, "0 File", 1) = 8) Then
and
Code:
If (InStr(1, TextData, "1 File", 1) = 8) Then
Put a breakpoint in the code and step through it - you can hover over variables and their contents will be displayed.
-
May 1st, 2007, 02:07 AM
#3
Re: Argh...Array Problems
you need to step through your loop and check everything is working as you'd expect. - my first question would be:
Are "0 File" and "1 File" in the lines and are they definitely at position 8?
-
May 1st, 2007, 12:58 PM
#4
Thread Starter
Junior Member
Re: Argh...Array Problems
So I double checked everything in the loops and found out that I was indeed grabbing the wrong number...doh! So this is fixed now, thanks so much guys :-)
-
May 1st, 2007, 05:17 PM
#5
Re: Argh...Array Problems
Welcome to the VBForums. We have a tradition here, when you've got your question answered please pull down the "Thread Tools" menu, just above your first post and select "Mark thread resolved". This will help everyone browsing the forum.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|