Jump to content
Sign in to follow this  
Nomis

For trickery

Recommended Posts

Nomis

Morning all i was wondering if anyone could help,

Before I start I may be pushing the limits of what the For command can do and I may be using the For command incorrectly so here goes, I’m having an issue with an app I'm building; the reason for the app is to execute the multiple install .exe files in a predetermined order to be deployed via Active Directory and a custom MSI.

I have the Autoit script doing what I want, passing each element in the ini file to within a single command so the first output would be a combination of App01 ans CLI01 from the ini file, but after it processing’s the information is errors with the following so it fails when that are no more things to process:

==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

MsgBox(4096, "Install", $InstallApp[$i][1] & @CR & $InstallCLI[$i][1])

MsgBox(4096, "Install", ^ ERROR

I will when I get is working change the MSGBOX to the ShellExecuteWait command I just want to get to working first.

The way I would like it to work is the following way: an ini file containing multiple sets 3 variables needed to install the .exe file (App Name, Any command line options & the Working Directory) these variables are then used in a single line (ShellExecuteWait) and this is processed until end of file.

INI File

[Application]

Appname=Application01

[EXE_App]

App01=Setup.exe

App02=Install.exe

App03=Setup.exe

App04=Setup.exe

[EXE_CLI]

CLI01=/q

CLI02=/silent

CLI03=/q

CLI04=/passive

[EXE_Wdir] ; Working Directory is relative to the ScriptDir

Wdir01=\App01\

Wdir02=\App02\

Wdir03=\App03\

Wdir04=\App04\

Autoit Script

#NoTrayIcon
#include <file.au3>
Opt("GUICloseOnESC", 1)
Opt('MustDeclareVars', 1)

Global $RNum, $InstallApp, $InstallCLI, $InstallWDir, $Appname

$RNum = Random(500, 3000, 1)
$InstallAPP = IniReadSection(@ScriptDir & "\Control.ini", "EXE_App") 
$InstallCLI = IniReadSection(@ScriptDir & "\Control.ini", "EXE_CLI") 
$InstallWDir = IniReadSection(@ScriptDir & "\Control.ini", "EXE_Wdir") 
$Appname = IniReadSection(@ScriptDir & "\Control.ini", "Application") 

Sleep($RNum)
If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
For $i = 1 To $InstallApp[0][0] & $InstallCLI[0][0]
    MsgBox(4096, "Install", $InstallApp[$i][1] & @CR & $InstallCLI[$i][1])
Next
EndIf
Exit

Share this post


Link to post
Share on other sites
UEZ

The problem is your for/next loop because $InstallApp[0][0] & $InstallCLI[0][0] = 4 & 4 -> 44 but you have only 4 elements in your ini section.

Correct is:

For $i = 1 To $InstallApp[0][0]
    MsgBox(4096, "Install", $InstallApp[$i][1] & @CR & $InstallCLI[$i][1])
Next

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
Nomis

The problem is your for/next loop because $InstallApp[0][0] & $InstallCLI[0][0] = 4 & 4 -> 44 but you have only 4 elements in your ini section.

Correct is:

For $i = 1 To $InstallApp[0][0]
    MsgBox(4096, "Install", $InstallApp[$i][1] & @CR & $InstallCLI[$i][1])
Next

Br,

UEZ

Hi UEZ, that did it thanks very much its been driving me mad. in sprit of learning ???$InstallApp[0][0] & $InstallCLI[0][0] = 4 & 4 -> 44 ??? how dose that work, this there a reference I can lookup??

Simon

Share this post


Link to post
Share on other sites
hannes08

Hi Simon,

in autoit a variable has no specified type so $var = 4 could be either an integer value or string for example.

So be combining two strings with the "&" operator you're getting a new string ( 4 & 4 => 44) which in this case will be interpreted as an integer value of 44.

Edit: The reference for this can be found in the help file under Operators and Variables.

:mellow:

Edited by Hannes123

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites
Nomis

Hi Hannes,

So sorry for being a little slow, but I take it $Var = 4 because I have 4 elements under the ini section and if I had 5 or 6 elements to the ini section the $var would = 5 or 6??, also I in my orginal script = 44 (I get that 4 & 4 = 44) is I had 44 elements to the ini section that would have worked ??

or am I simplifying it too much :mellow:

Thansk Simon

Share this post


Link to post
Share on other sites
hannes08

Hi Simon,

well yes and no :mellow:

$Var (Or $InstallApp[0][0]) is 4 because you have 4 elements in your ini file. Take a look at the IniReadSection() function in the helpfile.

But if you'd had 44 elements and you#d do $InstallApp[0][0] & $InstallCLI[0][0] you would have ended up counting to 4444.

Anyway if I take a closer look at your code it will fail if the number of entries in your ini sections EXE_App and EXE_CLI differ.

You might want to correct that with some error checks. :)


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.