Sign in to follow this  
Followers 0
maqleod

Error: Subscript used with non-Array Variable

6 posts in this topic

#1 ·  Posted (edited)

Ok, here's the deal, I had this script working beautifully and then I added a fileopendialog option to send data from the dialog to an input control just to make things a little easier on the operator. After getting this working I tested it and a completely unrelated error popped up (or at least I don't see why it's related)

The script is as follows:

#include <GUIConstants.au3>

Break(1)

Assign("name","LaunchDock 0.2")

$background = IniReadSection("config.ini", "Background")

$xy = IniReadSection("config.ini", "Position")

$tips = IniReadSectionNames("config.ini")

$parent = GUICreate($name, 210, 210, $xy[1][1], $xy[2][1],-1)

$contextmenu = GUICtrlCreateContextMenu ()

Opt("GUICoordMode",2)

Opt("RunErrorsFatal", 0)

Opt("GUICloseOnESC", 0)

Opt("WinTitleMatchMode", 2)

$fileopt = GUICtrlCreateMenu ("&File")

$ontopitem = GUICtrlCreateMenuitem ("Always On Top",$fileopt)

$top = IniReadSection("config.ini", "AlwaysOnTop")

if $top[1][1] = 0 then

GUICtrlSetState(-1,$GUI_UNCHECKED)

elseif $top[1][1] = 1 then

GUICtrlSetState(-1,$GUI_CHECKED)

WinSetOnTop($name, "", 1)

endif

$restartitem = GUICtrlCreateMenuitem ("Restart",$fileopt)

$exititem = GUICtrlCreateMenuitem ("Exit",$fileopt)

$configopt = GUICtrlCreateMenu ("Configure")

$toggleitem = GUICtrlCreateMenuitem ("Start On Boot",$configopt)

$reg = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "LaunchDock")

if $reg = @ScriptFullPath then

GUICtrlSetState(-1,$GUI_CHECKED)

elseif $reg <> @ScriptFullPath then

GUICtrlSetState(-1,$GUI_UNCHECKED)

endif

$strtpositem = GUICtrlCreateMenuitem ("Startup Position",$configopt)

$buttonsitem = GUICtrlCreateMenuitem ("Buttons",$configopt)

$bkcoloritem = GUICtrlCreateMenuitem ("Background Color",$configopt)

$transitem = GUICtrlCreateMenuitem ("Set Transparency",$configopt)

$helpopt = GUICtrlCreateMenu ("About")

$aboutitem = GUICtrlCreateMenuitem ("About",$helpopt)

$configmenu = GUICtrlCreateMenu ("Configure", $contextmenu)

$toggle = GUICtrlCreateMenuItem ("Toggle Startup", $configmenu)

$strtpos = GUICtrlCreateMenuItem ("Startup Position", $configmenu)

$buttons = GUICtrlCreateMenuItem ("Buttons", $configmenu)

$bkcolor = GUICtrlCreateMenuItem ("Background Color", $configmenu)

$trans = GUICtrlCreateMenuItem ("Set Transparency", $configmenu)

$ontop = GUICtrlCreateMenuItem ("Toggle Always On Top", $contextmenu)

$about = GUICtrlCreateMenuItem ("About", $contextmenu)

$restart = GUICtrlCreateMenuItem ("Restart", $contextmenu)

$exit = GUICtrlCreateMenuItem ("Exit", $contextmenu)

$but1opt1 = IniReadSection("config.ini", "Button 1")

$but2opt1 = IniReadSection("config.ini", "Button 2")

$but3opt1 = IniReadSection("config.ini", "Button 3")

$but4opt1 = IniReadSection("config.ini", "Button 4")

$but5opt1 = IniReadSection("config.ini", "Button 5")

$but6opt1 = IniReadSection("config.ini", "Button 6")

$but7opt1 = IniReadSection("config.ini", "Button 7")

$but8opt1 = IniReadSection("config.ini", "Button 8")

$but9opt1 = IniReadSection("config.ini", "Button 9")

