Jump to content

How to use an external file with an array ?


Recommended Posts

Hi,

I'm new to this:

I have an external file with three arrays. (teams.txt)

These arrays change every time, so I cannot #include them because I want to compile the script

Is there another way to get them active in my AutoIT script.

array looks like:

Dim $clubteams[6]

$clubteams[1] = " 'ASV Toppers' "

$clubteams[2] = " 'ASV Knallers' "

$clubteams[3] = " 'ASV Vechters' "

$clubteams[4] = " 'De Zalmen' "

$clubteams[5] = " 'ASV Halfjes' "

Dim equipes

Dim teams(13)

teams[0] = " '6 kluge Leute' "

teams[1] = " 'Collewijn 2' "

teams[2] = " 'Dynamic Drives SC' "

teams[3] = " 'Dynamic Drives Sport' "

... and so on

code to get things going:

; Open a connection to the database

$objConn = ObjCreate("ADODB.Connection")

$objConn.Open ("Driver={Microsoft Excel Driver (*.xls)}; DriverId=790; Dbq=asvmail.xls;" )

$file = FileOpen("results.html", 2)

For $i = 1 To ubound($clubteams)-1

$strSQL = "SELECT * FROM [asvmail$] WHERE clubteam = " & $clubteams[$i] & " ORDER BY rang ASC; "

$objRst = $objConn.execute($strSQL)

$team = StringReplace($clubteams[$i], "'", "")

FileWrite($file, "<tr><td colspan=5><h2> &nbsp; &nbsp; " & $i & ". &nbsp; &nbsp; " & $team)

$count = 1

With $objRst

While Not .EOF

FileWrite($file, "<tr><td>" & $count & @CRLF)

FileWrite($file, "<td>" & $objRst("bestuurder").value & @CRLF)

FileWrite($file, "<td>" & $objRst("navigator").value )

FileWrite($file, "<td>" & $objRst("pnt").value )

$count += 1

.MoveNext

WEnd

EndWith

$objRst.Close

============================================

Who knows the solution ???

Thanks

Najaden

Link to comment
Share on other sites

Hi,

where ist the problem? Why not saving the arrays and then reading them in your script.exe to work with them?

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

I'm new to this:

I have an external file with three arrays. (teams.txt)

These arrays change every time, so I cannot #include them because I want to compile the script

Is there another way to get them active in my AutoIT script.

array looks like:

Dim $clubteams[6]
$clubteams[1] = " 'ASV Toppers' "  
$clubteams[2] = " 'ASV Knallers' "  
$clubteams[3] = " 'ASV Vechters' " 
$clubteams[4] = " 'De Zalmen' "   
$clubteams[5] = " 'ASV Halfjes' "

Dim equipes
Dim teams(13)
teams[0] =  " '6 kluge Leute' "
teams[1] =  " 'Collewijn 2' "
teams[2] =  " 'Dynamic Drives SC' "
teams[3] =  " 'Dynamic Drives Sport' "

... and so on

code to get things going:

CODE
; Open a connection to the database

$objConn = ObjCreate("ADODB.Connection")

$objConn.Open ("Driver={Microsoft Excel Driver (*.xls)}; DriverId=790; Dbq=asvmail.xls;" )

$file = FileOpen("results.html", 2)

For $i = 1 To ubound($clubteams)-1

$strSQL = "SELECT * FROM [asvmail$] WHERE clubteam = " & $clubteams[$i] & " ORDER BY rang ASC; "

$objRst = $objConn.execute($strSQL)

$team = StringReplace($clubteams[$i], "'", "")

FileWrite($file, "<tr><td colspan=5><h2> &nbsp; &nbsp; " & $i & ". &nbsp; &nbsp; " & $team)

$count = 1

With $objRst

While Not .EOF

FileWrite($file, "<tr><td>" & $count & @CRLF)

FileWrite($file, "<td>" & $objRst("bestuurder").value & @CRLF)

FileWrite($file, "<td>" & $objRst("navigator").value )

FileWrite($file, "<td>" & $objRst("pnt").value )

$count += 1

.MoveNext

WEnd

EndWith

$objRst.Close

Who knows the solution ???

Thanks

Najaden

So, you need to read the data from a .txt file? Why format it as though it was AutoIT code, when it won't get executed? Wouldn't an .ini file be ever-so-much-easier? Read with IniReadSection(), like this:

; Teams.ini

[ClubTeams]
Team = ASV Toppers
Team = ASV Knallers
Team = ASV Vechters
Team = De Zalmen
Team = ASV Halfjes

[Teams]
Team =  6 kluge Leute
Team =  Collewijn 2
Team =  Dynamic Drives SC
Team =  Dynamic Drives Sport

Then, in your script you put:

$ClubTeams = IniReadSection("Teams.ini", "ClubTeams")
Dim $equipes
$Teams = IniReadSection("Teams.ini", "Teams")

And your data is ready to read in the arrays.

Please explain if I missed your point... :D

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

Hi,

do it as PsaltyDS said, or upload an example txt and maybe tell us what you wanna do after you've read the information out of the arrays.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

in the BETA version you have 2 good commands for the process you require.

Look them up in help file:

#include<File.au3>

_FileReadToArray("test.txt",$a_Test) ; read in your team data to an array

_FileWriteFromArray("test2.txt",$a_Test,1) ; save your teamdata array to a file.

HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
Share on other sites

in the BETA version you have 2 good commands for the process you require.

Look them up in help file:

#include<File.au3>

_FileReadToArray("test.txt",$a_Test) ; read in your team data to an array

_FileWriteFromArray("test2.txt",$a_Test,1) ; save your teamdata array to a file.

HardCopy

Hi,

Thanks!

That's precisely what I'm looking for ...

Najaden

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...