Sign in to follow this  
Followers 0
atnextc

FileWrite Loop Issues

34 posts in this topic

#1 ·  Posted (edited)

I have an issue where I'm trying to write a configuration for our routers. I am grabbing all the data needed from our website and declaring all the variables from the parsed html data.

I have a gui that a person will enter the number of projects that they have for each router.  This number of projects will dictate how many times the loop runs to grab all of the data.

The issue comes up when writing the file.

What I would like to happen is something similar to this:

===============================

Lines to only be written 1 time to file:

Lines to be written depend on number of projects:

Back to Only Write Lines below 1 time to file:

 

Lines to be written depend on number of projects:

=================================

 

I can get the number of lines being written the correct number of lines in the correct spot in the file, the issue is that the variable that is being written is the same variable everytime, since I believe its within the same do loop.

Any help would be greatly appreciated.

Below is a sample code written:

Do
$oIE = _IECreate("https://internalsite/?title=" & GUICtrlRead($ProjectNameInputBox) & "&action=edit", 0, 0, 1, 1)
    _IELinkClickByText($oIE, "Continue to this website (not recommended).")
$string = _IEBodyReadHTML($oIE)
$data = $oIE
    _IEQuit($oIE)

$asideinterface = _StringBetween($string, '|AInterface=', @CRLF)
$zsideinterface = _StringBetween($string, '|ZInterface=', @CRLF)

Local $aprojincr = StringRegExp(GUICtrlRead($ProjectNameInputBox), "(?<=-\d{2})([A-Z])(?=-Q)", 3)

        Local $aprojincr = StringRegExp(GUICtrlRead($ProjectNameInputBox), "(?<=-\d{2})([A-Z])(?=-Q)", 3)
        Local $incr_char = Chr(Asc($aprojincr[0]) + 1)
        GUICtrlSetData($ProjectNameInputBox, StringRegExpReplace(GUICtrlRead($ProjectNameInputBox), _
                "(?<=-\d{2})([A-Z])(?=-Q)", $incr_char))



if IsArray($asideinterface) = 1 Then
ReDim $asideinterface[1]
if IsArray($zsideinterface) = 1 Then
ReDim $zsideinterface[1]
EndIf
EndIf


ConsoleWrite("First Line Test"& @CRLF)

If Not GUICtrlRead($NumberofProjects) = 0 Then

Call ("_Test")

EndIf
ConsoleWrite("Last Line Test"& @CRLF)

$i += 1
Until $i = (GUICtrlRead($NumberofProjects))
If $i = $C Then Exit
    EndSwitch

WEnd

Func _Test()
ConsoleWrite($asideinterface[0]& @CRLF)
ConsoleWrite($zsideinterface[0]& @CRLF)
EndFunc

The code above is spitting this out in the Console:

--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
First Line Test
et-0/0/11
xe-3/0/0
Last Line Test
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
First Line Test
et-0/0/13
xe-3/1/0
Last Line Test
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
First Line Test
et-1/0/11
xe-3/0/2
Last Line Test
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
First Line Test
et-1/0/13
xe-3/1/2
Last Line Test

In the above text I only need "first line test" and last line test" to be written one time, and not looping like it currently is.

Below is the output file that is being created on the actual code:  Where the interface is the same, that is supposed to be the next interface that was in the loop.


THIS ONLY NEEDS TO BE WRITTEN ONE TIME

Pre-Snap Shot:

show interface description | no-more
show rsvp interface | no-more
show mpls interface| no-more
show ospf neighbor| no-more
show pim neighbors| no-more
show bgp summary| no-more
show ldp interface| no-more
show ldp session | no-more
show ldp neighbor | no-more
show mpls lsp | match wn
show igmp interface | no-more 
show bfd session summary
show log messages | last 300 

THIS NEEDS TO BE WRITTEN THE NUMBER OF TIMES THAT WE ARE LOOPING.  As you can see the interface "et-0/0/11" is the same all the lines.  I want this to be the next interface that is expected in the loop.

show interface extensive et-0/0/11 | no-more 
show interface diagnostics optics et-0/0/11 | match "Laser output power|Receiver signal average optical power"
show interface extensive et-0/0/11 | no-more 
show interface diagnostics optics et-0/0/11 | match "Laser output power|Receiver signal average optical power"
show interface extensive et-0/0/11 | no-more 
show interface diagnostics optics et-0/0/11 | match "Laser output power|Receiver signal average optical power"
show interface extensive et-0/0/11 | no-more 
show interface diagnostics optics et-0/0/11 | match "Laser output power|Receiver signal average optical power"
Edited by atnextc