$but1 = GUICtrlCreateButton ("1", 35, 35, 32, 32,$BS_ICON)

GUICtrlSetImage (-1, $but1opt1[2][1])

GUICtrlSetTip(-1, $tips[1] & ": " & $but1opt1[1][1])

$but2 = GUICtrlCreateButton ("2", 20, -32, 32, 32,$BS_ICON)

GUICtrlSetImage (-1, $but2opt1[2][1])

GUICtrlSetTip(-1, $tips[2] & ": " & $but2opt1[1][1])

$but3 = GUICtrlCreateButton ("3", 20, -32, 32, 32,$BS_ICON)

GUICtrlSetImage (-1, $but3opt1[2][1])

GUICtrlSetTip(-1, $tips[3] & ": " & $but3opt1[1][1])

$but4 = GUICtrlCreateButton ("4", -137, 15, 32, 32,$BS_ICON)

GUICtrlSetImage (-1, $but4opt1[2][1])

GUICtrlSetTip(-1, $tips[4] & ": " & $but4opt1[1][1])

$but5 = GUICtrlCreateButton ("5", 20, -32, 32, 32,$BS_ICON)

GUICtrlSetImage (-1, $but5opt1[2][1])

GUICtrlSetTip(-1, $tips[5] & ": " & $but5opt1[1][1])

$but6 = GUICtrlCreateButton ("6", 20, -32, 32, 32,$BS_ICON)

GUICtrlSetImage (-1, $but6opt1[2][1])

GUICtrlSetTip(-1, $tips[6] & ": " & $but6opt1[1][1])

$but7 = GUICtrlCreateButton ("7", -137, 15, 32, 32,$BS_ICON)

GUICtrlSetImage (-1, $but7opt1[2][1])

GUICtrlSetTip(-1, $tips[7] & ": " & $but7opt1[1][1])

$but8 = GUICtrlCreateButton ("8", 20, -32, 32, 32,$BS_ICON)

GUICtrlSetImage (-1, $but8opt1[2][1])

GUICtrlSetTip(-1, $tips[8] & ": " & $but8opt1[1][1])

$but9 = GUICtrlCreateButton ("9", 20, -32, 32, 32,$BS_ICON)

GUICtrlSetImage (-1, $but9opt1[2][1])

GUICtrlSetTip(-1, $tips[9] & ": " & $but9opt1[1][1])

HotKeySet("+!1","Button1")

HotKeySet("+!2","Button2")

HotKeySet("+!3","Button3")

HotKeySet("+!4","Button4")

HotKeySet("+!5","Button5")

HotKeySet("+!6","Button6")

HotKeySet("+!7","Button7")

HotKeySet("+!8","Button8")

HotKeySet("+!9","Button9")

Func Button1()

Run($but1opt1[2][1])

EndFunc

Func Button2()

Run($but2opt1[2][1])

EndFunc

Func Button3()

Run($but3opt1[2][1])

EndFunc

Func Button4()

Run($but4opt1[2][1])

EndFunc

Func Button5()

Run($but5opt1[2][1])

EndFunc

Func Button6()

Run($but6opt1[2][1])

EndFunc

Func Button7()

Run($but7opt1[2][1])

EndFunc

Func Button8()

Run($but8opt1[2][1])

EndFunc

Func Button9()

Run($but9opt1[2][1])

EndFunc

GUISetBkColor($background[1][1])

GUISetState()

Do

$transdata = IniReadSection("config.ini", "Transparency")

WinSetTrans($name,"", $transdata[1][1])

$msg = GUIGetMsg()

if $msg = $ontop or $msg = $ontopitem then

if BitAnd(GUICtrlRead($ontopitem),$GUI_CHECKED) = $GUI_CHECKED Then

GUICtrlSetState($ontopitem,$GUI_UNCHECKED)

IniWrite("config.ini", "AlwaysOnTop", "Value", "0")

WinSetOnTop("", "", 0)

else

GUICtrlSetState($ontopitem,$GUI_CHECKED)

IniWrite("config.ini", "AlwaysOnTop", "Value", "1")

