Sign in to follow this  
Followers 0
duncanchaos

A strange "Subscript used with non-array variable" error

7 posts in this topic

I have written a script to control my Flexwriter DVD/CD copy/print station. The script runs fine when I run it from SciTE4 and gets no errors when it is compiled, but when I run the exe it immediately errors out with an Autoit error window:

The windows title is AutoIt Error

Line -1:

Error: Subscript used with non-array Variable.

I cannot figure out what is happening here, especially when the script runs fine from within the editor. I have copied my code into the post. There are 2 variables that capture array data. Any help would be appreciated.

CODE
#include <GUIConstants.au3>

#include <commMG.au3>

;create GUI

GUICreate("Flexwriter DVD Transfer",400,160)

;create target path button

$Button1 = GUICtrlCreateButton("Destination Path",10,70)

$lbltarget = GUICtrlCreateInput("",110,70,280)

;create source optical drive list

$drvlist = DriveGetDrive( "CDROM" )

$CmboSrcDrv = GUICtrlCreateCombo("",10,40,85)

For $pl = 1 To $drvlist[0]

GUICtrlSetData($CmboSrcDrv, $drvlist[$pl])

Next

GUICtrlSetData($CmboSrcDrv, $drvlist[1]);show the first DVD drive found

$CDDrive = GUICtrlRead(5);set variable

$lblSrcDrv = GUICtrlCreateLabel("Choose the DVD Source Drive", 110, 40)

;create COM port list

$portlist = _CommListPorts(0)

$CmboPortsAvailable = GUICtrlCreateCombo("", 10,10,85)

For $pl = 1 To $portlist[0]

GUICtrlSetData($CmboPortsAvailable, $portlist[$pl]);_CommListPorts())

Next

GUICtrlSetData($CmboPortsAvailable, $portlist[1]);show the first port found

$iPort = StringTrimLeft(GUICtrlRead(7),3);trim the COM from the String and set variable

$lblportlist = GUICtrlCreateLabel("Choose the Flexwriter COM port connection", 110, 10)

;create OK button

$ButtonOK = GUICtrlCreateButton("OK",10,120,190)

;create quit button

$ButtonQuit = GUICtrlCreateButton("Quit",200,120,190)

GUISetState()

Do

$Answr = GUIGetMsg()

Select

Case $Answr = $button1

Do

$target = FileSelectFolder("Select Image Folder", "", 1)

If @error Then

MsgBox(4096,"Warning 1","No Folder selected")

ExitLoop

Else

$YesNo = MsgBox(4132, "Confirm", $target & @CRLF & @CRLF & "Is this the correct folder?")

If $YesNo = 6 Then

$YesNo = "X"

GUICtrlSetData(4, $target)

EndIf

EndIf

Until $YesNo = "X"

Case $Answr = $CmboPortsAvailable

$iPort = StringTrimLeft(GUICtrlRead(7),3)

Case $Answr = $CmboSrcDrv

$CDDrive = GUICtrlRead(5)

Case $Answr = $ButtonQuit

Exit

Case $Answr = $ButtonOK

If $target = "" Then

MsgBox(0,"ERROR","No Target Folder selected")

Else

ExitLoop

EndIf

EndSelect

Until $Answr = $gui_event_close

;MsgBox(0,"Program Settings","Port is COM" & $iPort & @crlf & "DVD Drive is " & $CDDrive & @CRLF & "Target Folder is " & $target)

;open COM Port to connect to the Flexwriter

$sErr=0;set error variable

$msg =_CommSetPort($iPort,$sErr,9600,8,0,1,2)

if $msg=0 Then

msgbox(0,"COM Port Error",$sErr & @CRLF & "Please check selected COM port")

Exit

EndIf

;send activation string to flexwriter

$iWaitComplete=1

$msg = _CommSendString("v",$iWaitComplete)

Sleep(2000) ; 2seconds

$return = _Commgetstring()

GUISetState(@SW_HIDE)

GUICreate("DVD Transfer Status",400,160)

GUISetState()

$font="Arial Bold"

$lbl1 = GUICtrlCreateLabel("Please Wait" & @CRLF & "Currently copying the following DVD:",20,20,360,60,$SS_CENTER)

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

$lbl2 = GUICtrlCreateLabel("",20,100,360,60,$SS_CENTER)

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

GUISetState()

;Setup loop for disks

While 1

;send get disk and insert command

CDTray($CDDrive, "open")

$msg = _CommSendString("i",$iWaitComplete)

Do

$return = _Commgetstring()

Until $return <> ""

if $return = "E" Then

ExitLoop

EndIf

CDTray($CDDrive, "close")

Sleep(20000)

$drvstat = DriveStatus($CDDrive)

if $drvstat = "READY" Then

;check volume label. If label is empty then populate variable

