Jump to content

Recommended Posts

Posted

Hi,

I'm new to AutoIT, and just wanting to create a script that would read the contents of a CSV file - then be able to output the CSV file's contents following some proper order.

To begin with, my source CSV's delimiter will be a comma (,). Should go something like:
Busy,Account1,Kamote,101
Busy,Account1,Kamote,102
Busy,Account1,Kamote,101
Busy,Account1,Kamote,102
Busy,Account1,Kamote,101
Busy,Account1,Kamote,102

I'd like to be able to output it through send following some output formats so it would be:
Busy{REAL TAB KEYSTROKE}Account1{REAL TAB KEYSTROKE}Kamote{REAL TAB KEYSTROKE}101
Busy{REAL TAB KEYSTROKE}Account1{REAL TAB KEYSTROKE}Kamote{REAL TAB KEYSTROKE}102
Busy{REAL TAB KEYSTROKE}Account1{REAL TAB KEYSTROKE}Kamote{REAL TAB KEYSTROKE}101
Busy{REAL TAB KEYSTROKE}Account1{REAL TAB KEYSTROKE}Kamote{REAL TAB KEYSTROKE}102
Busy{REAL TAB KEYSTROKE}Account1{REAL TAB KEYSTROKE}Kamote{REAL TAB KEYSTROKE}101
Busy{REAL TAB KEYSTROKE}Account1{REAL TAB KEYSTROKE}Kamote{REAL TAB KEYSTROKE}102

For some weird reasons, the closest code I can get renders this kind of output:
Busy{REAL TAB KEYSTROKE}Account1{REAL TAB KEYSTROKE}Kamote{REAL TAB KEYSTROKE}101
BusyAccount1{REAL TAB KEYSTROKE}Kamote102
BusyAccount1Kamote{REAL TAB KEYSTROKE}101
BusyAccount1Kamote102
BusyAccount1Kamote101
BusyAccount1Kamote102

Not sure if this is AutoIT's behavior when using send tabs, or am I missing something? Below is the source code that I currently have:
#include <Misc.au3>
#Include <WinAPI.au3>
#include<misc.au3>
#include <File.au3>
#include <Array.au3>

Global $aCSV[1]
Global $intCount = 0
Global $intRow = 0
Global $intCol = 0
Global $intLineCount = 0

_FileReadToArray("C:\Users\MasterMoronman\Desktop\ZC_ModelTemplates.csv", $aCSV, Default, ",")
$intLineCount = _FileCountLines("C:\Users\MasterMoronman\Desktop\ZC_ModelTemplates.csv") - 1

Do
    Sleep(1)
Until _IsPressed("71") or _IsPressed("72") or _IsPressed("0D")
If _IsPressed("71") Then
Send("F2 is pressed.")
ElseIf _IsPressed("72") Then
Send("F3 is pressed.")
ElseIf _IsPressed("0D") Then

While $intCount <= $intLineCount

    $intCount = $intCount + 1
    ;$intRow = $intCount

    Send($aCSV[$intRow+$intCount][$intCol])
    
    Sleep(1000)
    Send("{TAB}")
    Sleep(1000)
    
    Send($aCSV[$intRow+$intCount][$intCol+1])
    Sleep(1000)
    Send("{TAB}")
    Sleep(1000)

    Send($aCSV[$intRow+$intCount][$intCol+2])
    Sleep(1000)
    Send("{TAB}")
    Sleep(1000)
    
    Send($aCSV[$intRow+$intCount][$intCol+3])
    Sleep(1000)
    Send("{ENTER}")
    Sleep(1000)
WEnd

 

 EndIfZC_ModelTemplates.csv 

 

test-001.au3

Posted

The goal is to fill out some fields on web browsers with values. Thus typing one value and then sending a real tab keystroke after every value.

Posted (edited)

@moronman
There are _IE* functions which could be helpful in your case.
But if you want to make it in a "raw" way, then this should be helpful as well:

#include <Array.au3>
#include <File.au3>

Global $strFileName = @ScriptDir & "\SampleCSV.csv", _
       $arrFileContent


_FileReadToArray($strFileName, $arrFileContent, $FRTA_COUNT, ",")
If @error Then
    ConsoleWrite("Error while reading the content of the file '" & $strFileName & "'. Error: " & @error & @CRLF)
Else
    
    ; Activate your window in order to give it the focus
    
    For $i = 1 To UBound($arrFileContent, $UBOUND_ROWS) Step 1
        For $j = 0 To UBound($arrFileContent, $UBOUND_COLUMNS) - 1 Step 1
            Send($arrFileContent[$i][$j], $SEND_RAW)
            Send("{TAB}")
        Next
        Send("{ENTER}")
    Next
EndIf

:)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Posted

Have look at this very powerful utility? Once you have read the CSV you can output it again in any format you like :)

 

 

Skysnake

Why is the snake in the sky?

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
×
×
  • Create New...