Share this post


Link to post
Share on other sites



All of this is contained within a single do loop.  What i'm looking for is a fancy "find and replace" the problem is what i'm trying to replace is changing within the initial "do Until" loop since it's a different project. the variables are being written several times within the initial do loop.

sorry if that didn't make any sense. Trying to think of a good way to word what i'm looking for.

Share this post


Link to post
Share on other sites
0xdefea7 what you suggested is working, but the issues still arises that when my loop is reading through the array and grabbing the data it's not remembering it to be used later in the script. It's only saving the last variable that was pulled in the last loop.

 

 

I've tried everything I can think of to get it to pull all of the data at one time and to get it to be used later on in the script but nothing has worked.

Share this post


Link to post
Share on other sites

Ok after looking into this some more, it appears to me as if I'm having an issue with my "array" since I'm parsing the data using "Stringbetween" which as I understand it creates a 0 based array which is fine in my case since there will only ever be 1 possible piece of information in this field.

So i'm grabbing the data via stringbetween in a loop based on the number of times needed which is inputted by the user.  I believe that my issue is that the array0 is being re-written  with the latest grab and its not retaining the other data that it has pulled.

I've been looking a _ArrayAdd and Ubound but still can't seem to get a grasp on it.  Can anyone explain (hopefully in lamens terms) how I would get this to work?

1. Loop begins

2. I'm pulling data from webpage using _IEBodyReadHTML

3. parsing out the data needed using stringbetween in which case each variable is in theory its own 0 based array

4. Config written with place holders for the variables grabbed above.

Only the last variable is being written to my file and not all the other ones in the loop.

When I do an _ArrayDisplay while in the loop I have verified that it is indeed pulling the information that is wanted.

 

Snippet of code below

Local $array[2]
Local $array1[2]

$array[0] = _StringBetween($string, '|AInterface=', @CRLF)
$array1[0] = _StringBetween($string, '|ZInterface=', @CRLF)

Local $asideinterface = $array[0]
Local $zsideinterface = $array1[0]


For $I = 0 To UBound($array)-1
For $I = 0 To UBound($array1)-1
ConsoleWrite($asideinterface[$I] & @CRLF)
ConsoleWrite($zsideinterface[$I] & @CRLF)
Next
Next

Share this post


Link to post
Share on other sites

Where's the filewrite code?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

i can post it, but this was just a sample...i was trying to keep the code to a minimum, but the consolw write that is emulating the file write is the first sectino of code that I posted in the OP.

Share this post


Link to post
Share on other sites

I can understand keeping the code posted to a minimum, but that minimum must show the problem you're having.

BTW, did you intentionally reuse the variable $I for both loops?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

the variable for $asideinterface and $zsideinterface is only catching the last iteration of it in the loop.  Also $I is the count variable that i'm using to make sure that the number of loops = the number of projects.

Do
$oIE = _IECreate("https://internalsite/?title=" & GUICtrlRead($ProjectNameInputBox) & "&action=edit", 0, 0, 1, 1)
    _IELinkClickByText($oIE, "Continue to this website (not recommended).")
$string = _IEBodyReadHTML($oIE)
$data = $oIE
    _IEQuit($oIE)

$asideinterface = _StringBetween($string, '|AInterface=', @CRLF)
$zsideinterface = _StringBetween($string, '|ZInterface=', @CRLF)

Local $aprojincr = StringRegExp(GUICtrlRead($ProjectNameInputBox), "(?<=-\d{2})([A-Z])(?=-Q)", 3)

        Local $aprojincr = StringRegExp(GUICtrlRead($ProjectNameInputBox), "(?<=-\d{2})([A-Z])(?=-Q)", 3)
        Local $incr_char = Chr(Asc($aprojincr[0]) + 1)
        GUICtrlSetData($ProjectNameInputBox, StringRegExpReplace(GUICtrlRead($ProjectNameInputBox), _
                "(?<=-\d{2})([A-Z])(?=-Q)", $incr_char))