$vollbl = DriveGetLabel($CDDrive)

If $vollbl = "" Then

$vollbl = "DVDMovie"

EndIf

;check to see if directory that matches vl exists and if so add count to vl

$lblcount=""

Do

$fileexist = FileExists($target & "\" & $vollbl & $lblcount)

if $fileexist=1 Then

$lblcount=$lblcount + 1

EndIf

Until $fileexist = 0

;copy the data to the target drive

GUICtrlSetData($lbl2,$vollbl & $lblcount)

DirCopy($CDDrive, $target & "\" & $vollbl & $lblcount, 1)

;send retrieve disk command

CDTray($CDDrive, "open")

$msg = _CommSendString("a",$iWaitComplete)

Do

$return = _Commgetstring()

Until $return <> ""

Else

; if the drive cannot read the disk correctly, remove and reject disk

CDTray($CDDrive, "open")

$msg = _CommSendString("p",$iWaitComplete)

Do

$return = _Commgetstring()

Until $return <> ""

if $return = "E" Then

ExitLoop

EndIf

CDTray($CDDrive, "close")

$msg = _CommSendString("h",$iWaitComplete)

Do

$return = _Commgetstring()

Until $return <> ""

if $return = "E" Then

ExitLoop

EndIf

EndIf

WEnd

CDTray($CDDrive, "close")

$msg = _CommClosePort()

Share this post


Link to post
Share on other sites



Ho, wellcome to the forums! :)

It's a little dificult to debug, because you have not provided the include file <commMG.au3>...

But here is a little fixed version, where i checked the array with Ubound:

#include <GUIConstants.au3>
#include <commMG.au3>

;create GUI
GUICreate("Flexwriter DVD Transfer", 400, 160)

;create target path button
$Button1 = GUICtrlCreateButton("Destination Path", 10, 70)
$lbltarget = GUICtrlCreateInput("", 110, 70, 280)

;create source optical drive list
$drvlist = DriveGetDrive("CDROM")
$CmboSrcDrv = GUICtrlCreateCombo("", 10, 40, 85)
For $pl = 1 To UBound($drvlist) - 1
    GUICtrlSetData($CmboSrcDrv, $drvlist[$pl])
Next
If UBound($drvlist) > 1 Then GUICtrlSetData($CmboSrcDrv, $drvlist[1]);show the first DVD drive found
$CDDrive = GUICtrlRead(5);set variable
$lblSrcDrv = GUICtrlCreateLabel("Choose the DVD Source Drive", 110, 40)


;create COM port list
$portlist = _CommListPorts (0)
$CmboPortsAvailable = GUICtrlCreateCombo("", 10, 10, 85)
For $pl = 1 To UBound($portlist) - 1
    GUICtrlSetData($CmboPortsAvailable, $portlist[$pl]);_CommListPorts())
Next
If UBound($portlist) > 1 Then GUICtrlSetData($CmboPortsAvailable, $portlist[1]);show the first port found
$iPort = StringTrimLeft(GUICtrlRead(7), 3);trim the COM from the String and set variable
$lblportlist = GUICtrlCreateLabel("Choose the Flexwriter COM port connection", 110, 10)

;create OK button
$ButtonOK = GUICtrlCreateButton("OK", 10, 120, 190)

;create quit button
$ButtonQuit = GUICtrlCreateButton("Quit", 200, 120, 190)

GUISetState()

Do
    $Answr = GUIGetMsg()

    Select

        Case $Answr = $Button1
            Do
                $target = FileSelectFolder("Select Image Folder", "", 1)
                If @error Then
                    MsgBox(4096, "Warning 1", "No Folder selected")
                    ExitLoop
                Else
                    $YesNo = MsgBox(4132, "Confirm", $target & @CRLF & @CRLF & "Is this the correct folder?")
                    If $YesNo = 6 Then
                        $YesNo = "X"
                        GUICtrlSetData(4, $target)
                    EndIf
                EndIf
            Until $YesNo = "X"

        Case $Answr = $CmboPortsAvailable
            $iPort = StringTrimLeft(GUICtrlRead(7), 3)

        Case $Answr = $CmboSrcDrv
            $CDDrive = GUICtrlRead(5)

        Case $Answr = $ButtonQuit
            Exit

        Case $Answr = $ButtonOK

            If $target = "" Then
                MsgBox(0, "ERROR", "No Target Folder selected")

            Else
                ExitLoop
            EndIf

    EndSelect


Until $Answr = $gui_event_close

;MsgBox(0,"Program Settings","Port is COM" & $iPort & @crlf & "DVD Drive is " & $CDDrive & @CRLF & "Target Folder is " & $target)

;open COM Port to connect to the Flexwriter
$sErr = 0;set error variable
$msg = _CommSetPort ($iPort, $sErr, 9600, 8, 0, 1, 2)

