Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 688

Contents of an arrayList persist through all attempts to dump. WHY?

$
0
0
For context, I'm running this code as a macro on an AS400 terminal.
Offending line in red.

Entire For Each loop runs through lines in a .txt file and grabs each one parsing it out into the vars seen below, name/carrer/code etc.
For each of these 'NAMES' that we are looking for on the screen, grab the order# associated and add that to an array. Send that array to be processed (All works fine)
Each iteration needs to clear out the arrayList so it can repopulated on the next go through. Line near the bottom (in red) is the line that refuses to work. I've tested this process separately and it works as intended. Example at bottom of post.

Thoughts, anyone??

Code:

For Each rule In rulesByLine
        autECLSession.autECLOIA.WaitForAppAvailable
        autECLSession.autECLOIA.WaitForInputReady
        autECLSession.autECLPS.autECLFieldList.Refresh
        splitRule = split(rule)
                name = Replace(splitRule(0), "_", " ")
                curCarrier = Replace(splitRule(1), "_", " ")
                newCARC = splitRule(2)
                newSERV        = splitRule(3)
                If Debug = true Then MsgBox("name = "&name&Chr(13)&"curCarrier = "&curCarrier&Chr(13)&"newCARC = "&newCARC&Chr(13)&"newSERV = "&newSERV&Chr(13))
               
                '--- Initializes, or reinitializes ordersToChange as an array list, needs to be empty each cycle.
                Set ordersToChange = CreateObject("System.Collections.ArrayList")

               
       
        Do While isNextPage = true
                If Debug = true Then MsgBox("isNextPage is True")
                autECLSession.autECLOIA.WaitForAppAvailable
                autECLSession.autECLOIA.WaitForInputReady
                autECLSession.autECLPS.autECLFieldList.Refresh
                If Debug = true Then MsgBox("FieldList Refreshed")
               
                Set nameToFind = autECLSession.autECLPS.autECLFieldList.FindFieldByText(name, 1, 1, 1)
                If nameToFind Is Nothing Then
                        If Debug = true Then MsgBox("nameToFind was NOTHING")
                        autECLSession.autECLPS.SendKeys "[roll up]"
                Else
                        If Debug = true Then MsgBox("nameToFind was "& nameToFind.GetText)
                        Do While Not nameToFind Is Nothing
                                If Debug = true Then MsgBox("nameToFind was NOT Nothing: Found At "&nameToFind.StartRow&", "&nameToFind.StartCol)
                                If inStr(autECLSession.autECLPS.autECLFieldList.FindFieldByRowCol(nameToFind.StartRow, 46).GetText, curCarrier) Then
                                        If Debug = true Then MsgBox("curCarrier Matched rule")
                                        '--- This is where numbers are added to the array only if they're found on screen (Works as designed) 
                                        ordersToChange.Add autECLSession.autECLPS.GetText(nameToFind.StartRow, 6, 10)

                                End If
                               
                                Set nameToFind = autECLSession.autECLPS.autECLFieldList.FindFieldByText(name, 1, nameToFind.EndRow, nameToFind.EndCol)
                        Loop
                        autECLSession.autECLPS.SendKeys "[roll up]"
                End If
        Loop
       
        Dim text
        If ordersToChange.Count > 0 Then
                If Debug2 = true Then
                        For Each order in ordersToChange
                                text = text & order & Chr(13)
                        Next
                        MsgBox(text)
                End If
                changeCarrier ordersToChange, newCARC, newSERV                '--- If there is a list, sends list to cycle through each thing in the list and do stuff with it (All works as intended)
                Set ordersToChange = nothing                        '--- This is supposed to reset the list, ordersToChange.Clear won't work either. Instead, on the next go-around(s) it just adds more numbers to the array as if this line didn't exist..

                autECLSession.autECLOIA.WaitForAppAvailable
                autECLSession.autECLOIA.WaitForInputReady
                navigateTo "OR3"          '--- I know this whole statement is being run properly as this command does what it's supposed to do. If it didn't, the whole thing would break after changeCarrier is called. changeCarrier is being called correctly during testing so I know this section of code is being called.
        End If
        autECLSession.autECLPS.SendKeys "[pf5]"
Next

Below was the test I ran to make sure this concept works and this worked exactly as designed. Set the array to nothing after having proved index 0 had text, and show the new text at the same index.
If this works, why won't it work in the above code? My debug MsgBox does call and shows me exactly what's in the array and after finishing one round and moving on to another the array still has the original contents even after Set array = nothing is done...

Code:

Dim arrayName

Set arrayName = CreateObject("System.Collections.ArrayList")
arrayName.Add "This is just some text"

MsgBox(arrayName(0))

Set arrayName = nothing
Set arrayName = CreateObject("System.Collections.ArrayList")

arrayName.Add "This is now the new text"

MsgBox(arrayName(0))

I tried something. Better question.. Why are the 2 outputs of this code what you see below??
Attachment 193954Attachment 193955
I'm starting to think there's something fundamentally wrong with the arrayList objects themselves.
by using .Clear and setting it to 'nothing' one of those should have worked to empty out the array to allow the second .Add to populate it with a single line. The second output should be showing only one line "This is now the new text".. But it shows both lines of text even though I've 'DUMPED' the arrayList.. What is going on here?

Code:

Dim arrayName, order, text

Set arrayName = CreateObject("System.Collections.ArrayList")
arrayName.Add "This is just some text"

For Each order in arrayName
        text = text & order & Chr(13)
Next
MsgBox(text)

arrayName.Clear
Set arrayName = nothing
Set arrayName = CreateObject("System.Collections.ArrayList")

arrayName.Add "This is now the new text"

For Each order in arrayName
        text = text & order & Chr(13)
Next
MsgBox(text)


Viewing all articles
Browse latest Browse all 688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>