Sign in to follow this  
Followers 0
pillbug

Copy Text to Variable

5 posts in this topic

I have done a lot of searching on the forum and I can't seem to solve this particular solution. I'll summarize what I'd like to do:

I am trying to take the entire first line of text or cell of Excel and have a script copy it, store it to a variable, which is later used in the script. The program would then repeat to take the next line or cell of data.

I understand how to copy, store to a variable, and loop the task.

$i=1
Send("^c");  (copy to clip)
Global $filename = clipget()
Send("{DOWN}")
$i=$i+1

I just don't understand how I would select the entire first line. The data is all numerical, but it ranges in size from 3 digits to 7 digits.

I ran across functions like StringTrimLeft, but these seem to only work once I have data stored to an array.

Can someone direct me. Whether a function exists for pulling a line in either a text file or excel file, or if there is another way to perform the task of copying data with 3 to 7 digits.

Share this post


Link to post
Share on other sites



I have done a lot of searching on the forum and I can't seem to solve this particular solution. I'll summarize what I'd like to do:

I am trying to take the entire first line of text or cell of Excel and have a script copy it, store it to a variable, which is later used in the script. The program would then repeat to take the next line or cell of data.

I understand how to copy, store to a variable, and loop the task.

$i=1
Send("^c");  (copy to clip)
Global $filename = clipget()
Send("{DOWN}")
$i=$i+1

I just don't understand how I would select the entire first line. The data is all numerical, but it ranges in size from 3 digits to 7 digits.

I ran across functions like StringTrimLeft, but these seem to only work once I have data stored to an array.

Can someone direct me. Whether a function exists for pulling a line in either a text file or excel file, or if there is another way to perform the task of copying data with 3 to 7 digits.

here's a quick page ref since I'm about to crash

CODE
FileOpen

--------------------------------------------------------------------------------

Opens a text file for reading or writing.

FileOpen ( "filename", mode )

Parameters

filename Filename of the text file to open.

mode Mode (read or write) to open the file in.

Can be a combination of the following:

0 = Read mode

1 = Write mode (append to end of file)

2 = Write mode (erase previous contents)

4 = Read raw mode

8 = Create directory structure if it doesn't exist (See Remarks).

16 = Force binary(byte) reading and writing mode with FileRead and FileWrite

32 = Use Unicode UTF16 Little Endian mode when writing text with FileWrite and FileWriteLine (default is ANSI)

64 = Use Unicode UTF16 Big Endian mode when writing text with FileWrite and FileWriteLine (default is ANSI)

128 = Use Unicode UTF8 when writing text with FileWrite and FileWriteLine (default is ANSI)

Both write modes will create the file if it does not already exist. The folder path must already exist (except using mode '8' - See Remarks).

Return Value

Success: Returns a file "handle" for use with subsequent file functions.

Failure: Returns -1 if error occurs.

Remarks

A file can only be in either read or write mode; it cannot be in both.

Some file attributes can make the opening impossible.

When opening a file in write mode, the file will be created if it does not exist.

When finished working with a file, call the FileClose function to close the file. Autoit normally closes all files upon termination, but explicitly calling FileClose is still a good idea.

The default mode when writing text is ANSI - use the unicode flags to change this. When writing unicode files the Windows default mode (and the fastest in AutoIt due to the least conversion) is UTF16 Little Endian (mode 32).

When using the mode=4 (Raw Read) the filename is defined as "\\.\A:" for reading sector on a floppy disk the count must be a multiple of sector size(512).

Non-existing directory structure:

------------------------------------

By default the file will not be created if the directory structure doesn't exist.

To overwrite this behaviour use the modes '1' or '2' together with mode-flag '8'!

For instance the mode-flag '9' (1 + 8) checks for the directory structure and if it doesn't exist creates it automatically and then opens the file for appending.

Related

FileClose, FileReadLine, FileWriteLine, FileRead

Example

$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

FileClose($file)

; Another sample which automatically creates the directory structure

$file = FileOpen("test.txt", 10) ; which is similar to 2 + 8 (erase + create dir)

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

FileClose($file)

this page is part of the compiled html help file found in your AutoIt folder, its file size is roughly 72kb
1 person likes this

Share this post


Link to post
Share on other sites

Can someone direct me. Whether a function exists for pulling a line in either a text file or excel file, or if there is another way to perform the task of copying data with 3 to 7 digits.

http://www.autoitscript.com/forum/index.ph...st&p=249975

Specifically for Excel, this link has

ExcelCOM_UDF.au3 ( 138.3K ) A User Defined Functions file.

If this, #include <ExcelCOM_UDF.au3> , is in your script, then ExcelCOM_UDF.au3 has to be in the ...\AutoIt3\Include directory.

If this, #include "ExcelCOM_UDF.au3" , is in your script, then ExcelCOM_UDF.au3 has to be in the same directory as the script you are running.

To two examples also at this link will explain by example.

ExcelCOM_UDF_Example01.au3 ( 798bytes )

ExcelCOM_UDF_Example02.au3 ( 2.29K )

This UDF makes working with Excel much easier.

You could do a forum search on ExcelCOM_UDF.au3 for other examples should you care to.

Good Luck.

Share this post


Link to post
Share on other sites

Thank you for the help, I've implemented this guidance into my code. I'll post my code if it works when I test it at work. I don't have access to a PC because I'm a mac user at home. I wish applescript was as sophisticated as this language. Hopefully one day autoit will give support for macs.

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