iresolver Posted April 20, 2015 Share Posted April 20, 2015 hey guys I have an Auto Login script that has a GUI with an input field & a combo box with a list inside of 1 to10 what I want to have happen is when I type in a Email account into the input field it disables or removes number 1 from the combo box I have this but it only does it when I click the button in GUI not when I Type into the input field If $Password <> "" Then If StringRegExp($Account, "..*@gmail.com") Then If $n = 1 Then GUICtrlSetData($cCombo_AccType[1], 3) Add_MoreGmail() Else If $n <> 1 Then $Account = GUICtrlRead($Input1) $Password = GUICtrlRead($Input1_Pass) $n = GUICtrlRead($cCombo_AccType[1]) _GUICtrlComboBox_DeleteString($cCombo_AccType[1], 0) MsgBox($MB_SYSTEMMODAL, "", "string deleted"& $Account) Add_MoreGmail() I don't want the user to input two gmail accounts with the same account type so I want the account type 1 removed from the list if the user types a gmail account the 2nd time anyone know how I can do this? thanks guys AddEmail_GUI_Working.au3 Link to comment Share on other sites More sharing options...
iresolver Posted April 21, 2015 Author Share Posted April 21, 2015 (edited) here is the full script expandcollapse popup#include <GUIConstantsEx.au3> #Include <GuiComboBox.au3> #include <IE.au3> #include <ComboConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <GuiComboBoxEx.au3> #include <GuiToolbar.au3> #include <Array.au3> Opt("GUIOnEventMode", 1) AutoItSetOption ( "TrayIconDebug", 1 ) Opt('MustDeclareVars', 1) Global $sFilePath = @ScriptDir & "\AddEmail_GUI_Working.au3" Global $AddEmail_GUI, $aTaskbar, $aWin,$Input1, $Input1_Pass, $iLine ;------------------------------------------- Accounts will go here ---------------------------------------------------------------------------- ;------------------------------------------ Accounts go here END ------------------------------------------------------------------------------------------ AccType() Func AccType() $AddEmail_GUI = GUICreate("Auto Add Email", 509, 452, @DesktopWidth, @DesktopHeight) $aTaskbar = WinGetPos("[CLASS:Shell_TrayWnd]", "") $aWin = WinGetPos($AddEmail_GUI) WinMove($AddEmail_GUI, "", @DesktopWidth - $aWin[2] - 4, @DesktopHeight - $aWin[3] - $aTaskbar[3] - 180) Global $AddAccount_Button = GUICtrlCreateButton("Add Account", 368, 182, 105, 41) GUICtrlSetTip(-1, "Click To Add Your Account") GUICtrlSetFont(-1, 10, 800, 0, "Arial") $Input1 = GUICtrlCreateInput("", 24, 56, 457, 21) $Input1_Pass = GUICtrlCreateInput("", 24, 120, 457, 21) Global $cCombo_AccType[10] $cCombo_AccType[1] = GUICtrlCreateCombo("", 320, 192, 33, 25) GUICtrlSetData($cCombo_AccType[1], "1|2|3|4|5|6|7|8|9|10", "") GUISetState() ; Run the GUI until the dialog is closed GUICtrlSetFont(-1, 8, 400, 0, "Arial") Global $Label_AccType = GUICtrlCreateLabel("Must Select a Type of Account Before you Submit", 40, 186, 272, 17) GUICtrlSetTip(-1, "You can add up to 10 Accounts for each type ") GUICtrlSetFont(-1, 9, 400, 0, "Arial") ;Global $RemoveAll_Button = GUICtrlCreateButton("Remove All", 296, 368, 105, 41) ;GUICtrlSetTip(-1, "Click To Remove All Emails") ;GUICtrlSetFont(-1, 9, 800, 0, "Arial") Global $Label_Input1 = GUICtrlCreateLabel("Enter a Gmail or Hotmail or Live Account", 24, 32, 275, 17) GUICtrlSetFont(-1, 10, 800, 0, "Arial") Global $Label_Input1Pass = GUICtrlCreateLabel("Enter the Password for that Account", 24, 96, 249, 17) GUICtrlSetFont(-1, 10, 800, 0, "Arial") Global $Label_Primary = GUICtrlCreateLabel("1 = Primary", 136, 208, 72, 17) GUICtrlSetTip(-1, "Primary is the selected account in Drop Down List") GUICtrlSetFont(-1, 9, 400, 0, "Arial") Global $Label_Secondary = GUICtrlCreateLabel("2 = Secondary", 224, 208, 79, 17) GUICtrlSetTip(-1, "Secondary Accounts become Primary if no Primary are added") GUICtrlSetFont(-1, 9, 400, 0, "Arial") ;Global $Label_RemoveAll = GUICtrlCreateLabel("Remove All Accounts From Script", 267, 416, 162, 17) ;GUICtrlSetFont(-1, 8, 400, 0, "Arial") ;Global $Reset_Button = GUICtrlCreateButton("Reset", 104, 365, 105, 41) ;GUICtrlSetTip(-1, "Click To Reset Script to Defualt") ;GUICtrlSetFont(-1, 9, 800, 0, "Arial") ;Global $Label_ResettoDefualt = GUICtrlCreateLabel("Resets Script To Defualts", 93, 416, 127, 18) ;GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close") GUICtrlSetOnEvent(-1, "On_Button") GUICtrlSetOnEvent(14, "On_Button") GUICtrlSetOnEvent(8, "On_Button") GUICtrlSetOnEvent(3, "On_Button") GUISetState() EndFunc Func On_Button() Switch @GUI_CTRLID Case $AddAccount_Button Add_MultiEmail() EndSwitch EndFunc Global $AutoEmail_GUI Global $AddYourEmail_Button Func On_Close() Switch @GUI_WINHANDLE Case $AddEmail_GUI Exit Case $AddEmail_GUI GUIDelete($AddEmail_GUI) GUICtrlSetState($AddYourEmail_Button, $GUI_ENABLE) EndSwitch EndFunc Func Add_MultiEmail() Global $Account = GUICtrlRead($Input1) Global $Password = GUICtrlRead($Input1_Pass) Global $n = GUICtrlRead($cCombo_AccType[1]) If $Account = "" Then MsgBox($MB_SYSTEMMODAL, "Account Error", "You Must Enter a Gmail or Hotmail or Live Account ") Else If $Password = "" Then MsgBox($MB_SYSTEMMODAL, "Account Error", "You Must Enter a Password") Else If $Account <> "" Then If $Password <> "" Then If $n = 0 Then MsgBox($MB_SYSTEMMODAL, "Account Error", "You Must Select Account Type") Else If $Account <> "" Then If $Password <> "" Then $Account = GUICtrlRead($Input1) $Password = GUICtrlRead($Input1_Pass) $n = GUICtrlRead($cCombo_AccType[1]) If $Password <> "" Then If StringRegExp($Account, "..*@gmail.com") Then If $n = 1 Then GUICtrlSetData($cCombo_AccType[1], 2) Add_MoreGmail() Else If $n <> 1 Then $Account = GUICtrlRead($Input1) $Password = GUICtrlRead($Input1_Pass) $n = GUICtrlRead($cCombo_AccType[1]) _GUICtrlComboBox_DeleteString($cCombo_AccType[1], 0) MsgBox($MB_SYSTEMMODAL, "", "Combo item 1 Deleted") Add_MoreGmail() Else EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf Endfunc Func Add_MoreGmail() If $n = 1 Then Local $iLine = "34" If $n = 2 Then Local $iLine = "36" If $n = 3 Then Local $iLine = "38" If $n = 4 Then Local $iLine = "40" If $n = 5 Then Local $iLine = "42" If $n = 6 Then Local $iLine = "44" If $n = 7 Then Local $iLine = "46" If $n = 8 Then Local $iLine = "48" If $n = 9 Then Local $iLine = "50" If $n = 10 Then Local $iLine = "52" $Account= GUICtrlRead($Input1) $Password= GUICtrlRead($Input1_Pass) Global $USER_INPUT = "Global $GmailAccount"&($n)& " = " & '"' & ($Account) & '"' Global $USER_PASS = "Global $GmailPassword"&($n)& " = " & '"' & ($Password) & '"' _FileWriteToLine($sFilePath, $iLine, $USER_PASS) _FileWriteToLine($sFilePath, $iLine, $USER_INPUT) GUICtrlSetData($Input1,"") ;This Clears the input1 box GUICtrlSetData($Input1_Pass,"") ;This Clears the input1 pass box MsgBox($MB_SYSTEMMODAL, "Gmail", "You added "&$Account& " at Line "&$iLine) EndFunc While 1 $cCombo_AccType[2] = GUIGetMsg() Select Case $cCombo_AccType[2] = $GUI_EVENT_CLOSE Exit Case $cCombo_AccType[2] = $cCombo_AccType[1] MsgBox(64,"test",GUICtrlRead($cCombo_AccType[1])) EndSelect WEnd AddEmail_GUI_Working.au3 Edited April 21, 2015 by iresolver Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 21, 2015 Moderators Share Posted April 21, 2015 iresolver,I am sorry to have to say this but that is one of the worst scripts I have ever tried to debug. You are mixing OnEvent & MessageLoop modes; you have multiple redundant If..Then statements; you are even trying to store data within the script itself; and its layout was a real mess. I tried to clean it up (and I even got it to run) but I found it almost impossible to determine what you are trying to do. For example, you have 10 entries in the combo and yet you seem to tell the user that they can only choose "1/2" - so why are the other entries even in there?Here is a simplified version which I think does what you want. It stores the entered email data in an ini file in the same folder and automatically removes from the combo any of the numbers 1-10 that have already been used so that they cannot be accidentally overwritten:expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Opt("GUIOnEventMode", 1) Opt('MustDeclareVars', 1) Global $sFilePath = @ScriptDir & "\AddEmail.ini" Global $AddEmail_GUI, $AddAccount_Button, $Input1, $Input1_Pass, $cCombo_AccType, $sComboData AccType() While 1 Sleep(10) ; No point in using GUIGetMsg in OnEvent mode <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< WEnd Func AccType() $AddEmail_GUI = GUICreate("Auto Add Email", 509, 452) ; Simplified GUI for testing <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $AddAccount_Button = GUICtrlCreateButton("Add Account", 368, 182, 105, 41) $Input1 = GUICtrlCreateInput("", 24, 56, 457, 21) $Input1_Pass = GUICtrlCreateInput("", 24, 120, 457, 21) $cCombo_AccType = GUICtrlCreateCombo("", 320, 192, 33, 25) _Set_ComboData() ; Check to see what values are already filled and never put them in the combo <<<<<<<<<<<<<<<<<<< ; No point in storing label ControlIDs if you never use them <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlCreateLabel("Must Select a Type of Account Before you Submit", 40, 186, 272, 17) GUICtrlCreateLabel("Enter a Gmail or Hotmail or Live Account", 24, 32, 275, 17) GUICtrlCreateLabel("Enter the Password for that Account", 24, 96, 249, 17) GUICtrlCreateLabel("1 = Primary", 136, 208, 72, 17) GUICtrlCreateLabel("2 = Secondary", 224, 208, 79, 17) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close") GUICtrlSetOnEvent($AddAccount_Button, "On_Button") ; Always use the variable and never the actual value <<<<<<<<<< GUICtrlSetOnEvent($cCombo_AccType, "_On_Combo") ; Check the combo like this, not in the idle loop <<<<<<<<<<<<<<<< GUISetState() EndFunc ;==>AccType Func On_Close() Switch @GUI_WinHandle Case $AddEmail_GUI Exit ; Second Case removed - how was it evr going to run <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndSwitch EndFunc ;==>On_Close Func _On_Combo() MsgBox(64, "test", GUICtrlRead($cCombo_AccType)) ; Now the combo will be read when the value changes <<<<<<<<<<<<< EndFunc Func On_Button() Switch @GUI_CtrlId Case $AddAccount_Button Add_MultiEmail() EndSwitch EndFunc ;==>On_Button Func _Set_ComboData() Local $sComboData = "|1|2|3|4|5|6|7|8|9|10|" ; All possible values with a trailing "|" <<<<<<<<<<<<<<<<<<<<<<<<<<< Local $aAccounts = IniReadSection($sFilePath, "Gmail") ; Read the ini file to see what is already there <<<<<<<<<< If Not @error Then For $i = 1 To $aAccounts[0][0] ; Loop through the contents and remove all numbers found <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $sComboData = StringReplace($sComboData, "|" & $aAccounts[$i][0] & "|", "|") Next EndIf GUICtrlSetData($cCombo_AccType, StringTrimRight($sComboData, 1)) ; And fill the combo with what is left (removing the trailing "|") <<<<<<< EndFunc Func Add_MultiEmail() Local $Account = GUICtrlRead($Input1) Local $Password = GUICtrlRead($Input1_Pass) Local $n = GUICtrlRead($cCombo_AccType) ; A rather simplified If...Then structure If $Account = "" Then MsgBox($MB_SYSTEMMODAL, "Account Error", "You Must Enter a Gmail or Hotmail or Live Account ") ElseIf $n = "" Then MsgBox($MB_SYSTEMMODAL, "Account Error", "You Must Select Account Type") ElseIf $Password = "" Then MsgBox($MB_SYSTEMMODAL, "Account Error", "You Must Enter a Password") Else If StringRegExp($Account, ".*@gmail.com") Then Add_MoreGmail($n) ; Pass the number as a parameter <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf EndIf EndFunc ;==>Add_MultiEmail Func Add_MoreGmail($n) Local $Account = GUICtrlRead($Input1) Local $Password = GUICtrlRead($Input1_Pass) IniWrite($sFilePath, "Gmail", $n, $Account & "|" & $Password) ; Add the account to the ini file <<<<<<<<<<<<<<<< _Set_ComboData() ; And reset the combo to remove that value <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetData($Input1, "") GUICtrlSetData($Input1_Pass, "") MsgBox($MB_SYSTEMMODAL, "Gmail", "You added " & $Account) EndFunc ;==>Add_MoreGmailPlease try it and let me know if it is anything like what you want. Please ask any questions you may have about what I have done or why I have done it (I have commented liberally as you can see) - and of course do explain if I have completely misunderstood what you were trying to do.Just for future interest, I noted that you have commented out the "Remove & Reset" buttons - the ini format makes this very easy to do should you decide to continue with something along these lines.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
iresolver Posted April 21, 2015 Author Share Posted April 21, 2015 I was trying to debug the one part of my script that has the problem the full script is much biger it needs to work for 10 accounts that's why i have 10 in the combo sorry for the confusion I will try your script and see how it goes thank you melba23 Link to comment Share on other sites More sharing options...
kylomas Posted April 21, 2015 Share Posted April 21, 2015 M23 - Good Luck, I tried >here to no avail... Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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