Jump to content
Sign in to follow this  
john123

Help me about code for button on tab

Recommended Posts

john123

I have form below (in attach file), I want to write text in input1 box on tab1 into data1.ini file. And same for tab2 and tab3. please help me write code for button OK, Cancel, Apply to write text in input box into files. Thanks for your help. Thanks very much.

Form.au3

Share this post


Link to post
Share on other sites
martin

I have form below (in attach file), I want to write text in "input1" box on tab1 into "data1.ini" file. And same for tab2 and tab3. please help me write code for button "OK", "Cancel", "Apply" to write text in input box into files. Thanks for your help. Thanks very much.

Welcome to the AutoIt forums john123 :P

Here is a way to write the text from the inoputs to files when the OK button is pressed.

#include <ButtonConstants.au3>
  #include <EditConstants.au3>
  #include <GUIConstantsEx.au3>
  #include <TabConstants.au3>
  #include <WindowsConstants.au3>
  #include <file.au3>
  
  
  #Region ### START Koda GUI section ### Form=
  $Form1 = GUICreate("Form1", 427, 284, 289, 124)
  $Tab1 = GUICtrlCreateTab(24, 24, 369, 209)
  GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
  $TabSheet1 = GUICtrlCreateTabItem("Tab1")
  $Input1 = GUICtrlCreateInput("Input1", 64, 104, 121, 21)
  
  $TabSheet2 = GUICtrlCreateTabItem("Tab2")
  $Input2 = GUICtrlCreateInput("Input2", 64, 104, 121, 21)
  
  $TabSheet3 = GUICtrlCreateTabItem("Tab3")
  GUICtrlSetState(-1, $GUI_SHOW)
  $Input3 = GUICtrlCreateInput("Input3", 72, 112, 121, 21)
  
  
  GUICtrlCreateTabItem("")
  $B_Ok = GUICtrlCreateButton("OK", 144, 240, 75, 25, 0)
  $B_Cancel = GUICtrlCreateButton("Cancel", 224, 240, 75, 25, 0)
  $B_Apply = GUICtrlCreateButton("Apply", 304, 240, 75, 25, 0)
  GUISetState(@SW_SHOW)
  
  If FileExists(@ScriptDir & "\data1.ini") Then
   GUICtrlSetData($Input1, FileRead(@ScriptDir & "\data1.ini"))
   EndIf
   
   If FileExists(@ScriptDir & "\data2.ini") Then
   GUICtrlSetData($Input2, FileRead(@ScriptDir & "\data2.ini"))
   EndIf
   
   If FileExists(@ScriptDir & "\data3.ini") Then
   GUICtrlSetData($Input3, FileRead(@ScriptDir & "\data3.ini"))
   EndIf
  #EndRegion ### END Koda GUI section ###
  
  While 1
      $nMsg = GUIGetMsg()
      Switch $nMsg
          Case $GUI_EVENT_CLOSE
              Exit
  
          Case $B_Ok
              Switch GUICtrlRead($Tab1)
                  Case 0
                      ConsoleWrite(GUICtrlRead($Input1) & @CRLF)
                      $f = FileOpen(@ScriptDir & "\data1.ini", 2)
                       FileWrite($f,GUICtrlRead($Input1))
                       FileClose($f)
                  Case 1
                      ConsoleWrite(GUICtrlRead($Input2) & @CRLF)
                      $f = FileOpen(@ScriptDir & "\data2.ini", 2)
                       FileWrite($f,GUICtrlRead($Input2))
                       FileClose($f)
                  Case 2
                      ConsoleWrite(GUICtrlRead($Input3) & @CRLF)
                      $f = FileOpen(@ScriptDir & "\data3.ini", 2)
                       FileWrite($f,GUICtrlRead($Input3))
                       FileClose($f)
              EndSwitch
          Case $B_Cancel
           ;something
          Case $B_Apply
           ;something else
              
      EndSwitch
  WEnd

It would be easier to use one ini files as an ini file instead of a text file and then you could do this

#include <ButtonConstants.au3>
  #include <EditConstants.au3>
  #include <GUIConstantsEx.au3>
  #include <TabConstants.au3>
  #include <WindowsConstants.au3>
  #include <file.au3>
  
  
  #Region ### START Koda GUI section ### Form=
  $Form1 = GUICreate("Form1", 427, 284, 289, 124)
  $Tab1 = GUICtrlCreateTab(24, 24, 369, 209)
  GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
  $TabSheet1 = GUICtrlCreateTabItem("Tab1")
  $Input1 = GUICtrlCreateInput("Input1", 64, 104, 121, 21)
  
  $TabSheet2 = GUICtrlCreateTabItem("Tab2")
  $Input2 = GUICtrlCreateInput("Input2", 64, 104, 121, 21)
  
  $TabSheet3 = GUICtrlCreateTabItem("Tab3")
  GUICtrlSetState(-1, $GUI_SHOW)
  $Input3 = GUICtrlCreateInput("Input3", 72, 112, 121, 21)
  
  
  GUICtrlCreateTabItem("")
  $B_Ok = GUICtrlCreateButton("OK", 144, 240, 75, 25, 0)
  $B_Cancel = GUICtrlCreateButton("Cancel", 224, 240, 75, 25, 0)
  $B_Apply = GUICtrlCreateButton("Apply", 304, 240, 75, 25, 0)
  GUISetState(@SW_SHOW)
  
  If FileExists(@ScriptDir & "\data.ini") Then
   GUICtrlSetData($Input1, IniRead(@ScriptDir & "\data.ini","Text","Input1","input1"))
   GUICtrlSetData($Input2, IniRead(@ScriptDir & "\data.ini","Text","Input2","input2"))
   GUICtrlSetData($Input3, IniRead(@ScriptDir & "\data.ini","Text","Input3","input3"))
   EndIf
   
  
  #EndRegion ### END Koda GUI section ###
  
  While 1
      $nMsg = GUIGetMsg()
      Switch $nMsg
          Case $GUI_EVENT_CLOSE
              Exit
  
          Case $B_Ok
              Switch GUICtrlRead($Tab1)
                  Case 0
                      ConsoleWrite(GUICtrlRead($Input1) & @CRLF)
                      IniWrite(@ScriptDir & "\data.ini","Text","Input1",GUICtrlRead($Input1))
                  Case 1
                      ConsoleWrite(GUICtrlRead($Input2) & @CRLF)
                      
                       IniWrite(@ScriptDir & "\data.ini","Text","Input2",GUICtrlRead($Input2))
                  Case 2
                      ConsoleWrite(GUICtrlRead($Input3) & @CRLF)
                      IniWrite(@ScriptDir & "\data.ini","Text","Input3",GUICtrlRead($Input3))
              EndSwitch
          Case $B_Cancel
           ;something
          Case $B_Apply
           ;something else
              
      EndSwitch
  WEnd

EDIT:removed incorrectly included line in Case 1 in second version.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
john123

Thanks martin. You're great man. I love you. Thanks again.

Have a nice day.

Share this post


Link to post
Share on other sites
martin

Thanks martin. You're great man. I love you. Thanks again.

Have a nice day.

NP.

I made a mistake in Case 1 with an extra line which I have now corrected.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
john123

Thank you, Martin.

Please help me one other problem. In tab3, I have a combo box to chose "John" and "Smith", I want to display a message when I chose a item from combo box without press "OK" button. Please help me this problem.

I'm sorry to trouble you!

Thank you so much.

Form2.au3

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  

×