if IsArray($asideinterface) = 1 Then
ReDim $asideinterface[1]
if IsArray($zsideinterface) = 1 Then
ReDim $zsideinterface[1]
EndIf
EndIf


ConsoleWrite("First Line Test"& @CRLF)

If Not GUICtrlRead($NumberofProjects) = 0 Then

Call ("_Test")

EndIf
ConsoleWrite("Last Line Test"& @CRLF)

$i += 1
Until $i = (GUICtrlRead($NumberofProjects))
If $i = $C Then Exit
    EndSwitch

WEnd

Func _Test()
ConsoleWrite($asideinterface[0]& @CRLF)
ConsoleWrite($zsideinterface[0]& @CRLF)
EndFunc

Share this post


Link to post
Share on other sites

That last snippet doesn't run either, and it's different from the code you posted above it. Post runnable code that demonstrates the problem or it will be impossible to help you in any meaningful way.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

; Working "Do Until In Loop" But the items in the array are predefined. Still need to see how to get it to work on the actual script.


#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <IE.au3>
#include <String.au3>



$C4Automation = GUICreate("C4 Automation", 615, 438, 188, 121)
$Label1 = GUICtrlCreateLabel("C4 Automation", 32, 24, 564, 41)
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
$ProjectSiteCombo = GUICtrlCreateCombo("", 184, 104, 145, 25, BitOR($CBS_DROPDOWNLIST, $CBS_SORT))
;$ProjectTypeCombo = GUICtrlCreateCombo("", 184, 136, 145, 25, BitOR($CBS_DROPDOWNLIST, $CBS_SORT))
$ProjectNameInputBox = GUICtrlCreateInput("Project Name", 184, 168, 161, 21, $ES_UPPERCASE)
$NumberofProjects = GUICtrlCreateInput("Number of Projects", 184, 200, 161, 21)
$Submit = GUICtrlCreateButton("Submit", 136, 376, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Exit = GUICtrlCreateButton("Exit", 256, 376, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
;$Label2 = GUICtrlCreateLabel("Choose Your Project Type:", 24, 140, 156, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("Choose Your Project Site:", 24, 108, 150, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("Input Your Project Name:", 24, 172, 147, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("Input Number of Projects", 24, 204, 145, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label6 = GUICtrlCreateLabel("Choose Your Project Side", 24, 236, 149, 17)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$ProjectSideCombo = GUICtrlCreateCombo("", 184, 232, 145, 25, BitOR($CBS_DROPDOWN, $CBS_SORT))
GUICtrlSetState(-1, $GUI_HIDE)

$Label2 = GUICtrlCreateLabel("Please Check What You Would Like To Generate", 104, 264, 285, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$hardwaretest = GUICtrlCreateCheckbox("Hardware Test", 48, 304, 105, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$maintenanceemail = GUICtrlCreateCheckbox("Maintenance Email", 168, 304, 129, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Checkbox1 = GUICtrlCreateCheckbox("Traffic Add", 320, 304, 81, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

$C = GUICtrlRead($NumberofProjects)
$I = 0
Global $K = 0

Local $array[2]
Local $array1[2]
While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Exit
            Exit

        Case $Submit

                Do
    ;       For $I = 0 To UBound($array) - 1
                $oIE = _IECreate("https://internalsite/mediawiki/index.php?title=" & GUICtrlRead($ProjectNameInputBox) & "&action=edit", 0, 0, 1, 1)
                _IELinkClickByText($oIE, "Continue to this website (not recommended).")
                $string = _IEBodyReadHTML($oIE)
                $data = $oIE
                _IEQuit($oIE)


                $array[0] = _StringBetween($string, '|AInterface=', @CRLF)
                $array1[0] = _StringBetween($string, '|ZInterface=', @CRLF)
                
                Local $asideinterface = $array[0]; _StringBetween($string, '|AInterface=', @CRLF)
                Local $zsideinterface = $array1[0];_StringBetween($string, '|ZInterface=', @CRLF)
                Local $asiderouter = _StringBetween($string, '|ALocation=', @CRLF)
                Local $zsiderouter = _StringBetween($string, '|ZLocation=', @CRLF)
                Local $asidetransport = _StringBetween($string, '|ATransportLocation=', @CRLF)
                Local $zsidetransport = _StringBetween($string, '|ZTransportLocation=', @CRLF)
                Local $asidefpc = _StringBetween($string, '|AFPC=', @CRLF)
                Local $zsidefpc = _StringBetween($string, '|ZFPC=', @CRLF)
                Local $asidepic = _StringBetween($string, '|APIC=', @CRLF)
                Local $zsidepic = _StringBetween($string, '|ZPIC=', @CRLF)
                Local $asideoptics = _StringBetween($string, '|AOptics=', @CRLF)
                Local $zsideoptics = _StringBetween($string, '|ZOptics=', @CRLF)
                Local $asidetam = _StringBetween($string, '|ATAM=', @CRLF)
                Local $zsidetam = _StringBetween($string, '|ZTAM=', @CRLF)
                Local $asidetom = _StringBetween($string, '|ATOM=', @CRLF)
                Local $zsidetom = _StringBetween($string, '|ZTOM=', @CRLF)
                Local $asidetestip = _StringBetween($string, '|ATestingIP=', @CRLF)
                Local $zsidetestip = _StringBetween($string, '|ZTestingIP=', @CRLF)






                Local $aprojincr = StringRegExp(GUICtrlRead($ProjectNameInputBox), "(?<=-\d{2})([A-Z])(?=-Q)", 3)

                Local $aprojincr = StringRegExp(GUICtrlRead($ProjectNameInputBox), "(?<=-\d{2})([A-Z])(?=-Q)", 3)
                Local $incr_char = Chr(Asc($aprojincr[0]) + 1)
                GUICtrlSetData($ProjectNameInputBox, StringRegExpReplace(GUICtrlRead($ProjectNameInputBox), _
                        "(?<=-\d{2})([A-Z])(?=-Q)", $incr_char))

                $I += 1

_ArrayAdd($asideinterface,$array)
_ArrayAdd($Zsideinterface,$array1)
;_ArrayDisplay($array[0])
;_ArrayDisplay($array1[0])
                            Until $I = (GUICtrlRead($NumberofProjects))


                ConsoleWrite("First Line Test" & @CRLF)


For $I = 0 To UBound($array)-1
For $I = 0 To UBound($array1)-1
ConsoleWrite($asideinterface[$I] & @CRLF)
ConsoleWrite($zsideinterface[$I] & @CRLF)
Next
Next

                ConsoleWrite("Last Line Test" & @CRLF)

                If $I = (GUICtrlRead($NumberofProjects) + 1) Then Exit




    EndSwitch

WEnd

Above is the code that I just pulled from SCITE.  Please note that this "won't run" as the calls an internal company website, but everything is there that i'm trying to do.

Thanks

Share this post


Link to post
Share on other sites

This part here:

For $I = 0 To UBound($array)-1
For $I = 0 To UBound($array1)-1
ConsoleWrite($asideinterface[$I] & @CRLF)
ConsoleWrite($zsideinterface[$I] & @CRLF)
Next
Next

As BrewManH mentioned, is using the same variable to iterate through 2 loops. So, if both arrays are always going to be the same size, you can just use one of those for loops. Otherwise, try renaming your second loop's $I to $X or something other than $I. 

It seems that you only want to get the $array[0] so you can just ConsoleWrite that directly without using the above for loops at all. Something like:

ConsoleWrite($asideinterface[0] & @CRLF)

Also here:

$array[0] = _StringBetween($string, '|AInterface=', @CRLF)
$array1[0] = _StringBetween($string, '|ZInterface=', @CRLF)

Remove the [0] off the variables and try again. 

Share this post


Link to post
Share on other sites
0xdefea7 and BrewManH thanks for the input i'll test tonight and let you know.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Tested again with the code below.  It's still only grabbing the last iteration of each variable.

Case $Submit

                Do
    ;       For $I = 0 To UBound($array) - 1
                $oIE = _IECreate("https://internal/mediawiki/index.php?title=" & GUICtrlRead($ProjectNameInputBox) & "&action=edit", 0, 0, 1, 1)
                _IELinkClickByText($oIE, "Continue to this website (not recommended).")
                $string = _IEBodyReadHTML($oIE)
                $data = $oIE
                _IEQuit($oIE)


                $array = _StringBetween($string, '|AInterface=', @CRLF)
                $array1 = _StringBetween($string, '|ZInterface=', @CRLF)

                Local $asideinterface = $array; _StringBetween($string, '|AInterface=', @CRLF)
                Local $zsideinterface = $array1;_StringBetween($string, '|ZInterface=', @CRLF)
                Local $asiderouter = _StringBetween($string, '|ALocation=', @CRLF)
                Local $zsiderouter = _StringBetween($string, '|ZLocation=', @CRLF)
                Local $asidetransport = _StringBetween($string, '|ATransportLocation=', @CRLF)
                Local $zsidetransport = _StringBetween($string, '|ZTransportLocation=', @CRLF)
                Local $asidefpc = _StringBetween($string, '|AFPC=', @CRLF)
                Local $zsidefpc = _StringBetween($string, '|ZFPC=', @CRLF)
                Local $asidepic = _StringBetween($string, '|APIC=', @CRLF)
                Local $zsidepic = _StringBetween($string, '|ZPIC=', @CRLF)
                Local $asideoptics = _StringBetween($string, '|AOptics=', @CRLF)
                Local $zsideoptics = _StringBetween($string, '|ZOptics=', @CRLF)
                Local $asidetam = _StringBetween($string, '|ATAM=', @CRLF)
                Local $zsidetam = _StringBetween($string, '|ZTAM=', @CRLF)
                Local $asidetom = _StringBetween($string, '|ATOM=', @CRLF)
                Local $zsidetom = _StringBetween($string, '|ZTOM=', @CRLF)
                Local $asidetestip = _StringBetween($string, '|ATestingIP=', @CRLF)
                Local $zsidetestip = _StringBetween($string, '|ZTestingIP=', @CRLF)


                Local $aprojincr = StringRegExp(GUICtrlRead($ProjectNameInputBox), "(?<=-\d{2})([A-Z])(?=-Q)", 3)

                Local $aprojincr = StringRegExp(GUICtrlRead($ProjectNameInputBox), "(?<=-\d{2})([A-Z])(?=-Q)", 3)
                Local $incr_char = Chr(Asc($aprojincr[0]) + 1)
                GUICtrlSetData($ProjectNameInputBox, StringRegExpReplace(GUICtrlRead($ProjectNameInputBox), _
                        "(?<=-\d{2})([A-Z])(?=-Q)", $incr_char))

                $I += 1


                            Until $I = (GUICtrlRead($NumberofProjects))

                ConsoleWrite("First Line Test" & @CRLF)


ConsoleWrite($asideinterface[0] & @CRLF)
ConsoleWrite($zsideinterface[0] & @CRLF)

                ConsoleWrite("Last Line Test" & @CRLF)

                If $I = (GUICtrlRead($NumberofProjects) + 1) Then Exit




    EndSwitch

WEnd
Edited by atnextc

Share this post


Link to post
Share on other sites

How many versions of this script are you going to post? That one is different from the last one you posted.

But, one of the many things wrong with this script is that your're using _ArrayAdd and adding an array to an array and you're using StringBetween, which returns an array and putting that into an element of the array as well. You should read the Wiki article on how to use arrays, because it's clear you haven't used them before.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Must have missed something before, it seems that I've solved it:

The ConsoleWrite is outside of your "do..until" loop. So it only writes the values from the last iteration of the loop since it is called after the fact.

Here is my slightly modified version of your loop, I shortened a few things and removed the arrays (array and array1) as well as their _ArrayAdd functions

$C = GUICtrlRead($NumberofProjects)
$I = 0
$K = 0 

While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Exit
            Exit
        Case $Submit            
            ConsoleWrite("First Line Test" & @CRLF)
            
            Do

                $oIE = _IECreate("https://internalsite/mediawiki/index.php?title=" & GUICtrlRead($ProjectNameInputBox) & "&action=edit", 0, 0, 1, 1)
                _IELinkClickByText($oIE, "Continue to this website (not recommended).")
                $string = _IEBodyReadHTML($oIE)
                $data = $oIE
                _IEQuit($oIE)

                Local $asideinterface = _StringBetween($string, '|AInterface=', @CRLF)
                Local $zsideinterface = _StringBetween($string, '|ZInterface=', @CRLF)
                Local $asiderouter = _StringBetween($string, '|ALocation=', @CRLF)
                Local $zsiderouter = _StringBetween($string, '|ZLocation=', @CRLF)
                Local $asidetransport = _StringBetween($string, '|ATransportLocation=', @CRLF)
                Local $zsidetransport = _StringBetween($string, '|ZTransportLocation=', @CRLF)
                Local $asidefpc = _StringBetween($string, '|AFPC=', @CRLF)
                Local $zsidefpc = _StringBetween($string, '|ZFPC=', @CRLF)
                Local $asidepic = _StringBetween($string, '|APIC=', @CRLF)
                Local $zsidepic = _StringBetween($string, '|ZPIC=', @CRLF)
                Local $asideoptics = _StringBetween($string, '|AOptics=', @CRLF)
                Local $zsideoptics = _StringBetween($string, '|ZOptics=', @CRLF)
                Local $asidetam = _StringBetween($string, '|ATAM=', @CRLF)
                Local $zsidetam = _StringBetween($string, '|ZTAM=', @CRLF)
                Local $asidetom = _StringBetween($string, '|ATOM=', @CRLF)
                Local $zsidetom = _StringBetween($string, '|ZTOM=', @CRLF)
                Local $asidetestip = _StringBetween($string, '|ATestingIP=', @CRLF)
                Local $zsidetestip = _StringBetween($string, '|ZTestingIP=', @CRLF)
                Local $aprojincr = StringRegExp(GUICtrlRead($ProjectNameInputBox), "(?<=-\d{2})([A-Z])(?=-Q)", 3)
                Local $aprojincr = StringRegExp(GUICtrlRead($ProjectNameInputBox), "(?<=-\d{2})([A-Z])(?=-Q)", 3)
                Local $incr_char = Chr(Asc($aprojincr[0]) + 1)
                
                GUICtrlSetData($ProjectNameInputBox, StringRegExpReplace(GUICtrlRead($ProjectNameInputBox), _
                        "(?<=-\d{2})([A-Z])(?=-Q)", $incr_char))

                $I += 1

                ConsoleWrite($asideinterface[0] & @CRLF)
                ConsoleWrite($zsideinterface[0] & @CRLF)
                
            Until $I = $C
                        ExitLoop

    EndSwitch

WEnd

ConsoleWrite("Last Line Test" & @CRLF)
Exit
Edited by 0xdefea7

Share this post


Link to post
Share on other sites

hmm something still askew somewhere.

--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
First Line Test
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
C:\Users\atnextc\Desktop\array loop test 7-6-2013.au3 (104) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
ConsoleWrite($asideinterface[$I] & @CRLF)
ConsoleWrite(^ ERROR
->00:00:00 AutoIT3.exe ended.rc:1
>Exit code: 1    Time: 6.330
$C = GUICtrlRead($NumberofProjects)
$I = 0
$K = 0


While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Exit
            Exit

        Case $Submit
            ConsoleWrite("First Line Test" & @CRLF)

            Do

                $oIE = _IECreate("https://internalsite/mediawiki/index.php?title=" & GUICtrlRead($ProjectNameInputBox) & "&action=edit", 0, 0, 1, 1)
                _IELinkClickByText($oIE, "Continue to this website (not recommended).")
                $string = _IEBodyReadHTML($oIE)
                $data = $oIE
                _IEQuit($oIE)

                Local $asideinterface = _StringBetween($string, '|AInterface=', @CRLF)
                Local $zsideinterface = _StringBetween($string, '|ZInterface=', @CRLF)
                Local $asiderouter = _StringBetween($string, '|ALocation=', @CRLF)
                Local $zsiderouter = _StringBetween($string, '|ZLocation=', @CRLF)
                Local $asidetransport = _StringBetween($string, '|ATransportLocation=', @CRLF)
                Local $zsidetransport = _StringBetween($string, '|ZTransportLocation=', @CRLF)
                Local $asidefpc = _StringBetween($string, '|AFPC=', @CRLF)
                Local $zsidefpc = _StringBetween($string, '|ZFPC=', @CRLF)
                Local $asidepic = _StringBetween($string, '|APIC=', @CRLF)
                Local $zsidepic = _StringBetween($string, '|ZPIC=', @CRLF)
                Local $asideoptics = _StringBetween($string, '|AOptics=', @CRLF)
                Local $zsideoptics = _StringBetween($string, '|ZOptics=', @CRLF)
                Local $asidetam = _StringBetween($string, '|ATAM=', @CRLF)
                Local $zsidetam = _StringBetween($string, '|ZTAM=', @CRLF)
                Local $asidetom = _StringBetween($string, '|ATOM=', @CRLF)
                Local $zsidetom = _StringBetween($string, '|ZTOM=', @CRLF)
                Local $asidetestip = _StringBetween($string, '|ATestingIP=', @CRLF)
                Local $zsidetestip = _StringBetween($string, '|ZTestingIP=', @CRLF)
                Local $aprojincr = StringRegExp(GUICtrlRead($ProjectNameInputBox), "(?<=-\d{2})([A-Z])(?=-Q)", 3)
                Local $aprojincr = StringRegExp(GUICtrlRead($ProjectNameInputBox), "(?<=-\d{2})([A-Z])(?=-Q)", 3)
                Local $incr_char = Chr(Asc($aprojincr[0]) + 1)

                GUICtrlSetData($ProjectNameInputBox, StringRegExpReplace(GUICtrlRead($ProjectNameInputBox), _
                        "(?<=-\d{2})([A-Z])(?=-Q)", $incr_char))

                $I += 1

                ConsoleWrite($asideinterface[$I] & @CRLF)
                ConsoleWrite($zsideinterface[$I] & @CRLF)

            Until $I = $C

    EndSwitch

WEnd

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Change the $I to a 0 like I did in my edited post:

ConsoleWrite($zsideinterface[0] & @CRLF)

Do this for both lines. Also, add this for the output to look the way you described in your first post:

Until $I = $C
        ExitLoop       <==== This here

    EndSwitch

WEnd

ConsoleWrite("Last Line Test" & @CRLF) <==== This here
Edited by 0xdefea7

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Ok I didn't see the edited post.

Now it's working for the single iteration of "write 1 line" then write multiple lines then write 1 line again, how would I then start to add more multi lines in the script?

Also when using [0] instead of $I, the Do Until isn't working as the script is just looping through the array until there is a subscript error.

>Running:(3.3.8.1):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\tcovert\Desktop\array loop test 7-6-2013.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
First Line Test
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
et-0/0/11
xe-3/0/0
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
et-0/0/13
xe-3/1/0
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
et-1/0/11
xe-3/0/2
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
et-1/0/13
xe-3/1/2
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
et-2/0/11
xe-3/0/4
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
et-2/0/13
xe-3/1/4
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
C:\Users\tcovert\Desktop\array loop test 7-6-2013.au3 (104) : ==> Subscript used with non-Array variable.:
ConsoleWrite($asideinterface[0] & @CRLF)
ConsoleWrite($asideinterface^ ERROR
->00:19:55 AutoIT3.exe ended.rc:1
>Exit code: 1    Time: 11.484

Code:

Case $Submit
            ConsoleWrite("First Line Test" & @CRLF)

            Do

                $oIE = _IECreate("https://internal/mediawiki/index.php?title=" & GUICtrlRead($ProjectNameInputBox) & "&action=edit", 0, 0, 1, 1)
                _IELinkClickByText($oIE, "Continue to this website (not recommended).")
                $string = _IEBodyReadHTML($oIE)
                $data = $oIE
                _IEQuit($oIE)

                Local $asideinterface = _StringBetween($string, '|AInterface=', @CRLF)
                Local $zsideinterface = _StringBetween($string, '|ZInterface=', @CRLF)
                Local $asiderouter = _StringBetween($string, '|ALocation=', @CRLF)
                Local $zsiderouter = _StringBetween($string, '|ZLocation=', @CRLF)
                Local $asidetransport = _StringBetween($string, '|ATransportLocation=', @CRLF)
                Local $zsidetransport = _StringBetween($string, '|ZTransportLocation=', @CRLF)
                Local $asidefpc = _StringBetween($string, '|AFPC=', @CRLF)
                Local $zsidefpc = _StringBetween($string, '|ZFPC=', @CRLF)
                Local $asidepic = _StringBetween($string, '|APIC=', @CRLF)
                Local $zsidepic = _StringBetween($string, '|ZPIC=', @CRLF)
                Local $asideoptics = _StringBetween($string, '|AOptics=', @CRLF)
                Local $zsideoptics = _StringBetween($string, '|ZOptics=', @CRLF)
                Local $asidetam = _StringBetween($string, '|ATAM=', @CRLF)
                Local $zsidetam = _StringBetween($string, '|ZTAM=', @CRLF)
                Local $asidetom = _StringBetween($string, '|ATOM=', @CRLF)
                Local $zsidetom = _StringBetween($string, '|ZTOM=', @CRLF)
                Local $asidetestip = _StringBetween($string, '|ATestingIP=', @CRLF)
                Local $zsidetestip = _StringBetween($string, '|ZTestingIP=', @CRLF)
                Local $aprojincr = StringRegExp(GUICtrlRead($ProjectNameInputBox), "(?<=-\d{2})([A-Z])(?=-Q)", 3)
                Local $aprojincr = StringRegExp(GUICtrlRead($ProjectNameInputBox), "(?<=-\d{2})([A-Z])(?=-Q)", 3)
                Local $incr_char = Chr(Asc($aprojincr[0]) + 1)

                GUICtrlSetData($ProjectNameInputBox, StringRegExpReplace(GUICtrlRead($ProjectNameInputBox), _
                        "(?<=-\d{2})([A-Z])(?=-Q)", $incr_char))

                $I += 1

                ConsoleWrite($asideinterface[0] & @CRLF)
                ConsoleWrite($zsideinterface[0] & @CRLF)

            Until $I = $C
ExitLoop
    EndSwitch

WEnd

ConsoleWrite("Last Line Test" & @CRLF)

Thanks for all the help

Edited by atnextc

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Another question that comes to my mind is:

Do

                $oIE = _IECreate("https://internal/mediawiki/index.php?title=" & GUICtrlRead($ProjectNameInputBox) & "&action=edit", 0, 0, 1, 1)
                _IELinkClickByText($oIE, "Continue to this website (not recommended).")
                $string = _IEBodyReadHTML($oIE)
                $data = $oIE
                _IEQuit($oIE)

                Local $asideinterface = _StringBetween($string, '|AInterface=', @CRLF)
                Local $zsideinterface = _StringBetween($string, '|ZInterface=', @CRLF)
                Local $asiderouter = _StringBetween($string, '|ALocation=', @CRLF)
                Local $zsiderouter = _StringBetween($string, '|ZLocation=', @CRLF)
                Local $asidetransport = _StringBetween($string, '|ATransportLocation=', @CRLF)
                Local $zsidetransport = _StringBetween($string, '|ZTransportLocation=', @CRLF)
                Local $asidefpc = _StringBetween($string, '|AFPC=', @CRLF)
                Local $zsidefpc = _StringBetween($string, '|ZFPC=', @CRLF)
                Local $asidepic = _StringBetween($string, '|APIC=', @CRLF)
                Local $zsidepic = _StringBetween($string, '|ZPIC=', @CRLF)
                Local $asideoptics = _StringBetween($string, '|AOptics=', @CRLF)
                Local $zsideoptics = _StringBetween($string, '|ZOptics=', @CRLF)
                Local $asidetam = _StringBetween($string, '|ATAM=', @CRLF)
                Local $zsidetam = _StringBetween($string, '|ZTAM=', @CRLF)
                Local $asidetom = _StringBetween($string, '|ATOM=', @CRLF)
                Local $zsidetom = _StringBetween($string, '|ZTOM=', @CRLF)
                Local $asidetestip = _StringBetween($string, '|ATestingIP=', @CRLF)
                Local $zsidetestip = _StringBetween($string, '|ZTestingIP=', @CRLF)
                Local $aprojincr = StringRegExp(GUICtrlRead($ProjectNameInputBox), "(?<=-\d{2})([A-Z])(?=-Q)", 3)
                Local $aprojincr = StringRegExp(GUICtrlRead($ProjectNameInputBox), "(?<=-\d{2})([A-Z])(?=-Q)", 3)
                Local $incr_char = Chr(Asc($aprojincr[0]) + 1)

                GUICtrlSetData($ProjectNameInputBox, StringRegExpReplace(GUICtrlRead($ProjectNameInputBox), _
                        "(?<=-\d{2})([A-Z])(?=-Q)", $incr_char))

                $I += 1

This is where all of my information is coming from for all of the functions that I have in my much bigger script.  Currently I have the above at the start of every function, is there a way that I can have this be "global" so that I don't have to have all these multiple lines of code bundling up my script

Edited by atnextc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0