Sign in to follow this  
Followers 0
randd

clipget and _FileReadToArray

11 posts in this topic

Perhaps starting off with scripting python has damaged my un-adulterated programming mind but certain functions just don't work the way I want.

The _FileReadToArray is great (after I fixed the little bug with FileReadLine and made it FileRead - thanks to JdeB and this link.)

What's my problem then? What am I babbling about? I can't figure a way to get my data off the clipboard and directly to an array. I tried:

$cliptest = ClipGet()
MsgBox(0, "Clipboard contains:", $cliptest)

_FileReadToArray( $cliptest, $test )
MsgBox(0, "Clipboard contains:", $test[0])

Of course, the array isn't populated. Is this because I can't treat $cliptest as a file object?

The long of it is I can create a file and then read it into _FileReadToArray, but I'd rather work with the clipboard data since it's only 11 lines of text and I keep thinking that working directly with the clipboard is quicker and cleaner. Although that's based upon no facts what-so-ever. :D


Raoul S. Duke: Few people understand the psychology of dealing with a highway traffic cop. Your normal speeder will panic and immediately pull over to the side. This is wrong. It arouses contempt in the cop-heart. Make the bastard chase you. He will follow.

Share this post


Link to post
Share on other sites



The _FileReadToArray function is for files, not variables. If you need to store a value into an array element, just use $array[0] = $variable instead.


