NewBieAuto Posted April 5, 2021 Share Posted April 5, 2021 Here's my code. This is a problem after adding data in the DATA INPUT GUI, the old content still appears in the input boxes of the audio and video input box. even though I wrote a command to delete them all. Could anyone help me!! Thanks all! expandcollapse popup#Region ### DECLARE ### #include <array.au3> #include <file.au3> #Include <String.au3> #include <excel.au3> #include <Date.au3> #include <Misc.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ComboConstants.au3> #include <GuiListView.au3> #include <GuiToolBar.au3> #include <GuiEdit.au3> #include <IE.au3> #include <GDIPlus.au3> #include <ClipBoard.au3> #include <GUIListViewEx.ver.15.09.2020.au3> Global $Paused HotKeySet("`", "TogglePause") HotKeySet("^q", "Terminate") opt("WinTitleMatchMode", 2) opt('MouseCoordMode', 2) opt('PixelCoordMode', 2) opt('CaretCoordMode', 2) Opt("GUIResizeMode", BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE)) $iEditMode = 0 ;If UBound(ProcessList("autoit3.exe")) > 2 Then ; MsgBox(262208, "* NOTE * ", "Welcome to AutoIt 1-2-3 was already running ", 5) ; Exit ;EndIf Local $Gui_DataInput = 9999, $ArrElementPlus, $ArrElementMinus, $Input_A1, $Gui_DataInput_AudioRadio, $Gui_DataInput_ImageRadio,$AddToDeckLv, $Gui_DataInput_EditRadio Local $Gui_DataInput_InputByEdit = 9999, $InputByEdit_Add, $InputByEdit_Ip $InputByEditBtnID = '' $InputByEditID = '' Global $Element_For_Column = 5 ; Max number of element for column Global $Max_Element = 15 ; Number of total element Global $iCount = 0 ; Number 1 is used for basic element Global $Move_Top, $Move_Left, $Temp_iCount = 0 Global $ArrElement[1][4]= [['Title', 'Title content', 'get audio/img btn', 'browse btn']] $PathSound = '' $DatabasePath = @ScriptDir & '\database.txt' $PathImg = @ScriptDir & '\Image\' $PathAudio = @ScriptDir & '\Audio\' $PathAnkiTyping = @ScriptDir & '\anki list word type\' $PathAnkiDeckFile = @ScriptDir & '\Anki Deck File\' $PathAnkiMedia = @AppDataDir &'\Anki2\User 1\collection.media\' $ComboLoaiTuContent = 'Nouns|Verb|Adjective|Adverb' $PathNoImage = @ScriptDir & '\NoImage.jpg' $FontComboLV = "normal|bold|italic" $ColorComboLV = "green|black|blue|red" $DeckLVAudioColumn = 'Audio file' $DeckLVImageColumn = 'Image file' $DeckLVSoundCodeColumn = 'Sound Code' $DeckLVImageCodeColumn = 'Image Code' $DeckLVHiddenCharSuggestColumn = 'Hidden Char Suggest' $DeckLVKeyCodeHiddenCharColumn = 'KeyCode Anki' #EndRegion ;------------------------------------------------------- #Region ### START Koda GUI section ### Form=g:\autoit\gui builder\koda_1.7.3.0\forms\anki tool.kxf $MainGui = GUICreate("Anki Create Tools", 450, 100, 326, 110) $Group1 = GUICtrlCreateGroup("DATA INPUT", 3, 3, 433, 100) $Label3 = GUICtrlCreateLabel("File Name", 5, 24, 52, 17) $TenDeckIp = GUICtrlCreateInput("", 58, 24, 373, 21) $Gui_CreateDataInputGui = GUICtrlCreateButton("INPUT DATA", 90, 51, 130, 25, $BS_MULTILINE) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #Region ### UPDATE INFORMATION ### #EndRegion While 1 $CheckGui = GUIGetMsg(1) Switch $CheckGui[1] case $MainGui Switch $CheckGui[0] case $GUI_EVENT_CLOSE Exit case $Gui_CreateDataInputGui _Gui_CreateDataInputGui() EndSwitch case $Gui_DataInput Switch $CheckGui[0] Case $GUI_EVENT_CLOSE GUIDelete($Gui_DataInput) GUICtrlSetState($Gui_CreateDataInputGui, $GUI_ENABLE) case $AddToDeckLv $LvIdx_Deck = _DataInput_AddToDeckLV() Case $ArrElementPlus GUISwitch($Gui_DataInput) _DataInput_AddElement() Case $ArrElementMinus GUISwitch($Gui_DataInput) _DataInput_DeleteElement() Case Else For $i = 1 To UBound($ArrElement) - 1 Switch $CheckGui[0] Case $ArrElement[$i][2] ;All ID Get_Save Audio / Img / Input by Edit if $ArrElement[$i][2] <> '' then ;ID element khác '' Select case GUICtrlRead($ArrElement[$i][2]) = 'Get Audio' case GUICtrlRead($ArrElement[$i][2]) = 'Save Img Clipboard' ;~ _SaveImage() GUICtrlSetData($ArrElement[$i][1], "You have clicked button " & $i + 1) case GUICtrlRead($ArrElement[$i][2]) = 'Input by Edit' $InputByEditBtnID = $ArrElement[$i][2] $InputByEditID = $ArrElement[$i][1] _Gui_CreateInputByEditGui() EndSelect EndIf Case $ArrElement[$i][3] ;all Browse ID if $ArrElement[$i][3] <> '' then ;other ID element '' $LoadPath = '' Select case StringInStr(GUICtrlRead($ArrElement[$i][2]), 'Img', 1) $LoadPath = FileOpenDialog('Choose the open file', @ScriptDir, "Image File(*.jpg)", $FD_FILEMUSTEXIST) case StringInStr(GUICtrlRead($ArrElement[$i][2]), 'Audio', 1) $LoadPath = FileOpenDialog('Choose the open file', @ScriptDir, "Audio File (*.mp3)", $FD_FILEMUSTEXIST) EndSelect if $LoadPath <> '' then GUICtrlSetData($ArrElement[$i][1], $LoadPath) EndIf EndSwitch Next EndSwitch EndSwitch WEnd Func _Gui_CreateDataInputGui() $Gui_DataInput = GUICreate("Data Input GUI", 373, 97, -1, -1, Default, Default, $MAINGUI) $Label_A1 = GUICtrlCreateLabel("Title", 5, 5, 42, 17) $Input_A1 = GUICtrlCreateInput("", 50, 4, 107, 21) $ArrElementMinus = GUICtrlCreateButton("-", 326, 2, 19, 25) $ArrElementPlus = GUICtrlCreateButton("+", 348, 2, 19, 25) $Gui_DataInput_AudioRadio = GUICtrlCreateRadio("Audio", 225, 6, 47, 17) $Gui_DataInput_EditRadio = GUICtrlCreateRadio("Edit Text", 159, 6, 65, 17) $Gui_DataInput_ImageRadio = GUICtrlCreateRadio("Image", 273, 6, 50, 17) $AddToDeckLv = GUICtrlCreateButton("Add", 252, 30, 60, 28, BitOR($BS_DEFPUSHBUTTON,$BS_MULTILINE)) GUISetState(@SW_SHOW) $Move_Top = 0 $Move_Left = 0 $iCount = 0 $Temp_iCount = 0 Global $ArrElement[1][4]= [['Title', 'Title Content', 'get audio/img btn', 'browse btn']] GUICtrlSetState($Gui_CreateDataInputGui, $GUI_DISABLE) EndFunc Func _Gui_CreateInputByEditGui() $Gui_DataInput_InputByEdit = GUICreate("Input by edit", 452, 361, 578, 197) $InputByEdit_Ip = GUICtrlCreateEdit("", 18, 33, 421, 307, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetData(-1, "") $InputByEdit_Add = GUICtrlCreateButton("Add", 177, 3, 75, 25, $BS_DEFPUSHBUTTON) GUISetState(@SW_SHOW) EndFunc Func _DataInput_AddElement() $BtnName = '' $TieuDe = GUICtrlRead($Input_A1) if GUICtrlRead($Gui_DataInput_AudioRadio) = 1 then $BtnName = 'Get Audio' $TieuDe = $DeckLVAudioColumn EndIf if GUICtrlRead($Gui_DataInput_ImageRadio) = 1 then $BtnName = 'Save Img Clipboard' $TieuDe = $DeckLVImageColumn EndIf ;~ $TieuDe = 'dsgvssasasagvds' if $TieuDe <> '' then Global $Gui_DataInputSize_Height = 39, $Gui_DataInputSize_Width = 250 Local Const $Size = WinGetPos($Gui_DataInput) $Temp_iCount += 1 $iCount += 1 $Move_Top += 40 if $iCount = 0 then $TieuDe = 'Keyword' ;mặc định khung nhập đầu tiên là Keyword ;~ ToolTip($TieuDe & ' - ' & 8 & ' - ' & 26 + $Move_Top & ' - ' & 90 & ' - ' & 17, 600, 0) If $Temp_iCount > $Element_For_Column Then If $iCount <= $Max_Element Then WinMove($Gui_DataInput, "", Default, Default, $Size[2] + $Gui_DataInputSize_Width, Default) _DataInput_Middle($Gui_DataInput, "") $Move_Top = 0 ; reset top $Move_Left += 270 ; create left vaule $Temp_iCount = 1 ; reset temp_element EndIf EndIf If $iCount <= $Max_Element Then ;~ _ArrayDisplay($ArrElement, 'Before') If $iCount <= $Element_For_Column Then _ArrayAdd($ArrElement, '') $ArrElement[UBound($ArrElement) - 1][0] = GUICtrlCreateLabel($TieuDe, 8, 20 + $Move_Top, 290, 17) $ArrElement[UBound($ArrElement) - 1][1] = GUICtrlCreateInput('' , 8, 35 + $Move_Top, 161, 21) if GUICtrlRead($Gui_DataInput_EditRadio) = 1 Then $ArrElement[UBound($ArrElement) - 1][2] = GUICtrlCreateButton('Input by Edit' , 170, 33 + $Move_Top, 80, 25, $BS_MULTILINE) Else $ArrElement[UBound($ArrElement) - 1][1] = GUICtrlCreateInput('' , 8, 35 + $Move_Top, 161, 21) EndIf if $BtnName <> '' then $ArrElement[UBound($ArrElement) - 1][2] = GUICtrlCreateButton($BtnName, 170, 33 + $Move_Top, 51, 25, $BS_Multiline) $ArrElement[UBound($ArrElement) - 1][3] = GUICtrlCreateButton("...", 225, 33 + $Move_Top, 25, 25) EndIf WinMove($Gui_DataInput, "", Default, Default, Default, $Size[3] + $Gui_DataInputSize_Height) _DataInput_Middle($Gui_DataInput, "") ;~ _ArrayDisplay($ArrElement) ;~ _ArrayDisplay($ArrElement, 'After 2') Else _ArrayAdd($ArrElement, '') $ArrElement[UBound($ArrElement) - 1][0] = GUICtrlCreateLabel($TieuDe, 8 + $Move_Left, 60 + $Move_Top, 290, 17) $ArrElement[UBound($ArrElement) - 1][1] = GUICtrlCreateInput('', 8 + $Move_Left, 75 + $Move_Top, 161, 21) if $BtnName <> '' then $ArrElement[UBound($ArrElement) - 1][2] = GUICtrlCreateButton($BtnName, 170 + $Move_Left, 73 + $Move_Top, 51, 25, $BS_Multiline) $ArrElement[UBound($ArrElement) - 1][3] = GUICtrlCreateButton("...", 225 + $Move_Left, 73 + $Move_Top, 25, 25) EndIf EndIf EndIf If $iCount > $Max_Element Then $iCount = $Max_Element $Temp_iCount = $Element_For_Column - 1 EndIf GUICtrlSetData($Input_A1, '') GUICtrlSetState($Input_A1, $Gui_Focus) GUICtrlSetState($Gui_DataInput_AudioRadio, $GUI_UNCHECKED) GUICtrlSetState($Gui_DataInput_ImageRadio, $GUI_UNCHECKED) GUICtrlSetState($Gui_DataInput_EditRadio, $GUI_UNCHECKED) EndIf EndFunc ;==>_Gui_DataInput_AddElement Func _DataInput_AddToDeckLV() ;~ _ArrayDisplay($ArrElement) ;~ GUICtrlSetState($ArrElement[1][1], $Gui_Focus) for $a = 0 to UBound($ArrElement) - 1 GUICtrlSetData($ArrElement[$a][1], '') Next EndFunc Func _DataInput_DeleteElement() Local Const $Size = WinGetPos($Gui_DataInput) Local $Temp_Move_Top = 50 ; Equal to $Move_Top If $iCount = 1 Then ; No element $iCount = 1 Return Else GUICtrlDelete($ArrElement[UBound($ArrElement) - 1][0]) ; delete element GUICtrlDelete($ArrElement[UBound($ArrElement) - 1][1]) ; delete element GUICtrlDelete($ArrElement[UBound($ArrElement) - 1][2]) ; delete element GUICtrlDelete($ArrElement[UBound($ArrElement) - 1][3]) ; delete element _ArrayDelete($ArrElement, UBound($ArrElement) - 1) EndIf If $iCount <> 0 Then If $iCount <= $Element_For_Column Then WinMove($Gui_DataInput, "", Default, Default, Default, $Size[3] - $Gui_DataInputSize_Height) ; resize gui _DataInput_Middle($Gui_DataInput, "") EndIf EndIf If $Temp_iCount = 0 Then ; New Column WinMove($Gui_DataInput, "", Default, Default, $Size[2] - $Gui_DataInputSize_Width, Default) ; resize gui _DataInput_Middle($Gui_DataInput, "") $Move_Left -= 270 ; Remove left value $Temp_iCount += $Element_For_Column ; Remove new colum EndIf $iCount -= 1 ; Delete one count $Temp_iCount -= 1; Delete one temp count If $Move_Top = 0 Then ; Equal to start posizion $Move_Top = $Temp_Move_Top * ($Element_For_Column - 1) Else $Move_Top -= 50 ; Delete one position EndIf EndFunc ;==>_Gui_DataInput_DeleteElement Func _DataInput_Middle(Const $win, Const $txt) ; Snippet Valuater - cdkid Local Const $Size = WinGetClientSize($win, $txt) Local Const $y = (@DesktopHeight / 2) - ($Size[1] / 2) Local Const $x = (@DesktopWidth / 2) - ($Size[0] / 2) Return WinMove($win, $txt, $x, $y) EndFunc ;==>_Gui_DataInput_Middle ;-------------------------------------------------------- Func TogglePause() $Paused = NOT $Paused While $Paused sleep(200) ToolTip('Script is "Paused"',0,0) WEnd ToolTip("") EndFunc Func Terminate() Exit 0 EndFunc Link to comment Share on other sites More sharing options...
Subz Posted April 5, 2021 Share Posted April 5, 2021 Recommend adding error handling to your code, personally found the code difficult to follow, it appears the issues are related to the _DataInput_AddElement() function where you are creating multiple GuiCtrlCreateInput controls on top of each other. Link to comment Share on other sites More sharing options...
NewBieAuto Posted April 6, 2021 Author Share Posted April 6, 2021 My command runs normally. But there is an error like in the video that I don't understand why error.avi Link to comment Share on other sites More sharing options...
Subz Posted April 6, 2021 Share Posted April 6, 2021 As mentioned above the _DataInput_AddElements is adding multiple input controls on top of each other, replace rows 217 - 221 with the following, now re-run your test and you'll see what I mean. $ArrElement[UBound($ArrElement) - 1][1] = GUICtrlCreateInput('First Control' , 8, 35 + $Move_Top, 161, 21) if GUICtrlRead($Gui_DataInput_EditRadio) = 1 Then $ArrElement[UBound($ArrElement) - 1][2] = GUICtrlCreateButton('Input by Edit' , 170, 33 + $Move_Top, 80, 25, $BS_MULTILINE) Else $ArrElement[UBound($ArrElement) - 1][1] = GUICtrlCreateInput('Second Control' , 8, 35 + $Move_Top, 161, 21) EndIf NewBieAuto 1 Link to comment Share on other sites More sharing options...
NewBieAuto Posted April 6, 2021 Author Share Posted April 6, 2021 Haha! Thank you very much. I am so sloppy 😅😅 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