Что нового

Окно GUI не хочет работать на другом компе

lexaSF

Новичок
Сообщения
182
Репутация
3
Странно, вроде все ок, но на другом компьетере выдает ошибку: Error: Subscript used with non-Array variable Line 4561
Вот код:
Код:
#include <GUIConstants.au3>
#Include <GuiComboBox.au3>
#Include <GuiListBox.au3>
#Include <File.au3>
#Include <Array.au3>

$Dir = @ScriptDir & '\Setting.ini'
$FileList=_FileListToArray(@ScriptDir & '\settings')
$read = IniReadSectionNames($Dir)
$Form1_1_1 = GUICreate("Avtobot", 376, 322, 370, 266)
GUISetIcon("C:\Users\Lexa\Desktop\heroic_autobots.ico")
GUISetBkColor(0xB9D1EA)
$Label1 = GUICtrlCreateLabel("SID", 16, 128, 35, 24)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
$Input1 = GUICtrlCreateInput("", 16, 56, 169, 21)
$Label2 = GUICtrlCreateLabel("Name", 16, 32, 50, 24)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
$Input2 = GUICtrlCreateInput("", 16, 152, 169, 21)
$Label3 = GUICtrlCreateLabel("ID", 16, 80, 23, 24)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
$Input3 = GUICtrlCreateInput("", 16, 104, 169, 21)
$Label4 = GUICtrlCreateLabel("Server", 16, 176, 56, 24)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
$Input4 = GUICtrlCreateInput("", 16, 200, 169, 21)
$Button1 = GUICtrlCreateButton("Save", 16, 280, 73, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
$Button2 = GUICtrlCreateButton("Delete", 208, 280, 73, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
$List1 = GUICtrlCreateList("", 208, 104, 153, 162)
If @error <> 1 Then
For $i = 1 To $read[0]
	_GUICtrlListBox_AddString($List1, $read[$i])
Next
EndIf
$Button3 = GUICtrlCreateButton("Clear", 112, 280, 73, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
$Button4 = GUICtrlCreateButton("Edit", 289, 280, 73, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
$Label5 = GUICtrlCreateLabel("  Load Settings", 224, 0, 122, 26)
GUICtrlSetFont(-1, 12, 800, 0, "Constantia")
$Combo1 = GUICtrlCreateCombo("None", 208, 56, 153, 25)
For $K=1 To $FileList[0]
	_GUICtrlComboBox_AddString($Combo1,$FileList[$k])
Next
GUICtrlSetFont(-1, 8, 800, 0, "Palatino Linotype")
$Combo2 = GUICtrlCreateCombo("None", 16, 248, 169, 25)
GUICtrlSetData(-1, "1-1|1-2|1-3|1-4|1-5|1-6|1-7|1-8|2-1|2-2|2-3|2-4|2-5|2-6|2-7|2-8|3-1|3-2|3-3|3-4|3-5|3-6|3-7|3-8|4-1|4-2|4-3|4-5")
GUICtrlSetFont(-1, 8, 800, 0, "Palatino Linotype")
$Label6 = GUICtrlCreateLabel("Account", 72, 0, 67, 23)
GUICtrlSetFont(-1, 12, 800, 0, "Constantia")
$Label7 = GUICtrlCreateLabel("Map", 16, 224, 32, 22)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
GUISetState(@SW_SHOW)
While 1
	$read = IniReadSectionNames($Dir)
    If @error <> 1 Then
For $i=1 To $read[0]
    $FindStr = _GUICtrlListBox_FindString($List1,$read[$i])
    $FindText = _GUICtrlListBox_GetText($List1,$FindStr) ; $findText = 0 здесь
    If Number($FindText) = Number($read[$i]) Then
     Else
_GUICtrlListBox_AddString($List1, $read[$i])
EndIf
Next
EndIf
	_GUICtrlComboBox_LimitText($Combo1,0)
	_GUICtrlComboBox_LimitText($Combo2,0)
$name = GUICtrlRead($Input1)
$sid = GUICtrlRead($Input2)
$id = GUICtrlRead($Input3)
$serv = GUICtrlRead($Input4)
$map = GUICtrlRead($Combo2)
$Setting = ControlGetText('Avtobot','','[CLASS:Edit; INSTANCE:5]')
$Findname = _GUICtrlListBox_FindString($List1,$name)
$FindTextname = _GUICtrlListBox_GetText($List1,$Findname)
	$nMsg = GUIGetMsg()
	Switch $nMsg
	Case $GUI_EVENT_CLOSE
			Exit
		Case $Button1
		$CtrlRead = GUICtrlRead($Input1)
		$CtrlReadId = GUICtrlRead($Input3)
		$CtrlReadSid = GUICtrlRead($Input2)
		$CtrlReadServ = GUICtrlRead($Input4)
		$StringLen = StringLen($CtrlReadId)
		$seaTxt = ControlGetText("Avtobot", "Account", '[CLASS:Edit; INSTANCE:6]')
		$seaTxtset = ControlGetText ("Avtobot", "Account", '[CLASS:Edit; INSTANCE:5]') 
		If $CtrlRead = '' Then
				MsgBox(0,'ERROR','Error!' & @LF & 'Enter an account name!' & $CtrlRead)
				$err = 1
			Else
				$err = 0
			EndIf
				If StringIsDigit($CtrlReadId) = 1 And StringLen($CtrlReadId) = 8 Then
						IniWrite( $Dir,$name, "ID",$id)
						$ide = 0
					Else
						MsgBox(0,'ERROR!','Error!' & @LF & 'Enter an correct ID!')
						$ide = 1
					EndIf
					If StringIsAlNum($CtrlReadSid) = 1 And StringLen($CtrlReadSid) = 32 Then
						IniWrite( $Dir,$name, "SID",$sid)
						$side = 0
					Else
						MsgBox(0,'ERROR!','Error!' & @LF & 'Enter correct SID!')
						$side = 1
					EndIf
					If StringLen($CtrlReadServ) = 0 Or StringLen($CtrlReadServ) > 5  Then
						MsgBox(0,'ERROR!','Error!' & @LF & 'Enter correct Server!')
						$serve = 1
					Else
						IniWrite( $Dir,$name, "SERVER",$serv)
						$serve = 0
					EndIf
					If $seaTxt = 'None' Then
						MsgBox(0,'ERROR!','Error!' & @LF & 'Enter an correct Map!')
						$mape = 1
					Else
						IniWrite( $Dir,$name, "MAP",_GUICtrlComboBox_GetCurSel($Combo2))
						$mape = 0
					EndIf
					IniWrite($Dir,$name,'SETTING',$Setting)
			If $name = $FindTextname And $err = 0 And $ide = 0 And $side = 0 And $mape = 0 And $serve = 0  Then
				For $ed=1 To $read[0]
						$regedit = StringRegExp($read[$ed],$name,0)
						If $regedit = 1 Then $edit = 1
					Next
					If $edit = 1 Then
				MsgBox(0,'OK!','Account Edit!')
			EndIf
			If $Findname = -1 And $err = 0 And $ide = 0 And $side = 0 And $mape = 0 And $serve = 0 Then
					For $r=1 To $read[0]
						$regsave = StringRegExp( $read[$r],$name,0)
					Next
					If $regsave = 0 Then
					MsgBox(0,'OK!','Account Save!')
				EndIf
			EndIf
			EndIf
			Case $Button2
			$Marker = _GUICtrlListBox_GetAnchorIndex($List1)
			$StrText = _GUICtrlListBox_GetText($List1,$Marker)
			If $Marker <> -1 Then
			_GUICtrlListBox_DeleteString($List1, $Marker)
			IniDelete($Dir,$StrText)
		Else
			MsgBox(0,'ERROR!','Error!' & @LF & 'The account for removal isn"t chosen!')
		EndIf
	Case $Button3
			ControlSetText('Avtobot','','[CLASS:Edit; INSTANCE:1]','')
			ControlSetText('Avtobot','','[CLASS:Edit; INSTANCE:3]','')
			ControlSetText('Avtobot','','[CLASS:Edit; INSTANCE:2]','')
			ControlSetText('Avtobot','','[CLASS:Edit; INSTANCE:4]','')
			_GUICtrlComboBox_SetCurSel($Combo2,'0')
            _GUICtrlComboBox_SetCurSel($Combo1,'0')
		Case $Button4
			$Nameindex = _GUICtrlListBox_GetAnchorIndex($List1)
			$NameIni = _GUICtrlListBox_GetText($List1, $Nameindex)
			If $Nameindex <> -1 Then
			$IniSid = IniRead($Dir,$NameIni,'SID','')
			$IniId = IniRead($Dir,$NameIni,'ID','')
			$IniServer = IniRead($Dir,$NameIni,'SERVER','')
			$IniMap = IniRead($Dir,$NameIni,'MAP','')
			$IniSetting = IniRead($Dir,$NameIni,'SETTING','')
			ControlSetText('Avtobot','','[CLASS:Edit; INSTANCE:1]',$NameIni)
			ControlSetText('Avtobot','','[CLASS:Edit; INSTANCE:3]',$IniId)
			ControlSetText('Avtobot','','[CLASS:Edit; INSTANCE:2]',$IniSid)
			ControlSetText('Avtobot','','[CLASS:Edit; INSTANCE:4]',$IniServer)
			_GUICtrlComboBox_SetCurSel($Combo2,$IniMap)
            _GUICtrlComboBox_SetCurSel($Combo1,$IniSetting + 1)
		Else
			MsgBox(0,'ERROR!','The account for removal isn"t chosen!')
		EndIf	
	EndSwitch
	$edit = 0
WEnd

Подскажите что не так?
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8 471
Репутация
2 401
lexaSF [?]
Ты изначально предполагаешь что функция вернёт массив, но при некоторых обстоятельствах это может быть не так.
Нужно использовать не $read[0] и т.п., а например Ubound($read)-1, ну или проверять на массивность (If IsArray($read) Then...).

Код:
#include <GUIConstants.au3>
#include <GuiComboBox.au3>
#include <GuiListBox.au3>
#include <File.au3>
#include <Array.au3>

$Dir = @ScriptDir & '\Setting.ini'
$FileList = _FileListToArray(@ScriptDir & '\settings')
$read = IniReadSectionNames($Dir)
$Form1_1_1 = GUICreate("Avtobot", 376, 322, 370, 266)
GUISetIcon("C:\Users\Lexa\Desktop\heroic_autobots.ico")
GUISetBkColor(0xB9D1EA)
$Label1 = GUICtrlCreateLabel("SID", 16, 128, 35, 24)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
$Input1 = GUICtrlCreateInput("", 16, 56, 169, 21)
$Label2 = GUICtrlCreateLabel("Name", 16, 32, 50, 24)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
$Input2 = GUICtrlCreateInput("", 16, 152, 169, 21)
$Label3 = GUICtrlCreateLabel("ID", 16, 80, 23, 24)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
$Input3 = GUICtrlCreateInput("", 16, 104, 169, 21)
$Label4 = GUICtrlCreateLabel("Server", 16, 176, 56, 24)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
$Input4 = GUICtrlCreateInput("", 16, 200, 169, 21)
$Button1 = GUICtrlCreateButton("Save", 16, 280, 73, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
$Button2 = GUICtrlCreateButton("Delete", 208, 280, 73, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
$List1 = GUICtrlCreateList("", 208, 104, 153, 162)
For $i = 1 To UBound($read)-1
	_GUICtrlListBox_AddString($List1, $read[$i])
Next
$Button3 = GUICtrlCreateButton("Clear", 112, 280, 73, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
$Button4 = GUICtrlCreateButton("Edit", 289, 280, 73, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
$Label5 = GUICtrlCreateLabel("  Load Settings", 224, 0, 122, 26)
GUICtrlSetFont(-1, 12, 800, 0, "Constantia")
$Combo1 = GUICtrlCreateCombo("None", 208, 56, 153, 25)
For $K = 1 To UBound($FileList)-1
	_GUICtrlComboBox_AddString($Combo1, $FileList[$K])
Next
GUICtrlSetFont(-1, 8, 800, 0, "Palatino Linotype")
$Combo2 = GUICtrlCreateCombo("None", 16, 248, 169, 25)
GUICtrlSetData(-1, "1-1|1-2|1-3|1-4|1-5|1-6|1-7|1-8|2-1|2-2|2-3|2-4|2-5|2-6|2-7|2-8|3-1|3-2|3-3|3-4|3-5|3-6|3-7|3-8|4-1|4-2|4-3|4-5")
GUICtrlSetFont(-1, 8, 800, 0, "Palatino Linotype")
$Label6 = GUICtrlCreateLabel("Account", 72, 0, 67, 23)
GUICtrlSetFont(-1, 12, 800, 0, "Constantia")
$Label7 = GUICtrlCreateLabel("Map", 16, 224, 32, 22)
GUICtrlSetFont(-1, 10, 800, 0, "Palatino Linotype")
GUISetState(@SW_SHOW)
While 1
	$read = IniReadSectionNames($Dir)
	For $i = 1 To UBound($read)-1
		$FindStr = _GUICtrlListBox_FindString($List1, $read[$i])
		$FindText = _GUICtrlListBox_GetText($List1, $FindStr) ; $findText = 0 здесь
		If Number($FindText) <> Number($read[$i]) Then
			_GUICtrlListBox_AddString($List1, $read[$i])
		EndIf
	Next
	_GUICtrlComboBox_LimitText($Combo1, 0)
	_GUICtrlComboBox_LimitText($Combo2, 0)
	$name = GUICtrlRead($Input1)
	$sid = GUICtrlRead($Input2)
	$id = GUICtrlRead($Input3)
	$serv = GUICtrlRead($Input4)
	$map = GUICtrlRead($Combo2)
	$Setting = ControlGetText('Avtobot', '', '[CLASS:Edit; INSTANCE:5]')
	$Findname = _GUICtrlListBox_FindString($List1, $name)
	$FindTextname = _GUICtrlListBox_GetText($List1, $Findname)
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Button1
			$CtrlRead = GUICtrlRead($Input1)
			$CtrlReadId = GUICtrlRead($Input3)
			$CtrlReadSid = GUICtrlRead($Input2)
			$CtrlReadServ = GUICtrlRead($Input4)
			$StringLen = StringLen($CtrlReadId)
			$seaTxt = ControlGetText("Avtobot", "Account", '[CLASS:Edit; INSTANCE:6]')
			$seaTxtset = ControlGetText("Avtobot", "Account", '[CLASS:Edit; INSTANCE:5]')
			If $CtrlRead = '' Then
				MsgBox(0, 'ERROR', 'Error!' & @LF & 'Enter an account name!' & $CtrlRead)
				$err = 1
			Else
				$err = 0
			EndIf
			If StringIsDigit($CtrlReadId) = 1 And StringLen($CtrlReadId) = 8 Then
				IniWrite($Dir, $name, "ID", $id)
				$ide = 0
			Else
				MsgBox(0, 'ERROR!', 'Error!' & @LF & 'Enter an correct ID!')
				$ide = 1
			EndIf
			If StringIsAlNum($CtrlReadSid) = 1 And StringLen($CtrlReadSid) = 32 Then
				IniWrite($Dir, $name, "SID", $sid)
				$side = 0
			Else
				MsgBox(0, 'ERROR!', 'Error!' & @LF & 'Enter correct SID!')
				$side = 1
			EndIf
			If StringLen($CtrlReadServ) = 0 Or StringLen($CtrlReadServ) > 5 Then
				MsgBox(0, 'ERROR!', 'Error!' & @LF & 'Enter correct Server!')
				$serve = 1
			Else
				IniWrite($Dir, $name, "SERVER", $serv)
				$serve = 0
			EndIf
			If $seaTxt = 'None' Then
				MsgBox(0, 'ERROR!', 'Error!' & @LF & 'Enter an correct Map!')
				$mape = 1
			Else
				IniWrite($Dir, $name, "MAP", _GUICtrlComboBox_GetCurSel($Combo2))
				$mape = 0
			EndIf
			IniWrite($Dir, $name, 'SETTING', $Setting)
			If $name = $FindTextname And $err = 0 And $ide = 0 And $side = 0 And $mape = 0 And $serve = 0 Then
				For $ed = 1 To UBound($read)-1
					$regedit = StringRegExp($read[$ed], $name, 0)
					If $regedit = 1 Then $edit = 1
				Next
				If $edit = 1 Then
					MsgBox(0, 'OK!', 'Account Edit!')
				EndIf
				If $Findname = -1 And $err = 0 And $ide = 0 And $side = 0 And $mape = 0 And $serve = 0 Then
					For $r = 1 To UBound($read)-1
						$regsave = StringRegExp($read[$r], $name, 0)
					Next
					If $regsave = 0 Then
						MsgBox(0, 'OK!', 'Account Save!')
					EndIf
				EndIf
			EndIf
		Case $Button2
			$Marker = _GUICtrlListBox_GetAnchorIndex($List1)
			$StrText = _GUICtrlListBox_GetText($List1, $Marker)
			If $Marker <> -1 Then
				_GUICtrlListBox_DeleteString($List1, $Marker)
				IniDelete($Dir, $StrText)
			Else
				MsgBox(0, 'ERROR!', 'Error!' & @LF & 'The account for removal isn"t chosen!')
			EndIf
		Case $Button3
			ControlSetText('Avtobot', '', '[CLASS:Edit; INSTANCE:1]', '')
			ControlSetText('Avtobot', '', '[CLASS:Edit; INSTANCE:3]', '')
			ControlSetText('Avtobot', '', '[CLASS:Edit; INSTANCE:2]', '')
			ControlSetText('Avtobot', '', '[CLASS:Edit; INSTANCE:4]', '')
			_GUICtrlComboBox_SetCurSel($Combo2, '0')
			_GUICtrlComboBox_SetCurSel($Combo1, '0')
		Case $Button4
			$Nameindex = _GUICtrlListBox_GetAnchorIndex($List1)
			$NameIni = _GUICtrlListBox_GetText($List1, $Nameindex)
			If $Nameindex <> -1 Then
				$IniSid = IniRead($Dir, $NameIni, 'SID', '')
				$IniId = IniRead($Dir, $NameIni, 'ID', '')
				$IniServer = IniRead($Dir, $NameIni, 'SERVER', '')
				$IniMap = IniRead($Dir, $NameIni, 'MAP', '')
				$IniSetting = IniRead($Dir, $NameIni, 'SETTING', '')
				ControlSetText('Avtobot', '', '[CLASS:Edit; INSTANCE:1]', $NameIni)
				ControlSetText('Avtobot', '', '[CLASS:Edit; INSTANCE:3]', $IniId)
				ControlSetText('Avtobot', '', '[CLASS:Edit; INSTANCE:2]', $IniSid)
				ControlSetText('Avtobot', '', '[CLASS:Edit; INSTANCE:4]', $IniServer)
				_GUICtrlComboBox_SetCurSel($Combo2, $IniMap)
				_GUICtrlComboBox_SetCurSel($Combo1, $IniSetting + 1)
			Else
				MsgBox(0, 'ERROR!', 'The account for removal isn"t chosen!')
			EndIf
	EndSwitch
	$edit = 0
WEnd


P.S
Я бы не стал так в цикле проверять постоянно секций в файле.
 
Автор
L

lexaSF

Новичок
Сообщения
182
Репутация
3
Спс, щас попробую.Но при каких обстоятельсвах?Ведь InireadSectionNames всегда будет возвращать $var[0]?
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8 471
Репутация
2 401
lexaSF [?]
при каких обстоятельсвах
При отсутствий файла например, это же очевидно.

InireadSectionNames всегда будет возвращать $var[0]?
Разве, а что в справке по этому поводу написано? ;)

P.S
И не нужно цитировать всё сообщение (включая код).
 
Автор
L

lexaSF

Новичок
Сообщения
182
Репутация
3
Ну тогда придется весь код перерабатывать.к тому же я проверял ена другом копме когда файл присутствовал!и еще, как мне сделать автообновление списка? я сделал
Код:
If @error <> 1 Then
For $i=1 To $read[0]
    $FindStr = _GUICtrlListBox_FindString($List1,$read[$i])
    $FindText = _GUICtrlListBox_GetText($List1,$FindStr) ; $findText = 0 здесь
	$regeditlist = StringRegExp($FindText,$name,0)
    If $regeditlist = 1 Then
	Else
			MsgBox(0,'',$read[$i])
_GUICtrlListBox_AddString($List1, $read[$i])
EndIf
Next
EndIf

Но почему то это не работает!


Добавлено:
Сообщение автоматически объединено:

Оно как бы работает, но создает Н колво одинаковых строк.Как это исправить?


Добавлено:
Сообщение автоматически объединено:

А все спс, допер) :laugh:
 

`p r o x y

«Улыбайтесь, господа!»
Команда форума
Глобальный модератор
Сообщения
596
Репутация
157
lexaSF, как понимаю тема решена? Тогда стоит отметить ее как "решенную".
 
Верх