Что нового

как назначить и сохранить для одной переменной несколько значений

general66

Пришел увидел наследил
Сообщения
211
Репутация
3
Подскажите пожалуйста как реализовать следующую идею есть форма

Код:
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Dialog", 402, 315, 346, 262)
$GroupBox1 = GUICtrlCreateGroup("", 10, 9, 365, 238)
$Input1 = GUICtrlCreateInput("название", 24, 32, 145, 24)
$Combo1 = GUICtrlCreateCombo("Combo1", 192, 32, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Group1 = GUICtrlCreateGroup("Group1", 192, 72, 145, 145)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Group2", 24, 72, 145, 145)
$Input2 = GUICtrlCreateInput("Input2", 36, 101, 121, 24)
$Input3 = GUICtrlCreateInput("Input3", 36, 133, 121, 24)
$Input4 = GUICtrlCreateInput("Input4", 36, 165, 121, 24)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("&OK", 80, 250, 92, 31)
$Button2 = GUICtrlCreateButton("&Cancel", 199, 250, 93, 31)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit

	EndSwitch
WEnd

подскажите как можно сохранить переменную из поля "название" и привязать к ней значения из Input2 - Input4 чтоб при выборе в Combo1 значения из поле "название", в Group1 отобразились значения из Input2 - Input4
Суть как записать в файл все значения полей и потом вытащить их в поле Group1 более-менее понятна только вот механизм получается очень громоздким и при большом количестве переменных совсем не читаемым и трудно редактируемым пытался сделать это через ini файлы.
Подскажите существуют ли более элегантные и не громоздкие способы создания такой себе подручной базы данных
зарание благодарю за помощь.
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
Если я правильно понял...

Код:
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $aNames[1][2] = [[0]]

$Form2 = GUICreate("Dialog", 402, 315, 346, 262)

$GroupBox1 = GUICtrlCreateGroup("", 10, 9, 365, 238)
$Input1 = GUICtrlCreateInput("название", 24, 32, 145, 24)
$Combo1 = GUICtrlCreateCombo("Combo1", 192, 32, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Group1 = GUICtrlCreateGroup("Group1", 192, 72, 145, 145)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Group2", 24, 72, 145, 145)
$Input2 = GUICtrlCreateInput("Input2", 36, 101, 121, 24)
$Input3 = GUICtrlCreateInput("Input3", 36, 133, 121, 24)
$Input4 = GUICtrlCreateInput("Input4", 36, 165, 121, 24)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("&OK", 80, 250, 92, 31)
$Button2 = GUICtrlCreateButton("&Cancel", 199, 250, 93, 31)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
	
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
		Case $Combo1
			_AddName(GUICtrlRead($Input1), GUICtrlRead($Input2) & '|' & GUICtrlRead($Input4))
			_ArrayDisplay($aNames)
    EndSwitch
WEnd
 
Func _AddName($sName, $sData)
	For $i = 1 To $aNames[0][0]
		If $aNames[$i][0] = $sName Then
			$aNames[$i][0] = $sName
			$aNames[$i][1] = $sData
			
			Return $i
		EndIf
	Next
	
	$aNames[0][0] += 1
	ReDim $aNames[$aNames[0][0]+1][2]
	
	$aNames[$aNames[0][0]][0] = $sName
	$aNames[$aNames[0][0]][1] = $sData
	
	Return $aNames[0][0]
EndFunc


при каждом выборе combo, в базу будет добавляться запись вида:
Код:
[N][0] = название (без повторении)
[N][1] = данные с полей input2 и input4 (разделённые через |)
 
Автор
G

general66

Пришел увидел наследил
Сообщения
211
Репутация
3
CreatoR [?]
Если я правильно понял...

Извиняюсь за непонятное изложение своих мыслей :-[ писал ночью полусонный уже...

Я имел ввиду вот что если заполнить поля "название" и Input2 - Input4 а потом скажем нажать кнопку ОК то в Combo1 появляется пункт "название" при выборе которого в Group1 отображается записанные для "название" значения Input2 - Input4 и все это должно хранится в каком нибудь файле для последующего использования. Ну и чтоб повторять такие записи многократно, с возможностью их редактирования.

Трудность для меня оказалась в сохранение и организации файла в котором будут хранится все записи для постоянного их использования
 

InnI

AutoIT Гуру
Сообщения
4,922
Репутация
1,432
general66
Код:
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $Input[5], $Label[5]

$Form2 = GUICreate("Dialog", 402, 315, 346, 262)
$GroupBox1 = GUICtrlCreateGroup("", 10, 9, 365, 238)
$Input[1] = GUICtrlCreateInput("название", 24, 32, 145, 24)
$Combo1 = GUICtrlCreateCombo("Combo1", 192, 32, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Group1 = GUICtrlCreateGroup("Group1", 192, 72, 145, 145)
$Label[2] = GUICtrlCreateLabel("", 206, 101, 121, 24)
$Label[3] = GUICtrlCreateLabel("", 206, 133, 121, 24)
$Label[4] = GUICtrlCreateLabel("", 206, 165, 121, 24)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Group2", 24, 72, 145, 145)
$Input[2] = GUICtrlCreateInput("Input2", 36, 101, 121, 24)
$Input[3] = GUICtrlCreateInput("Input3", 36, 133, 121, 24)
$Input[4] = GUICtrlCreateInput("Input4", 36, 165, 121, 24)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("&Save", 80, 250, 92, 31)
$Button2 = GUICtrlCreateButton("&Cancel", 199, 250, 93, 31)
GUISetState(@SW_SHOW)

Load()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Save()
        Case $Combo1
            For $i = 2 To UBound($Input) - 1
                GUICtrlSetData($Label[$i], IniRead("base.ini", GUICtrlRead($Combo1), "inp" & $i, ""))
            Next

    EndSwitch
WEnd

Func Save()
  For $i = 2 To UBound($Input) - 1
    IniWrite("base.ini", GUICtrlRead($Input[1]), "inp" & $i, GUICtrlRead($Input[$i]))
  Next
  Load()
EndFunc

Func Load()
  Local $ar = IniReadSectionNames("base.ini")
  If Not @error Then
    GUICtrlSetData($Combo1, "")
    For $i = 1 To $ar[0]
      GUICtrlSetData($Combo1, $ar[$i])
    Next
    ControlCommand($Form2, "", $Combo1, "SelectString", GUICtrlRead($Input[1]))
  EndIf
EndFunc
 
Автор
G

general66

Пришел увидел наследил
Сообщения
211
Репутация
3
InnI
Спасибо огромное скрипт то что надо :beer: :IL_AutoIt_1:
 
Верх