Results 1 to 5 of 5

Thread: Argh...Array Problems

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    29

    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

  2. #2
    Member
    Join Date
    Mar 2007
    Posts
    46

    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.


  3. #3
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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?

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    29

    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 :-)

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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
  •  



Click Here to Expand Forum to Full Width