Sign in to follow this  
Followers 0
timmyc

Copying line by line from notepad list

8 posts in this topic

Hi all,

Apologies for my noobiness, i do appreciate your help!

I am trying to read line 1 of a notepad, associate it with a variable, then sending that variable elsewhere.

then do the same for line 2 and so on and so on until there are no more lines in the notepad.

I need to collect two IP address, first the user will enter in the GUI box, the second will be line 1 in the notepad

Then use the same first ip adress (as first entered in GUI box) and then use line 2 in the notepad.

I have started a new notepad at the end just to test that it is getting these values, later on i will put it in the appropriate program.

Thanks for your help

Tim

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Template IP for PLID copy", 436, 160, 192, 124)
$Input1 = GUICtrlCreateInput("Ip address", 144, 48, 153, 21)
$Label1 = GUICtrlCreateLabel("What is the Template IP?", 72, 16, 292, 17)
$Button1 = GUICtrlCreateButton("Ok", 80, 96, 113, 25)
$Button2 = GUICtrlCreateButton("Cancel", 240, 96, 105, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###




While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            $IP = GUICtrlRead($Input1)
            ExitLoop
        case $Button2
            Exit
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd





Local $file = FileOpen("D:\userdata\testdir\txt.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    Local $line1 = FileReadLine($file, 1)
    $line2 = FileReadLine($file, 2)
    $line3 = FileReadLine($file, 3)
    $line4 = FileReadLine($file, 4)
    $line5 = FileReadLine($file, 5)
    If @error = -1 Then ExitLoop


WEnd
FileClose($file)


Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send($IP)
Send("{ENTER}")
Send($line1)

Share this post


Link to post
Share on other sites



From what I can tell, you basically want to create an array that contains a user given IP address that correlates to a list of IP addresses read from a file. Using your file name with one IP address per line, try this code:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>

$Form1 = GUICreate("Template IP for PLID copy", 436, 160)
$Input1 = GUICtrlCreateInput("Ip address", 144, 48, 153, 21)
$Label1 = GUICtrlCreateLabel("What is the Template IP?", 72, 16, 292, 17)
$Button1 = GUICtrlCreateButton("Ok", 80, 96, 113, 25)
$Button2 = GUICtrlCreateButton("Cancel", 240, 96, 105, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            $IP = GUICtrlRead($Input1)

            $file = @ScriptDir & "\txt.txt"
            $arraySize = _FileCountLines($file)
            Dim $array[$arraySize][2]
            For $i = 1 to $arraySize Step 1
                $array[$i - 1][0] = $IP
                $array[$i - 1][1] = FileReadLine($file, $i)
            Next
            _ArrayDisplay($array)
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button2
            Exit

    EndSwitch
WEnd

 

Arrays are an efficient way to work with data. With this, you can have variable file sizes and loop your commands to the size of the array.

If you could give a real world example of what you are wanting to accomplish, maybe we could provide more ideas.


RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

Thanks so much! I haven't had much experience with arrays.

This is pretty much step 1 of what i want, step two is as follows:

sending $ip, then sending array value (colum 1, row 0)

sending $ip, then sending array value (colum 1, row 1)

sending $ip, then sending array value (colum 1, row 2)

etc etc

Untill Colum 1 is empty.

Thanks again

Tim

Share this post


Link to post
Share on other sites

Thanks so much! I haven't had much experience with arrays.

This is pretty much step 1 of what i want, step two is as follows:

sending $ip, then sending array value (colum 1, row 0)

sending $ip, then sending array value (colum 1, row 1)

sending $ip, then sending array value (colum 1, row 2)

etc etc

Untill Colum 1 is empty.

Thanks again

Tim

 

What are you sending these values to? Are you sending the data to a text file or are you sending to the IP addresses? I'm having trouble understanding the overall goal.


RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

Hi,

Sorry, i am sending the values to a program.

A feature in this program is that it copies and pastes certain printer settings to any pc IP (within our network). To do this manually i would give it the "good" IP ($ip) then give it the IP of the pc that needs those settings. This would copy the settings from $ip to the destination Pc however i want to automate this so i can compile a list of IP's and it runs through and copies $ip settings to the list of ip address's. 

I have made a basic version where Template IP GUI box pops up ($ip) 
Then destination IP GUI box pops up 
Once you hit OK it runs the program, logs me in, goes to the menu, sends $ip, sends enter, sends destination ip, sends enter 

This only does 1 "copy and paste" however i want to the list of all the ips in the .txt file.
 

Hope this makes sense 

Share this post


Link to post
Share on other sites

OK, that makes more sense. It is usually best to activate the window (bring it to the front of all other windows) and wait until it is active. For this, you will need to type the titlebar title of the window in the parts I wrote in "Window Title". Of course, I can't test this code since I do not have your software, but this is close to what should work:

Example:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>

$Form1 = GUICreate("Template IP for PLID copy", 436, 160)
$Input1 = GUICtrlCreateInput("Ip address", 144, 48, 153, 21)
$Label1 = GUICtrlCreateLabel("What is the Template IP?", 72, 16, 292, 17)
$Button1 = GUICtrlCreateButton("Ok", 80, 96, 113, 25)
$Button2 = GUICtrlCreateButton("Cancel", 240, 96, 105, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            $IP = GUICtrlRead($Input1)

            $file = @ScriptDir & "\txt.txt"
            $arraySize = _FileCountLines($file)
            Dim $array[$arraySize][2]
            For $i = 1 to $arraySize Step 1
                $array[$i - 1][0] = $IP
                $array[$i - 1][1] = FileReadLine($file, $i)
            Next
            For $i = 1 to $arraySize Step 1 ; loop until end of array
                WinActivate("Window Title", "") ; activate the popup window
                WinWaitActive("Window Title") ; wait until the window is active
                Send($array[$i - 1][0]) ; send $IP
                Send("{ENTER}")
                WinActivate("Next Window Title", "") ; activate the next popup window
                WinWaitActive("Window Title") ; wait until the window is active
                Send($array[$i - 1][1]) ; send the IP address from the list
                Send("{ENTER}")
            Next
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button2
            Exit

    EndSwitch
WEnd

 

If you use AutoIt Info Window, you may be able to use ControlClick and ControlSetText to more accurately set the data rather than using Send. I have found Send can lose characters and when ControlSetText works (it doesn't work with all programs), it works extremely well.


RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

This is where it gets pretty tricky ....The program is an old dos based program so when i try use autoit window info and drag and drop the finder tool, i cant get any window title, name, classes...anything...i just doesn't return any value when i drop the finder tool in the application. The application also has no name on the window in the task bar so i cant call on any name. So i dont think theres any way to make sure that window is active (may be a deal breaker)

This is where im up to so far however the loop does not stop at the end of the IP list (just keeps doing the same list): 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>

$Form1 = GUICreate("Template IP for PLID copy", 436, 160)
$Input1 = GUICtrlCreateInput("Ip address", 144, 48, 153, 21)
$Label1 = GUICtrlCreateLabel("What is the Template IP?", 72, 16, 292, 17)
$Button1 = GUICtrlCreateButton("Ok", 80, 96, 113, 25)
$Button2 = GUICtrlCreateButton("Cancel", 240, 96, 105, 25)
GUISetState(@SW_SHOW)


Run("C:\Program Files\HBCIS\EXE\HBCIS_GOLDCOAST.exe")
                WinWait("HBCIS - Gold Coast")
                WinActive("HBCIS - Gold Coast")
                Sleep(2000)
                ControlCommand("HBCIS - Gold Coast", "", "[CLASS:Button; INSTANCE:43]", "Check")
                Sleep(1000)
                Send("173576")
                Send("{ENTER}")
                Send("password")
                Send("{ENTER}" )
                Sleep(1000)
                Send("3")
                Send("{ENTER}")
; Above logs me into the application and gets to the menu where the (below) looping will occur 

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            $IP = GUICtrlRead($Input1)

            $file = @ScriptDir & "\ip.txt"
            $arraySize = _FileCountLines($file)
            Dim $array[$arraySize][2]
            For $i = 1 to $arraySize Step 1
                $array[$i - 1][0] = $IP
                $array[$i - 1][1] = FileReadLine($file, $i)
            Next
            For $i = 1 to $arraySize Step 1 ; loop until end of array

                
                Send("3")
                Send("{ENTER}")
                Send("INETD-")
                Send($array[$i - 1][0]) ; send $IP
                Send("-0001")
                Send("{ENTER}")
                Send("INETD-")
                Send($array[$i - 1][1]) ; send the IP address from the list
                Send("-0001")
                Send("{ENTER}")
                Send("N")
                Send("{ENTER}")
            Next
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button2
            Exit

    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

UPDATE: Thanks to your help i have got it working. Instead of using Winactivate command i have sent an alt tab command which should work 99% of the time.

There might be the odd little thing i need to fix up from here but you have been so helpful! 

Thanks so much!

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