Sign in to follow this  
Followers 0
lafafmentvotre

Error with Array.au3

10 posts in this topic

Hi everybody and sorry for my bad english.

I have an error with a script on Windows Seven (wich i didn't have on windows XP).

Here is the part of script :

Func Proxy_Enable()
$value='user_pref("network.proxy.type", 1);';Manual Configuration
Select
Case FileExists(@AppDataDir&'\Mozilla\Firefox\profiles.ini')
Do
ProcessClose($FF_process)
Until Not ProcessExists($FF_process)
$var=StringReplace(IniRead(@AppDataDir&'\Mozilla\Firefox\profiles.ini','Profile0','Path',''),'/','\')
$file=@AppDataDir&'\Mozilla\Firefox\'&$var&'\prefs.js'
_FileReadToArray($file,$aArray)
$line=_ArraySearch($aArray,'user_pref("network.proxy.type',0, 0, 0, 1)
_ArrayDelete($aArray,$line)
_ArrayInsert($aArray,$line,$value)
FileOpen($file,2)
_FileWriteFromArray($file,$aArray,1)
FileClose($file)
EndSelect
EndFunc

and the error :

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "E:\Pro\AutoIt Development\Proxy_Statut\GIS_Suisse\GISProxyConfig.au3"    
C:\Program Files (x86)\AutoIt3\Include\Array.au3 (585) : ==> Array variable subscript badly formatted.:
$avArray[$i] = $avArray[$i - 1]
$avArray[$i] = $avArray[^ ERROR
>Exit code: 1    Time: 8.857

Does anyone have any idea?

Thanks

Share this post


Link to post
Share on other sites



Place a consolewrite before the error line for get $i - 1 value...Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Hello

I place ConsoleWrite($avArray[$i - 1]) in Array.au3 :

Func _ArrayInsert(ByRef $avArray, $iElement, $vValue = "")
    If Not IsArray($avArray) Then Return SetError(1, 0, 0)
    If UBound($avArray, 0) <> 1 Then Return SetError(2, 0, 0)

    ; Add 1 to the array
    Local $iUBound = UBound($avArray) + 1
    ReDim $avArray[$iUBound]

    ; Move all entries over til the specified element
    For $i = $iUBound - 1 To $iElement + 1 Step -1
        ConsoleWrite($avArray[$i - 1])
        $avArray[$i] = $avArray[$i - 1]
    Next

    ; Add the value in the specified element
    $avArray[$iElement] = $vValue
    Return $iUBound
EndFunc   ;==>_ArrayInsert

I get in the console the pref.js file content with error at the end :

C:\Program Files (x86)\AutoIt3\Include\Array.au3 (585) : ==> Array variable subscript badly formatted.:
ConsoleWrite($avArray[$i - 1])
ConsoleWrite($avArray[^ ERROR

Share this post


Link to post
Share on other sites

Hello

I place ConsoleWrite($avArray[$i - 1]) in Array.au3 :

Func _ArrayInsert(ByRef $avArray, $iElement, $vValue = "")
    If Not IsArray($avArray) Then Return SetError(1, 0, 0)
    If UBound($avArray, 0) <> 1 Then Return SetError(2, 0, 0)

    ; Add 1 to the array
    Local $iUBound = UBound($avArray) + 1
    ReDim $avArray[$iUBound]

    ; Move all entries over til the specified element
    For $i = $iUBound - 1 To $iElement + 1 Step -1
        ConsoleWrite($avArray[$i - 1])
        $avArray[$i] = $avArray[$i - 1]
    Next

    ; Add the value in the specified element
    $avArray[$iElement] = $vValue
    Return $iUBound
EndFunc   ;==>_ArrayInsert

I get in the console the pref.js file content with error at the end :

C:\Program Files (x86)\AutoIt3\Include\Array.au3 (585) : ==> Array variable subscript badly formatted.:
ConsoleWrite($avArray[$i - 1])
ConsoleWrite($avArray[^ ERROR

$avArray[$i - 1] value is not $i - 1

Try ConsoleWrite($i - 1)


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Here is the error with ConsoleWrite($i - 1)

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "E:\Pro\AutoIt Development\Proxy_Statut\GIS_Suisse\GISProxyConfig.au3"    
66656463626160595857565554535251504948476665646362616059585756555453525150494847464544434241403938373635343332313029282726252423222120191817161514131211109876543210-1C:\Program Files (x86)\AutoIt3\Include\Array.au3 (586) : ==> Array variable subscript badly formatted.:
$avArray[$i] = $avArray[$i - 1]
$avArray[$i] = $avArray[^ ERROR
>Exit code: 1    Time: 5.267

Share this post


Link to post
Share on other sites

So $i value is too big

Can you show your entire script for find the error ?


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

So $i value is too big

Can you show your entire script for find the error ?

Yes

#cs ----------------------------------------------------------------------------
Version:    3.3.6.1
Author:     GIS & InfraFrance@2010
Function:   Change, enable and disable Proxy
#ce ----------------------------------------------------------------------------
#region AutoIT Variables
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <Process.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <IE.au3>
#include <Array.au3>
#include <file.au3>
#endregion
#region Script Variables
Global $aritems, $proxy, $ssl,$options
Local $radioval1, $statut, $statut_IE,$statut_FF,$var,$aArray
Local $script='Proxy_Statut'
Local $ver="3.1"
Local $FF_process='firefox.exe'
Local $green="0x11EF56"
Local $red="0xFF0101"
Local $blue="0xD9E3E9"
Local $reg=RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyServer")
Local $title=StringTrimRight($reg, 5)
Local $country_ini='Country.ini'
Local $value='user_pref("network.proxy.type", 1);';Manual Configuration
#endregion
#region DIRECTORY & DRIVERS
DirCreate(@TempDir&'\Proxy_Statut')
FileInstall('company.jpg', @TempDir&'\Proxy_Statut\company.jpg',1)
FileInstall('bg.jpg', @TempDir&'\Proxy_Statut\bg.jpg',1)
#endregion
#region Language
$m0 = "GIS_Proxy_Config"
$m1 = "&File"
$m2 = "Exit"
$m3 = "Actions"
$m4 = "Enabled"
$m5 = "Disabled"
$m6 = "Run SSL"
$m7 = "About..."
$m8 = "Status Proxy : "
$m9 = "For Information"
$m10 = "1. From a Richemont office, you must select the country which is more close of your place and then activate proxy."
$m12 = "2. Outside Richemont have to start the VPN and the proxy must be activated."
$m13 = "Change Proxy"
$m14 = "Actual"
$m15 = "Options"
$m16 = "Enable"
$m17 = "Disable"
$m18 = "Please restart your browser to apply modifications."
$m19 = "Please select a country before clicking on """&$m13&"""."
$m20 = "Select the country in order to modify your proxy :"
$m21 = "Your Proxy is activated. Click on """&$m5&""" before running SSL"
$m22 = "Proxy Status :"
$m23 = "Proxy Value Internet Explorer :"
$m24 = "Proxy Firefox :"
$m25 = "Proxy Value Firefox :"
$m26 = ""
$m27 = "Proxy :"
#endregion
statut()
#region GUI
$Gui1 = GuiCreate(" "&StringTrimRight(@ScriptName,4)& " "&$ver&"", 600, 300, -1, -1,$WS_POPUPWINDOW)
$bg = GUICtrlCreatePic(@TempDir&'\Proxy_Statut\bg.jpg', 0, 0, 600, 300,$WS_CLIPSIBLINGS)
$filemenu=GUICtrlCreateMenu ($m1)
$activeitem=GUICtrlCreateMenuitem ($m4,$filemenu)
$desactiveitem=GUICtrlCreateMenuitem ($m5,$filemenu)
$changeitem=GUICtrlCreateMenuItem($m13,$filemenu)
$exititem=GUICtrlCreateMenuitem ($m2,$filemenu)
;#############
;ACTUAL
;#############
$Group1 = GUICtrlCreateGroup('', 8, 78, 290, 85)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Group1_label=GUICtrlCreateLabel(StringUpper($m14),10,90,285,20,$SS_CENTER)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, -1, 800, 0, "",1)
$Label_IE = GUICtrlCreateLabel($m22, 60, 110, 90, 20,$SS_RIGHT)
GUICtrlSetFont(-1, -1, 800, 0, "",1)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$statut_IE = GUICtrlCreateLabel($statut, 160, 110, 90, 20)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Label_value = GUICtrlCreateLabel($m27, 60, 130, 90, 20,$SS_RIGHT)
GUICtrlSetFont(-1, -1, 800, 0, "",1)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$value_IE=GUICtrlCreateLabel($title, 160, 130, 90, 20)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
;#############
;PROXY OPTIONS
;#############
$Group2 = GUICtrlCreateGroup('',300, 78, 290, 85)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Group2_label=GUICtrlCreateLabel(StringUpper($m15),302,90,285,20,$SS_CENTER)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, -1, 800, 0, "",1)
$country_label=GUICtrlCreateLabel($m20,302,110, 285,20,$SS_CENTER)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$country_combo=GUICtrlCreateCombo("",398, 130, 100, 20)
_GetOptions($options)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Select
case $statut=$m16
GUICtrlSetColor($statut_IE, $green)
GUICtrlSetFont($statut_IE, 9, 800)
case Else
GUICtrlSetColor($statut_IE, $red)
GUICtrlSetFont($statut_IE, 9, 800)
EndSelect
;#############
;BUTTONS OPTIONS
;#############
$bouton_active = GUICtrlCreateButton($m4, 120, 170, 87, 20)
$bouton_desactive = GUICtrlCreateButton($m5, 210, 170, 87, 20)
$bouton_change=GUICtrlCreateButton($m13, 300, 170, 87, 20)
$bouton_quitter=GUICtrlCreateButton($m2, 390, 170, 87, 20)
;#############
;REMINDER
;#############
$Group3 = GUICtrlCreateGroup('', 8, 200, 585, 70)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Group3_label=GUICtrlCreateLabel(StringUpper($m9),10,212,580,20,$SS_CENTER)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, -1, 800, 0, "",1)
$Label5 = GUICtrlCreateLabel($m10&@LF&$m12, 10, 232, 580, 30)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Top_header = GUICtrlCreatePic(@TempDir&'\Proxy_Statut\company.jpg', 0, 0, 600, 72)
$WMA = GUICtrlCreateLabel($script, 465, 15, 200, 30,$SS_LEFT)
GUICtrlSetFont(-1, 15, 400, 0, "",1)
GUICtrlSetColor(-1,0xFFFFFF)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Version = GUICtrlCreateLabel("Version "&$ver, 495, 40, 90, 17)
GUICtrlSetFont(-1, 10, 400, 0, "",1)
GUICtrlSetColor(-1,0xFFFFFF)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUISetState(@SW_SHOW,$Gui1)
#endregion
#region SCRIPT
While 1
$listener=GUIGetMsg()
$options=GUICtrlRead($country_combo)
Select
Case $listener = $GUI_EVENT_CLOSE or $listener = $exititem or $listener = $bouton_quitter
ExitLoop
Case $listener = $bouton_active Or $listener=$activeitem
$reg=RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyServer")
If $reg = "" Then
$reg2=RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyServerBackup")
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyServer","REG_SZ",$reg2)
EndIf
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyEnable","REG_DWORD","1")
Proxy_Enable()
SplashTextOn("", $m18, 500, 40, -1, -1, 1,"Arial",9)
Sleep(3000)
statut()
GUICtrlSetData($statut_IE,$statut)
Refresh()
SplashOff()
Case $listener = $bouton_change Or $listener=$changeitem
If $options="" Then
SplashTextOn("", $m19, 500, 40, -1, -1, 1,"Arial",9)
Sleep(3000)
SplashOff()
Else
_GetOptions($options)
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyServer","REG_SZ",$proxy)
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyServerBackup","REG_SZ",$proxy)
Proxy_FF_Change()
Refresh()
EndIf
Case $listener = $bouton_desactive Or $listener=$desactiveitem
If $reg <> "" Then
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyServerBackup","REG_SZ",$reg)
EndIf               
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyEnable","REG_DWORD","0")
Proxy_Disable()
SplashTextOn("", $m18, 500, 40, -1, -1, 1,"Arial",9)
Sleep(3000)
statut()
GUICtrlSetData($statut_IE,$statut)
Refresh()
SplashOff()
EndSelect 
Wend
#endregion
#region FUNCTIONS
Func statut()
If RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyEnable") = "1" Then
$statut=$m16
GUICtrlSetColor($statut_IE, $green)
GUICtrlSetFont($statut_IE, 9, 800)
Else
$statut=$m17
GUICtrlSetColor($statut_IE, $red)
GUICtrlSetFont($statut_IE, 9, 800)
EndIf
Return $statut
EndFunc
Func Refresh()
$refresh=RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyServer")
$title2=StringTrimRight($refresh, 5)
GUICtrlSetData($value_IE,$title2)
EndFunc
Func _GetOptions($options)
$var=IniReadSectionNames($country_ini)
$list_combo=""
For $y=1 to UBound($var) -1
If $var[($y)] <> "" Then
$list_combo = $list_combo & "|"
$list_combo = $list_combo & $var[($y)]
EndIf   
Next
GUICtrlSetData($country_combo, $list_combo)
$proxy=IniRead($country_ini, $options, "proxy", "")
$ssl=IniRead($country_ini, $options, "ssl", "")
EndFunc
Func Proxy_Enable()
;~ $value='user_pref("network.proxy.type", 1);';Manual Configuration
Select
Case FileExists(@AppDataDir&'\Mozilla\Firefox\profiles.ini')
Do
ProcessClose($FF_process)
Until Not ProcessExists($FF_process)
$var=StringReplace(IniRead(@AppDataDir&'\Mozilla\Firefox\profiles.ini','Profile0','Path',''),'/','\')
$file=@AppDataDir&'\Mozilla\Firefox\'&$var&'\prefs.js'
_FileReadToArray($file,$aArray)
$line=_ArraySearch($aArray,'user_pref("network.proxy.type',0, 0, 0, 1)
_ArrayDelete($aArray,$line)
_ArrayInsert($aArray,$line,$value)
FileOpen($file,2)
_FileWriteFromArray($file,$aArray,1)
FileClose($file)
EndSelect
EndFunc
Func Proxy_Disable()
$value='user_pref("network.proxy.type", 0);';No proxy 
Select
Case FileExists(@AppDataDir&'\Mozilla\Firefox\profiles.ini')
Do
ProcessClose($FF_process)
Until Not ProcessExists($FF_process)
$var=StringReplace(IniRead(@AppDataDir&'\Mozilla\Firefox\profiles.ini','Profile0','Path',''),'/','\')
$file=@AppDataDir&'\Mozilla\Firefox\'&$var&'\prefs.js'
_FileReadToArray($file,$aArray)
$line=_ArraySearch($aArray,'user_pref("network.proxy.type',0, 0, 0, 1)
_ArrayDelete($aArray,$line)
_ArrayInsert($aArray,$line,$value)
FileOpen($file,2)
_FileWriteFromArray($file,$aArray,1)
FileClose($file)
EndSelect
EndFunc
Func Proxy_FF_Change()
$proxy=StringTrimRight($proxy,5)
Select
Case FileExists(@AppDataDir&'\Mozilla\Firefox\profiles.ini')
Do
ProcessClose($FF_process)
Until Not ProcessExists($FF_process)
$var=StringReplace(IniRead(@AppDataDir&'\Mozilla\Firefox\profiles.ini','Profile0','Path',''),'/','\')
$file=@AppDataDir&'\Mozilla\Firefox\'&$var&'\prefs.js'
_FileReadToArray($file,$aArray)
;Proxy_Ftp
$line1=_ArraySearch($aArray,'user_pref("network.proxy.ftp"',0, 0, 0, 1)
_ArrayDelete($aArray,$line1)
_ArrayInsert($aArray,$line1,'user_pref("network.proxy.ftp", "'&$proxy&'");')
FileOpen($file,2)
_FileWriteFromArray($file,$aArray,1)
FileClose($file)
;Proxy_Gopher
_FileReadToArray($file,$aArray)
$line2=_ArraySearch($aArray,'user_pref("network.proxy.gopher"',0, 0, 0, 1)
_ArrayDelete($aArray,$line2)
_ArrayInsert($aArray,$line2,'user_pref("network.proxy.gopher", "'&$proxy&'");')
FileOpen($file,2)
_FileWriteFromArray($file,$aArray,1)
FileClose($file)
;Proxy_Http
_FileReadToArray($file,$aArray)
$line3=_ArraySearch($aArray,'user_pref("network.proxy.http"',0, 0, 0, 1)
_ArrayDelete($aArray,$line3)
_ArrayInsert($aArray,$line3,'user_pref("network.proxy.http", "'&$proxy&'");')
FileOpen($file,2)
_FileWriteFromArray($file,$aArray,1)
FileClose($file)
;Proxy_Socks
_FileReadToArray($file,$aArray)
$line4=_ArraySearch($aArray,'user_pref("network.proxy.socks"',0, 0, 0, 1)
_ArrayDelete($aArray,$line4)
_ArrayInsert($aArray,$line4,'user_pref("network.proxy.socks", "'&$proxy&'");')
FileOpen($file,2)
_FileWriteFromArray($file,$aArray,1)
FileClose($file)
;Proxy_Ssl
_FileReadToArray($file,$aArray)
$line5=_ArraySearch($aArray,'user_pref("network.proxy.ssl"',0, 0, 0, 1)
_ArrayDelete($aArray,$line5)
_ArrayInsert($aArray,$line5,'user_pref("network.proxy.ssl", "'&$proxy&'");')
FileOpen($file,2)
_FileWriteFromArray($file,$aArray,1)
FileClose($file)
EndSelect
EndFunc
#endregion

Share this post


Link to post
Share on other sites

I get no errors ! Posted Image

So instead of use _Arrayinsert, try to use _ReplaceStringInFile function like this :

#include <File.au3>

$_FilePath = @AppDataDir & '\Mozilla\Firefox\' & $var & '\prefs.js'
$_StringToFind = 'user_pref("network.proxy.type'
$_StringToReplace = 'user_pref("network.proxy.type", 1);'
_ReplaceStringInFile ( $_FilePath, $_StringToFind, $_StringToReplace )

Is there still errors ?


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Hello Wakillon

It works with your example.

Thank you

Share this post


Link to post
Share on other sites

Hello Wakillon

It works with your example.

Thank you

Glad to help you !

and _ReplaceStringInFile is more handy !

Bon courage ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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