zielke Posted March 20, 2009 Share Posted March 20, 2009 Hi, I was wondering why the following code on some systems returns a "subscript used with non-array variable"? It runs fine on other machines but today one user reported this error. Func restoreprofile(); Restores given backup file Local $file, $activate, $profname, $restore $file = FileOpenDialog ( "Select backup file:", "", "CW (*.cws)" , 3 ,"",$mGUI) ; now check whether the file is empty or way too small to contain anything useful If $file = "" Then; check whether backup file has been selected or not MsgBox (16, "Error", "Aborting!",0,$mGUI) ElseIf FileGetSize ( $file ) < 50 Then; check whether file contains anything. Emtpy zip normally is aorund 22 bytes MsgBox (16, "Error", "Aborting!",0,$mGUI) Else RunWait ( @TempDir & "\7za.exe x -bd -y -o" & @TempDir & "\codprofile" & " " & $file,"",@SW_HIDE); extract the file to temp dir for pre-checking $profname = _FileListToArray( @TempDir & "\codprofile","*",2) $restore = MsgBox (36, "Profile Restoration", "restore profile: " & $profname[1] & " ?",0,$mGUI); user confirmation If $restore = 6 Then DirRemove ( ppath() & "\" & $profname[1],1 ); remove old profile if still exist DirMove ( @TempDir & "\codprofile\" & $profname[1], ppath(), 1); copy restored profile to profile path If @error Then MsgBox(16, "Error", "Restoration process failed!") Else $activate = MsgBox (36, "Profile activation", "activate the profile: " & $profname[1] & " ?",0,$mGUI); ask whether to activate profile If $activate = 6 Then If FileExists ( ppath() & "\active.txt" ) Then; kill old active.txt FileDelete ( ppath() & "\active.txt" ) EndIf FileWrite ( ppath() & "\active.txt", $profname[1] ); write active.txt with restored profile name If @error Then MsgBox(16, "Error", "Activation process failed!") EndIf EndIf DirRemove (@TempDir & "\codprofile", 1); kill temp decompression dir MsgBox (64, "Done!", "You profile has been sucessfully restored!",0,$mGUI) EndIf Else MsgBox(16, "Profile Restoration", "Restoration process aborted!") EndIf EndIf EndFunc; ==> restoreprofile Link to comment Share on other sites More sharing options...
Authenticity Posted March 20, 2009 Share Posted March 20, 2009 $profname = _FileListToArray( @TempDir & "\codprofile","*",2) $restore = MsgBox (36, "Profile Restoration", "restore profile: " & $profname[1] & " ?",0,$mGUI); It's required to first check if $profname is an array before using it's element which may not happen to exist. In my @TempDir for example I don't have a folder called "codprofile" so I'd get this error as well. Same for the rest of the script, check if it's an array before using it. Link to comment Share on other sites More sharing options...
zielke Posted March 20, 2009 Author Share Posted March 20, 2009 $profname = _FileListToArray( @TempDir & "\codprofile","*",2) $restore = MsgBox (36, "Profile Restoration", "restore profile: " & $profname[1] & " ?",0,$mGUI); It's required to first check if $profname is an array before using it's element which may not happen to exist. In my @TempDir for example I don't have a folder called "codprofile" so I'd get this error as well. Same for the rest of the script, check if it's an array before using it. The folder you mentioned is created during the extraction-process RunWait ( @TempDir & "\7za.exe x -bd -y -o" & @TempDir & "\codprofile" & " " & $file,"",@SW_HIDE) so this should be no problem. I just noticed that the user is using Windows 7 beta. This might cause the problem. Is Windows 7 officially supported by AutoIt? Link to comment Share on other sites More sharing options...
trancexx Posted March 20, 2009 Share Posted March 20, 2009 Supported or not you should do what Authenticity said if you want to debug that. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now