Sign in to follow this  
Followers 0
prpldodge

Subscript Used With Non-array

4 posts in this topic

I have a script that gets this error:

Line0:

$bkdate= $nt[1] & "/" & $nt[2] & "/" & $nt[0] &"at " &$nt[3] &":"& $nt[4] &":"& $nt[5]

$bkdate= $nt^ERROR

Error: Subscript used with non-Array Variable.

It used to work but I do not know what changed. Originaly I did not declare the variables, I added the DIM statments but it had no effect.

Alan

here is the script

; This program backups the speed shift data from the Win server to the city hall server

dim $nt[5][5]

dim $ot[5][5]

dim $file

dim $bkdate

dim $ndate

dim $odate

$nt = FileGetTime("d:\Speed shift data\schedule1.wcs", 0)

$ot = FileGetTime("\\city_hall\data\users\plceschd\isispeed\schedule1.wcs", 0)

$bkdate= $nt[1] & "/" & $nt[2] & "/" & $nt[0] &"at " &$nt[3] &":"& $nt[4] &":"& $nt[5]

If Not @error Then

$ndate = $nt[1] & $nt[2] & $nt[0] & $nt[3] & $nt[4] & $nt[5]

; MsgBox(0, "Creation Time of schedule1.wcs", $ndate )

EndIf

If Not @error Then

$odate = $ot[1] & $ot[2] & $ot[0] & $ot[3] & $ot[4] & $ot[5]

EndIf

If $ndate > $odate then

FileCopy("d:\Speed shift data\schedule1.wcs", "\\city_hall\data\users\plceschd\isispeed\schedule1.wcs",1)

EndIf

$results = $ndate - $odate

$file = FileOpen("d:\Speed shift data\backup log.txt", 1)

FileWriteLine($file, $bkdate & @LF)

;MsgBox(0, "Creation Time of schedule1.wcs", $Results )

$results = $ndate - $odate

;MsgBox(0, "Creation Time of schedule1.wcs", $Results )

Share this post


Link to post
Share on other sites



You appear to be creating a multi-dimensional array, then trying to access it as if it were a single dimension array.

Try:

Dim $nt[5]

Dim $ot[5]

Also, arrays start at 0, not 1. The last element is size-1, not size. So in an array with 5 elements, the elements are 0 - 4, not 1 -5. That will need changed, also.

Share this post


Link to post
Share on other sites

Ooops, I see that you are using FileGetTime, which creates its own array. You need to check to make sure FileGetTime returned correctly before you try to access the elements of the array. Also, its not necessary to Dim the array first since FileGetTime will create on for you.

Share this post


Link to post
Share on other sites

Corrected array statement but it did not change anything. If i change the paths of the file to work on my local computer it works fine. it seems to be a problem with the file (schedule1.wcs). This file may be open when the script runs. What kind of problem does this create? Is there a better command to use when a file maybe in use at the time the script is run?

Alan

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