WinSetOnTop("", "", 1)

endif

endif

if $msg = $toggle or $msg = $toggleitem then

if BitAnd(GUICtrlRead($toggleitem),$GUI_CHECKED) = $GUI_CHECKED Then

GUICtrlSetState($toggleitem,$GUI_UNCHECKED)

RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "LaunchDock")

else

GUICtrlSetState($toggleitem,$GUI_CHECKED)

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "LaunchDock", "REG_SZ",

@ScriptFullPath)

endIf

endif

if $msg = $strtpos or $msg = $strtpositem then

$child1 = GUICreate("Configure Startup", 275, 175, -1, -1, -1, $parent)

Opt("RunErrorsFatal", 0)

GUICtrlCreateLabel ("X Coordinates:", 20, 40, 70,70)

$xchange = GUICtrlCreateInput( $xy[1][1], 20, -75, 75, 20)

GUICtrlCreateLabel ("Y Coordinates:", -165, 20, 70,70)

$ychange = GUICtrlCreateInput( $xy[2][1], 20, -75, 75, 20)

$xychange = GUICtrlCreateButton ("OK", 10, 20, 75)

GUISetState()

Do

$msg1 = GUIGetMsg()

if $msg1 = $xychange then

IniWrite("config.ini", "Position", "x", GUICtrlRead($xchange))

IniWrite("config.ini", "Position", "y", GUICtrlRead($ychange))

MsgBox(64,"Notice","You must restart LaunchDock for changes to take effect")

ExitLoop

endif

Until $msg1 = $GUI_EVENT_CLOSE

GUIDelete()

endif

if $msg = $buttons or $msg = $buttonsitem then

$child2 = GUICreate("Configure Buttons", 275, 175, -1, -1, -1, $WS_EX_ACCEPTFILES, $parent)

Opt("RunErrorsFatal", 0)

GUICtrlCreateLabel ("Choose a Button:", 20, 10, 70,70)

$buttonchange = GUICtrlCreateCombo ("Button 1", 10, -55, 75, 20,$CBS_DROPDOWNLIST)

GUICtrlSetData(-1,"Button 2|Button 3|Button 4|Button 5|Button 6|Button 7|Button 8|Button 9","Button 1")

GUICtrlCreateLabel ("Enter The Program Name:", -155, 10, 70,70)

$namechange = GUICtrlCreateInput( "", 10, -55, 75, 20)

GUICtrlCreateLabel ("Enter The Program Path:", -155, 10, 70,70)

$pathchange = GUICtrlCreateInput( "", 10, -55, 75, 20)

GUICtrlSetState(-1,$GUI_ACCEPTFILES)

$fileopen = GUICtrlCreateButton ("...", 5, -20, 25,25)

$change = GUICtrlCreateButton ("OK", -35, 10, 75,25 )

GUISetState()

Do

$msg2 = GUIGetMsg()

if $msg2 = $fileopen then