[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

The _FileReadToArray function is for files, not variables.  If you need to store a value into an array element, just use $array[0] = $variable instead.

I don't understand you. This is probably inexperience on my part, but if I assign $aArray[0] = $cliptest then $aArray[$variable] is always equal to 0 (where $variable is any number that I think should fall into $aArray size limit). Probably because I've had to Dim $aArray before I could pretend it's an array because it's really being saved as a standard variable not as an array anyway.

Kinda rhymey and clear as mud eh?

I just want to be able to save text contents of the clipboard directly to an array.

For the moment, I've decided to create and delete a file with the clipboard contents.

$cliptest = ClipGet()
$file = FileOpen('C:\SNMP.txt', 2)
FileWrite($file, $cliptest)
FileClose($file)
FileDelete('c:\SNMP.txt')

If someone could kick me in the right direction that'd be great. And if pekster kicked me in the right direction I'll have to ask for a harder kick, because I didn't get it.

TIA!


Raoul S. Duke: Few people understand the psychology of dealing with a highway traffic cop. Your normal speeder will panic and immediately pull over to the side. This is wrong. It arouses contempt in the cop-heart. Make the bastard chase you. He will follow.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I just want to be able to save text contents of the clipboard directly to an array.

;Assuming your clipboard is delimited with @LF ...

$aArray = StringSplit(ClipGet(), @LF)

;Assuming your clipboard is delimited with @CRLF ...

$aArray = StringSplit(StringReplace(ClipGet(),@CRLF,@LF),@LF)

Edit: improved accuracy.

Edited by trids

Share this post


Link to post
Share on other sites

...if I assign $aArray[0] = $cliptest then $aArray[$variable] is always equal to 0 (where $variable is any number that I think should fall into $aArray size limit).

If it helps you understand better, an array in AutoIt is 0-indexed, which means the first element is numbered 0, not one. This is different than when you dimension an array, in which case the number of dimensions is one less than the last element number of the array. So if you did Local $array[5] the last element in the array would be $array[4] and the first $array[0]

Another important note: any newly created array is filled with 0's, so unless you store a 0 to an alement, all 0 numbers will mean that nothing has been defined to it.

Hopefully trids helped you out with his example of splitting a multi-line string into an array. I might have misunderstood what you needed because I thought you just had a variable, and wanted to insert the entire variable into an array element. The solution trids provided will split your source string into an array, the first element containing the number of elements (such that $array[$array[0]] is the last element), and the rest containing data that was seperated with either the @LF or @CR characters (or both.)

With any luck, this description didn't make things worse for you :D


[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

;Assuming your clipboard is delimited with @LF ...

$aArray = StringSplit(ClipGet(), @LF)

;Assuming your clipboard is delimited with @CRLF ...

$aArray = StringSplit(StringReplace(ClipGet(),@CRLF,@LF),@LF)

Edit: improved accuracy.

pekster and trids,

Thanks! I learned the StringSplit function before, but it didn't click right away. I've got it now. I should have thought of it myself. You coulda just told me "Look into StringSplit" and I would have gotten it. (or perhaps not as I've just noticed the big fat stringsplit right in the middle of the _FileReadToArray function :D )

I don't know why, but I really thought I could just pass the contents of the clipboard directly to the _FileReadToArray function. I guess because that function actaully does the FileRead is what messes it up.

Is it plausible to change the following line

$aArray = StringSplit( FileRead( $hFile, FileGetSize( $sFilePath ) ), @LF )

to accept input directly from the clipboard? It's probably not plausible to peform that is it?


Raoul S. Duke: Few people understand the psychology of dealing with a highway traffic cop. Your normal speeder will panic and immediately pull over to the side. This is wrong. It arouses contempt in the cop-heart. Make the bastard chase you. He will follow.

Share this post


Link to post
Share on other sites

Is it plausible to change the following line

$aArray = StringSplit( FileRead( $hFile, FileGetSize( $sFilePath ) ), @LF )

to accept input directly from the clipboard?  It's probably not plausible to peform that is it?

Sure. In the helpfile, it says that the first paramater is the input string. In the case of the code that you see in the UDF, it is reading a file for the length of the file. Just replace thewhole FileRead call with the ClipGet call. So your source string is the value of the clipboard, and you are delimiting with @LF. Just keep in mind that you may find lines that are seperated by the @CR or @CRLF combinations as well. Using more than one character at the end will split the string at either of the two characters (and not the combination of both.) This means you can do something like StringSplit($string, @CRLF) and have it split at either the @CR or the @LF characters. It also works if they're both there.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

Not to drag this on... but I guess I wasn't clear. I was asking if it was plausible to update the UDF (user defined function?) to include grabbing text from the clipboard and not just from files located on the disk. File in memory (clipboard) vs file on the hard drive right? I know it's possible, but I'm not sure if anyone would think the way that I do and assume the grabbing a files contents out of the clipboard should be the same as grabbing a files contents off the disk.

As an aside, because it's all windows based isn't the end of each line going to be CRLF anyway? Well, come to think of it, I guess there's some apps that fool with the end of line structure for portability reasons. I think winzip has a facilty to muck about with CRLF and LF.


Raoul S. Duke: Few people understand the psychology of dealing with a highway traffic cop. Your normal speeder will panic and immediately pull over to the side. This is wrong. It arouses contempt in the cop-heart. Make the bastard chase you. He will follow.

Share this post


Link to post
Share on other sites

...and assume the grabbing a files contents out of the clipboard should be the same as grabbing a files contents off the disk.

It's not. To read a file, you use the FileRead or FileReadLine function, which needs to point to a file. You access the clipboard through a macro, so it's a different access method. The only way the built in function could be updated is through an optional paramater, and I don't see that being useful for all the work it would take. Just write your own UDF. You already have most of the code you need right here in this thread. Just ask if you get confused along the way.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

Not to drag this on... but I guess I wasn't clear.  I was asking if it was plausible to update the UDF

User Defined Functions are completely under your own control. :D

They are all just as editable / customisable as any other code that you write yourself. So if you wish to write another UDF or change your copy of _FileReadToArray() to refer to the clipboard instead (or as well), then go ahead.

And if you come up with something spectacular, you can always share it on the Scripts And Scraps forum, from where it might find it's way into the UDFs of a subsequent download. :huh2:

Share this post


Link to post
Share on other sites

Thanks guys, for all the quick replys.

Since I don't think anyone else has the same need I'll probably just keep this all to myself. :D

Thanks again!


Raoul S. Duke: Few people understand the psychology of dealing with a highway traffic cop. Your normal speeder will panic and immediately pull over to the side. This is wrong. It arouses contempt in the cop-heart. Make the bastard chase you. He will follow.

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