Sign in to follow this  
Followers 0
triodz

Using array to call ini file for combobox list (Subscript used with non-Array variable error)

11 posts in this topic

#1 ·  Posted (edited)

FINAL EDIT: The answer you seek is at the

EDIT: It definitley has to do with any part of the code with this in it:

For $iX = 1 To $print[0][0]
GUICtrlSetData(-1, $print[$iX][0],"")
Next

which calls on this:

$print = IniReadSection(".ifileprinterlist.ini","PRINTERS")

I commented all of the arrays and it worked fine. So I guess i need to figure out what I'm doing wrong here.

END EDIT

MORE EDITS

I used a totally different array and it still fails when trying to runas.

I tried to runas using a command prompt and it failed with the same error again.

I have no idea whats going on. It may be something to do with the Include file Array.au3. I am going to go that way next.

END MORE EDITS

**********************************************************************************************************************

I am just wondering if the below code is, in fact, correct (the way that the combolists are getting information from the ini files):

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
$print = IniReadSection(".ifileprinterlist.ini","PRINTERS")
$port = IniReadSection(".ifileportlist.ini","PORTS")
$queue = IniReadSection(".ifilequeuelist.ini","QUEUE")
$queuemini = IniReadSection(".ifilequeuelist2.ini","QUEUE")
globaL $PrintGUI = GUICreate("Printer Installation Assistant", 530, 349, 192, 114)
GUISetBkColor(0xA6CAF0)
$EnterPC = GUICtrlCreateInput("", 160, 45, 225, 21)
$PCNum = GUICtrlCreateLabel("Enter PC number:", 18, 49, 107, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$PrintCombo = GUICtrlCreateCombo("", 160, 77, 225, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
For $iX = 1 To $print[0][0]
GUICtrlSetData(-1, $print[$iX][0],"")
Next
$PortCombo = GUICtrlCreateCombo("", 160, 110, 225, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
For $iY = 1 To $port[0][0]
GUICtrlSetData(-1, $port[$iY][0],"")
Next
$QueueCombo = GUICtrlCreateCombo("", 160, 141, 225, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
For $iZ = 1 To $queue[0][0]
GUICtrlSetData(-1, $queue[$iZ][0],"")
Next

I am trying to use this code:

CredCheckPrint.au3

to call this code:

Printer Install.au3

as an adminstrator. What I have posted above is the the first part of Printer Install.au3.

When Printer Install.au3 is run on its own (compiled or uncompiled), it works absolutely perfectly. If I try to runas from the CredCheckPrint.au3 file, it fails with "Subscript used with non-Array variable error". It cites line 1591 of the Printer Install script as the culprit, but this line does not exist.

I can use the CredCheck script to run other scripts with no issue.

If I right click Printer Install and Run as an admin manually, it works fine.

I am at a loss and I know there is something in the way I have used the array that is not working. There are more combo boxes further down the script (different GUI's) that use the same method as is shown above.

I know very little about arrays and have borrowed this from someone on this forum. Once I get this working I am going to post and credit it to who I borrowed it from.

Thanks in advance for any help.

Edit: Needed to make more sense at the beginning.

Edited by triodz

Share this post


Link to post
Share on other sites



Thanks Aipion. I wish i could try this, but my work proxy has blocked your site. Nothing personal, our filters are just really paranoid! I think it picked up the .co.cc domain and slammed down the iron door of fear!

Is it possible to post the au3 file? Thanks again

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Still happening :)

Here is the error that happens EVERY time. It is always the same (with yours and mine).

Posted Image

I can see what you were doing with the ini files, too. I didn't have anything in the "value" field for a couple of them. Made no difference though unfortunately.

As mentioned above, ONLY happens when I try and run as from a different autoit script (compiled or uncompiled) or runas with a command prompt. If I right click and Run As a different user, it works perfectly fine.

Thanks a million for you input though Aipion.

My head will now explode...

Edited by triodz

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

The Error is mainly coming because it can't find the file therefore it can't create the array.

Do know in your script you have those "." in the location of the ini files: ".ifileprinterlist.ini", instead of that lets use the below code.

@ScriptDir&"ifileprinterlist.ini"
Edited by Aipion

Share this post


Link to post
Share on other sites

Thanks, but I have picked up on this and tried with the ini file in the same folder as the script and withwithout the "." in front. Still fails with the same error.

I am now resorting to finding a way without using arrays. Maybe using filereadline, but it only reads one line. Ah well. Another journey to undertake!

Share this post


Link to post
Share on other sites

You need to add some debugging to your script to see WHY it's failing with the arrays. Put an _ArrayDisplay after every IniReadSection with the array name being used to see what your arrays contain before trying to work with them. There might be a clue as to why it's failing there. Also, put your cursor on each of the array variables and press ALT-D to create a debug to console line for each of your arrays, see if there's an error returned. Right now you have no idea why its failing, just that it is.

Fix the problem with the arrays before trying anything else because you're going about it the wrong way.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Hi BrewManNH,

I added what you suggested, as such:

$print = IniReadSection(".printerlist.ini","PRINTERS")
_ArrayDisplay ($print)

and:

$PrintCombo = GUICtrlCreateCombo("", 160, 77, 225, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
For $iX = 1 To $print[0][0]
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') :  $iX = ' &  $iX & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
GUICtrlSetData(-1, $print[$iX][0],"")
Next

When run uncompiled, the array displays perfectly, with no debug errors at all.

Unfortunately, the same error came up when trying to runas the Printer Install script when it is compiled. So it does not even open it to debug it. As stated before, when run from the au3 file or if I run the exe just by double clicking on it, there are no errors. So nothing to debug.

Thanks for the hints though.

I ended up trying this in place of the arrays:

$PrintCombo = GUICtrlCreateCombo("", 160, 77, 225, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$file = FileOpen("printerlist.txt", 0)
$lineComplete = ""
while 1
    $line = FileReadLine($file)
 If @error = -1 Then ExitLoop
    $lineComplete = $lineComplete & $line
 GUICtrlSetData(-1,$lineComplete)
WEnd
 FileClose($file)

Now it does not show the error when using runas. Instead, I see the autoit icon in the system tray, but it does not open the GUI! Gah!!

Edited by triodz

Share this post


Link to post
Share on other sites

If you're running it compiled, try substituting the consolewrite debug with the msgbox debug to see what you're getting, as well as the _ArrayDisplay. It could be that it's not finding the ini file.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I FIGURED IT OUT!! OMG I THOUGHT MY HEAD WOULD ASPLODE AND EVERYONE AROUND ME WOULD BE COVERED IN CONFUSED BRAIN GOO!

Right, now that excitement is out of the way:

BrewManNH, you are very right, but not in the way I (or perhaps you) are thinking.

I was wondering if the files were getting the same rights as the initial script calling on them. Our standard logon and our Admin logon (the reason I am creating this) are different - "username" for standard and "username_a" for admin. So if the script is being opened with the "username_a", then calling on files that have not inherited the same rights, it will fail. Because these files are a part of the array, said annoying-as-hell error appears.

So what to do? Look at the Logon script (CredCheckPrint) that calls the script I want to run!

In this script, I had this:

case $ok
   If _ValidUserPass($usera, $computer, $passa) = True Then
    Ini_Write("Password","c:cred3.ini","Section","Key",$passa) ;    
    RunAs($usera, $computer, $passa,0,@ScriptDir&"test3.exe")
    ExitLoop
   Else

for when the OK button was pressed.

I changed the RunAs line to this:

RunAs($usera, $computer, $passa,0,@ScriptDir&"test3.exe",@ScriptDir,"",0x1)

Help file states: 0x1 ($STDIN_CHILD) = Provide a handle to the child's STDIN stream

My interpretation of this is that the credentials used will also also be used for any files the script calls on. Which is what i need.

Works beautifully! When I have this completed and working, I am going to post for use by others as it really is going to be a useful script in an environment that only uses admin logons when troubleshooting users PC's. It will allow automation of any script yiou create that needs to be run as admin. And the printing script may come in handy too!

Thanks SO MUCH for the help you have both provided! Once again this community shows its awesomeness.

Edited by triodz

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