$file = FileOpenDialog("Select Program", "C:\Program Files\", "Executables (*.exe;*.bat;*.com;*.pif)", 5)

GUICtrlSetData($pathchange,$file,"")

endif

if $msg2 = $change then

IniWrite("config.ini", GUICtrlRead($buttonchange), "Button Name", GUICtrlRead($namechange))

IniWrite("config.ini", GUICtrlRead($buttonchange), "Path", GUICtrlRead($pathchange))

MsgBox(64,"Notice","You must restart LaunchDock for changes to take effect")

ExitLoop

endif

Until $msg2 = $GUI_EVENT_CLOSE

GUIDelete()

endif

if $msg = $bkcolor or $msg = $bkcoloritem then

$child5 = GUICreate("Change Background Color", 275, 175, -1, -1, -1, $WS_EX_ACCEPTFILES, $parent)

Opt("RunErrorsFatal", 0)

GUICtrlCreateLabel ("Choose a Color:", 40, 50, 110,70)

$bkcolorchange = GUICtrlCreateCombo ("Black", 10, -65, 75,20,$CBS_DROPDOWNLIST)

GUICtrlSetData(-1,"Blue|Red|Green|Yellow|Purple|Gray|White|Orange","Button 1")

$colorok = GUICtrlCreateButton ("OK", -70, 40, 75,25)

GUISetState()

Do

$msg5 = GUIGetMsg()

if $msg5 = $colorok then

$newcolour = GUICtrlRead($bkcolorchange)

if $newcolour = "Black" then

Assign("newcolor","0x000000")

elseif $newcolour = "Blue" then

Assign("newcolour","0x0000FF")

elseif $newcolour = "Red" then

Assign("newcolor","0xFF0000")

elseif $newcolour = "Green" then

Assign("newcolor","0x009900")

elseif $newcolour = "Yellow" then

Assign("newcolor","0xFFFF00")

elseif $newcolour = "Purple" then

Assign("newcolor","0x660099")

elseif $newcolour = "Gray" then

Assign("newcolor","0x999999")

elseif $newcolour = "White" then

Assign("newcolor","0xFFFFFF")

elseif $newcolour = "Orange" then

Assign("newcolor","0xFF9900")

endif

IniWrite("config.ini", "Background", "Color", $newcolor)

MsgBox(64,"Notice","You must restart LaunchDock for changes to take effect")

ExitLoop

endif

Until $msg5 = $GUI_EVENT_CLOSE

GUIDelete()

endif

if $msg = $trans or $msg = $transitem then

$child3 = GUICreate("Set Transparency", 275, 175, -1, -1, -1, $parent)

Opt("RunErrorsFatal", 0)

GUICtrlCreateLabel ("Enter Transparency Value (0-254):", 40, 50, 110,70)

$settrans = GUICtrlCreateInput($transdata[1][1], 10, -65, 75,20)

$transok = GUICtrlCreateButton ("OK", -70, 40, 75,25)

GUISetState()

Do

$msg3 = GUIGetMsg()

if $msg3 = $transok then

IniWrite("config.ini", "Transparency", "Value", GUICtrlRead($settrans))

WinSetTrans($name,"", $transdata[1][1])

ExitLoop

endif

Until $msg3 = $GUI_EVENT_CLOSE

GUIDelete()

endif

if $msg = $about or $msg = $aboutitem then

$child4 = GUICreate("About", 275, 175, -1, -1, -1, $parent)

$font = "Ariel"

Opt("RunErrorsFatal", 0)

GUICtrlCreateLabel ($name, 90, 20, 150,30)

GUICtrlSetFont (-1,10, 400, $font)

GUICtrlCreateLabel ("by Jared Epstein", -140, 10, 150,30)

GUICtrlSetFont (-1,10, 400, $font)

$aboutok = GUICtrlCreateButton ("OK", -140, 30, 75,25)

GUISetState()

Do

$msg4 = GUIGetMsg()

if $msg4 = $aboutok then

ExitLoop

endif

Until $msg4 = $GUI_EVENT_CLOSE

GUIDelete()

endif

if $msg = $restart or $msg = $restartitem then

Run(@ScriptFullPath)

ExitLoop

endif

if $msg = $exit or $msg = $exititem then

ExitLoop

endif

if $msg = $but1 then

Run($but1opt1[2][1])

endif

if $msg = $but2 then

Run($but2opt1[2][1])

endif

if $msg = $but3 then

Run($but3opt1[2][1])

endif

if $msg = $but4 then

Run($but4opt1[2][1])

endif

if $msg = $but5 then

Run($but5opt1[2][1])

endif

if $msg = $but6 then

Run($but6opt1[2][1])

endif

if $msg = $but7 then

Run($but7opt1[2][1])

endif

if $msg = $but8 then

Run($but8opt1[2][1])

endif

if $msg = $but9 then

Run($but9opt1[2][1])

endif

Until $msg = $GUI_EVENT_CLOSE

The error message is as follows:

Line 143 (File "C:\...\Launchdock.au3)

WinSetTrans($name,"",$transdata[1][1])

WinSetTrans($name,"",$transdata^ERROR

Error: Subscript used with non-Array Variable

Now I only get this error when I open up the script and open up the configuration gui and actually use the fileopendialog within the gui. I don't know why I'm getting an error that says that $transdata[1][1] a non-array variable because it's being pulled from here: $transdata = IniReadSection("config.ini", "Transparency"), nor do I know why the error is related to the fileopendialog function.

Any help would be greatly appreciated

maqleod

here's the config.ini details:

[button 1]

Button Name=

Path=

[button 2]

Button Name=

Path=

[button 3]

Button Name=t

Path=

[button 4]

Button Name=

Path=

[button 5]

Button Name=

Path=

[button 6]

Button Name=

Path=

[button 7]

Button Name=

Path=

[button 8]

Button Name=

Path=

[button 9]

Button Name=

Path=

[Position]

x=0

y=25

[AlwaysOnTop]

Value=0

[Transparency]

Value=254

Color=0x999999

Edited by maqleod

[u]You can download my projects at:[/u] Pulsar Software

Share this post


Link to post
Share on other sites



Just running on assumption here...

The FileOpenDialog will change your working directory. Since you don't supply a path to the IniReadSection, it's probably defaulting to the script directory. After using your FileOpenDialog, the working directory changes to the directory to whatever file you opened, and can't find the "config.ini", and spits an error back at you.

After this line:

$transdata = IniReadSection("config.ini", "Transparency")

Try doing some error checking.

(Also, try wrapping your code with the [ code ] bbtags)

Share this post


Link to post
Share on other sites

yup, that was it, I just added

FileChangeDir(@ScriptDir)

after the fileopendialog section and it works just fine, thanks


[u]You can download my projects at:[/u] Pulsar Software

Share this post


Link to post
Share on other sites

Hi,

I've been trying to run kylomas script lodged here and I'm getting the same error.as in this thread.

>"N:\JKMPrivate\Utils\AutoIT\SciTe\..\autoit3.exe" /ErrorStdOut "D:\Profiles\kristian\Desktop\Setanta\kylomasRevisedScriptMod01.au3"    
D:\Profiles\kristian\Desktop\Setanta\kylomasRevisedScriptMod01.au3 (107) : ==> Subscript used with non-Array variable.:
local $fl = fileopen("C:\Users\Kristian\Desktop\Setanta\cache\TVxb-setanta.hk-" & stringright($savedate[0],6),2)
local $fl = fileopen("C:\Users\Kristian\Desktop\Setanta\cache\TVxb-setanta.hk-" & stringright($savedate^ ERROR
>Exit code: 1    Time: 31.964

This thread was the only one with a fix.

So I added

FileChangeDir(@ScriptDir)

after each of the 3# fileopendialog sections but it still bombs out with the same error message?

kylomasRevisedScriptMod01.au3

Share this post


Link to post
Share on other sites

jksmurf,

Why reopen a thread over 5 years old when you already have a thread running on the very code you are trying to debug? :)

And what on earth makes you think that your error has anything to do with FileOpenDialog? :)

The error message shows quite clearly that the error occurs because $savedate is not an array. Looking at the code you are using (assuming it is that posted in the other thread) shows that the variable is created by this line:

$savedate = stringregexp($shtml, 'class=selected><A(.+?)'', ''Tab-Date',3)

The SRE is obviously failing (you can check for @error to find out why) and so you do not get an array to use in the line which produces the error when it tries to read the array element. You should always use errorcheck code to check that you have an array before trying to access its elements to prevent crashes like this. I suggest you go back to the thread you were using and ask the author to help you debug his code. :P

And do not resurrect off-topic ancient history threads again. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hi Melba23,

:):)

I'm really sorry for that, the example scripts thread make it clear it's not a support forum, so could not post there and I wanted to show I really had tried to look for the solution myself before asking. I will open a new thread next time, I promise! I assume it's OK to continue this now though?

I guess the reason why I thought it was with the FileOpenDialog was simply that mines appeared (to me) was the same error that this fellow got, with the same FileOpenDialog command.

Will check with the author,

Cheers

k.

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