If $msg = 0 Then
    MsgBox(0, "COM Port Error", $sErr & @CRLF & "Please check selected COM port")
    Exit
EndIf

;send activation string to flexwriter
$iWaitComplete = 1
$msg = _CommSendString ("v", $iWaitComplete)
Sleep(2000) ; 2seconds
$return = _Commgetstring ()

GUISetState(@SW_HIDE)

GUICreate("DVD Transfer Status", 400, 160)
GUISetState()

$font = "Arial Bold"
$lbl1 = GUICtrlCreateLabel("Please Wait" & @CRLF & "Currently copying the following DVD:", 20, 20, 360, 60, $SS_CENTER)
GUICtrlSetFont(-1, 14, 400, 1, $font)
$lbl2 = GUICtrlCreateLabel("", 20, 100, 360, 60, $SS_CENTER)
GUICtrlSetFont(-1, 14, 400, 1, $font)

GUISetState()



;Setup loop for disks
While 1
    ;send get disk and insert command
    CDTray($CDDrive, "open")
    $msg = _CommSendString ("i", $iWaitComplete)

    Do
        $return = _Commgetstring ()
    Until $return <> ""
    If $return = "E" Then
        ExitLoop
    EndIf

    CDTray($CDDrive, "close")
    Sleep(20000)
    $drvstat = DriveStatus($CDDrive)
    If $drvstat = "READY" Then

        ;check volume label. If label is empty then populate variable
        $vollbl = DriveGetLabel($CDDrive)
        If $vollbl = "" Then
            $vollbl = "DVDMovie"
        EndIf

        ;check to see if directory that matches vl exists and if so add count to vl
        $lblcount = ""
        Do
            $fileexist = FileExists($target & "\" & $vollbl & $lblcount)
            If $fileexist = 1 Then
                $lblcount = $lblcount + 1
            EndIf
        Until $fileexist = 0

        ;copy the data to the target drive
        GUICtrlSetData($lbl2, $vollbl & $lblcount)
        DirCopy($CDDrive, $target & "\" & $vollbl & $lblcount, 1)

        ;send retrieve disk command
        CDTray($CDDrive, "open")
        $msg = _CommSendString ("a", $iWaitComplete)

        Do
            $return = _Commgetstring ()
        Until $return <> ""

    Else
        ; if the drive cannot read the disk correctly, remove and reject disk
        CDTray($CDDrive, "open")
        $msg = _CommSendString ("p", $iWaitComplete)
        Do
            $return = _Commgetstring ()
        Until $return <> ""
        If $return = "E" Then
            ExitLoop
        EndIf
        CDTray($CDDrive, "close")
        $msg = _CommSendString ("h", $iWaitComplete)
        Do
            $return = _Commgetstring ()
        Until $return <> ""
        If $return = "E" Then
            ExitLoop
        EndIf


    EndIf

WEnd

CDTray($CDDrive, "close")

$msg = _CommClosePort ()

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Thanks for the welcome and the help MsCreatoR! I have been using AutoIt for a couple of years now, but this is the first major stumbling block that I have had.

I appreciate the code updates. I have not had to use arrays much. I tend to use AutoIt as a deployment tool as I am a Systems Engineer with Toshiba in the Computer Systems Division.

I tried the updated code and it will run after compiled but the COM port combo box is not filled. When the script is run from the editor it works fine. This must have something to do with the "commMG.au3" UDF. I found it in the AutoIt forums. It along with it's supplied dll give me the COM port controls. I will see what I can find from the author of it.

Thanks again!

Share this post


Link to post
Share on other sites

I just commented out the _CommListPorts section and added the items to the combo box during the create. The compiled exe works great. The issue is definitely with the _CommListPorts array.

Thanks

Share this post


Link to post
Share on other sites

The issue turned out to be the dll file for the "commMG.au3" UDF. I had the dll in the AutoIt3 directory but not in c:\windows\system32, so running from the editor worked but the compiled exe could not find the dll.

Case closed. :)

Share this post


Link to post
Share on other sites

The issue turned out to be the dll file for the "commMG.au3" UDF. I had the dll in the AutoIt3 directory but not in c:\windows\system32, so running from the editor worked but the compiled exe could not find the dll.

Case closed. :)

You should be able to run it if the dll is in the same folder as the exe. I have never put the dll in system32, though if that works - well, fine.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Hey martin!

Thanks for the "commMG.au3" UDF. It works great! I have already written a couple of utilities for my Flexwriter using it.

As for the dll location, this is fully my fault. :) I was saving my compiled exe file to my desktop and running it from there but I had put your dll in the AutoIT program directory so it was not finding it.

Have a great New Year!

You should be able to run it if the dll is in the same folder as the exe. I have never put the dll in system32, though if that works - well, fine.

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