Jump to content

Clipboard or array ?(newbie questions)


Recommended Posts

Hi guys,

I'm new to AutoIT, as well as programming in general. This tool will really make my life soooo much easier. Thanks in advance for helping answer my stupid questions that probably have obvious answers.

I started playing around with AutoIT and went through the tutorials. I'm trying to automate tasks I do at work and am *slowly* trying to write code to accomplish this.

Okay question 1:

I wrote code to open a "select folder dialogue", and then a "file select dialogue". Those values are being written to an array. Since the number of files will vary from day to day, how do I declare an array that will accommodate different sizes? Or is this done automatically when enter in the files? This leads to

Question 2:

How do I actually inspect an array (look at the values) to ensure that what I think has been written actually is? I tried outputting these values to a messagebox, but nothing was returned.

Question 3:

Do I actually need an array in this example? I will probably have between 1 and 200 files to process, depending on the day. Would using the clipboard be more efficient? What is the best practice to follow here?

Here's what I wrote:

#Include <File.au3>

; declare an array to hold each file to be input

Dim $filearray

; select the folder with the data in it.

$selectfolder = FileSelectFolder("Choose the folder location for your data", "")

; select multiple files in the folder previously specified using the filter set

$filearray = FileOpenDialog("Select data files to process", $selectfolder, "Data (*.dat;*.img)", 4)

if @error then Exit

; read the files just selected into an array

_FileReadToArray($selectfolder, $filearray)

MsgBox(0, "Array check 1", "$selectfolder")

MsgBox(0, "Array check 2", "$filearray")

Thanks again for your help! I will gladly take any criticism or suggestions!

Link to comment
Share on other sites

Okay question 1:

I wrote code to open a "select folder dialogue", and then a "file select dialogue". Those values are being written to an array. Since the number of files will vary from day to day, how do I declare an array that will accommodate different sizes? Or is this done automatically when enter in the files?

The native command to resize an array without losing the old data is REDIM (see help file). As long as you don't change the number of dimensions (i.e. from a 1D array to 2D) the data is not lost. For a 1D array, there is an _ArrayAdd() UDF (see help file) to take care of this for you. REDIM'ing an array is relatively slow, so you would want other techniques if doing it in a tight loop, but for anything with human interface dialogs involved, that's not an issue.

Question 2:

How do I actually inspect an array (look at the values) to ensure that what I think has been written actually is? I tried outputting these values to a messagebox, but nothing was returned.

_ArrayDisplay() (see help file)

Question 3:

Do I actually need an array in this example? I will probably have between 1 and 200 files to process, depending on the day. Would using the clipboard be more efficient? What is the best practice to follow here?

Stick with the array. The big problem with newbies around is here is REFUSING to learn arrays and writing ridiculous work-arounds to avoid them. You're on the right track!

Here's what I wrote:

#Include <File.au3>
; declare an array to hold each file to be input
Dim $filearray

; select the folder with the data in it.
$selectfolder = FileSelectFolder("Choose the folder location for your data", "")

; select multiple files in the folder previously specified using the filter set
$filearray = FileOpenDialog("Select data files to process", $selectfolder, "Data (*.dat;*.img)", 4)
if @error then Exit

; read the files just selected into an array
_FileReadToArray($selectfolder, $filearray)

MsgBox(0, "Array check 1", "$selectfolder")
MsgBox(0, "Array check 2", "$filearray")

Thanks again for your help! I will gladly take any criticism or suggestions!

Kudos for working on it and posting code to illustrate your issue! Here's a tweak with some debug info presented for testing:
#include <File.au3>
#include <Array.au3>

; declare an array to hold each file to be input
Dim $aFileArray

; select the folder with the data in it.
$sSelectFolder = FileSelectFolder("Choose the folder location for your data", "")
If @error Then Exit
ConsoleWrite("Debug:  $sSelectFolder = " & $sSelectFolder & @LF)

; select multiple files in the folder previously specified using the filter set
$sSelectFile = FileOpenDialog("Select data files to process", $sSelectFolder, "Data (*.dat;*.img)|All Files (*.*)", 4)
If @error Then Exit
ConsoleWrite("Debug:  $sSelectFile = " & $sSelectFile & @LF)

; Create array from string of selections
$aFileArray = StringSplit($sSelectFile, "|")
_ArrayDisplay($aFileArray, "Debug: $aFileArray")

:D

P.S. If you already have an array, and want to add another array's contents to it, look at _ArrayConcatenate() (see help file).

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

PsaltyDS,

Thanks for the quick response! Your comments make a lot of sense to me. I tried out the suggestions you made to my code, and it works great. Like you mentioned, I am more interested in learning concepts and the proper way to code than have solutions given to me. Programming is funny, as it is a series of logical steps to solve a problem, however I don't always understand the logic :D. I'll get there though!

Thanks again

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...