dreamzboy Posted November 4, 2013 Share Posted November 4, 2013 (edited) I have 3 input boxes and I wanted to make sure all the entries entered in are equal before proceeding with the script. The statement that I used If ($host_Count = $ip_Count = $pw_Count) only compared the first 2 variables and "ignored" the last variable, $pw_Count. The script will execute regardless of what value $pw_Count holds. Same thing happened if I were to use "AND" instead of equal sign. How can I compare all 3 variables to make sure they all matches? expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <ButtonConstants.au3> #include <GuiListBox.au3> #include <array.au3> Opt ("TrayIconDebug", 1) Local $ribcl_temp = '', $xml_temp, $i Local $hn_input, $ip_input, $pw_input Local $host_Count, $ip_Count, $pw_Count Local $msg, $success, $password, $hostname, $ip_address Local $log_label, $generate_btn, $clrLog_btn Local $test_str0 = "dl360g7-25" & @CRLF & "dl360g7-26" & @CRLF & "dl360g7-27" Local $test_str1 = "10.112.15.22" & @CRLF & "10.112.15.23" & @CRLF & "10.112.15.24" Local $test_str2 = "pass1" & @CRLF & "pass2" & @CRLF & "pass3" GUICreate ("Test", 600, 450) GUICtrlCreateLabel ("1. Enter hostname (ex: dl360g7-25):", 30, 70, 250, 20) GUICtrlSetFont (-1, 10) $hn_input = GUICtrlCreateEdit ("", 30, 90, 215, 70) GUICtrlSetData ($hn_input, $test_str0) GUICtrlCreateLabel ("2. Enter iLO static IP address:", 30, 180, 250, 20) GUICtrlSetFont (-1, 10) $ip_input = GUICtrlCreateEdit ("", 30, 200, 215, 70) GUICtrlSetData ($ip_input, $test_str1) GUICtrlCreateLabel ("3. Enter iLO default password:", 30, 290, 200, 20) GUICtrlSetFont (-1, 10) $pw_input = GUICtrlCreateEdit ("", 30, 310, 215, 70) GUICtrlSetData ($pw_input, $test_str2) $log_label = GUICtrlCreateList ("", 300, 90, 270, 292, BitOR($WS_BORDER, $WS_VSCROLL, $WS_HSCROLL)) $generate_btn = GUICtrlCreateButton ("Generate XML File", 55, 400, 150, 30) GUICtrlSetFont (-1, 10) GUICtrlCreateLabel ("version 2.0", 530, 425, 70) GUICtrlSetColor (-1, 0x0000cd) $clrLog_btn = GUICtrlCreateButton ("Clear Log", 385, 400, 100, 30) GUICtrlSetFont (-1, 10) GUISetState () Do $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $generate_btn ; Check entry simliarity on all fields $hostname = StringSplit (GUICtrlRead ($hn_input), @CRLF, 3) $host_Count = UBound ($hostname) $ip_address = StringSplit (GUICtrlRead ($ip_input), @CRLF, 3) $ip_Count = UBound ($ip_address) $password = StringSplit (GUICtrlRead ($pw_input), @CRLF, 3) $pw_Count = UBound ($password) If ($host_Count = $ip_Count = $pw_Count) Then MsgBox (0, "", $host_Count) MsgBox (0, "", $ip_Count) MsgBox (0, "", $pw_Count) Else GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & " Error - One or more fields doesn't match!") MsgBox (48, "Error", "One or more field does not match! Please check the entries and try again.") EndIf _GUICtrlListBox_UpdateHScroll ($log_label) Sleep (1000) Case $msg = $clrLog_btn GUICtrlSetData ($log_label, "") ; Clear log file EndSelect Until 0 Edited November 4, 2013 by dreamzboy Link to comment Share on other sites More sharing options...
JayHawkfl Posted November 4, 2013 Share Posted November 4, 2013 Which of these three will be the most reliable or which would be the "primary" varable. You can compare the other two to the most "stable" or "reliable" one and get the results you want. It would look like If $host_Count and $ip_Count = $pw_Count Then Thanks for your time Link to comment Share on other sites More sharing options...
BrewManNH Posted November 4, 2013 Share Posted November 4, 2013 Which of these three will be the most reliable or which would be the "primary" varable. You can compare the other two to the most "stable" or "reliable" one and get the results you want. It would look like If $host_Count and $ip_Count = $pw_Count Then That would evaluate to true if $host_count held anything other than 0 and $ip_count was equal to $pw_count, it would not check to see if $host_count was equal to any other variable in the comparison. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
dreamzboy Posted November 4, 2013 Author Share Posted November 4, 2013 It didn't work. If ($host_Count And $ip_Count = $pw_Count) Then $host_Count = 2, $ip_Count = 3, $pw_Count = 3, the script still executed. The error is now reversed of what I had before with $pw_Count being ignored. Link to comment Share on other sites More sharing options...
JayHawkfl Posted November 4, 2013 Share Posted November 4, 2013 It didn't work. If ($host_Count And $ip_Count = $pw_Count) Then $host_Count = 2, $ip_Count = 3, $pw_Count = 3, the script still executed. The error is now reversed of what I had before with $pw_Count being ignored. I didn't have my full thoughts together, but apparently I'm off base any way. I'll tinker with it and get back to you Thanks for your time Link to comment Share on other sites More sharing options...
Developers Jos Posted November 4, 2013 Developers Share Posted November 4, 2013 try: If ($host_Count = $ip_Count And $ip_Count = $pw_Count) Then SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
kylomas Posted November 4, 2013 Share Posted November 4, 2013 (edited) dreamzboy, Try it like this (untested). Note how multiple vars are displayed in once instance of msgbox... if $host_count = $ip_count and $host_count = $pw_count then msgbox($mb_ok,'TRUE', $ip_count & @crlf & $host_count & @crlf & $pw_count) Else msgbox($mb_ok,'FALSE', $ip_count & @crlf & $host_count & @crlf & $pw_count) endif kylomas edit: $MB_OK is declared in CONSTANTS.AU3 Edited November 4, 2013 by kylomas 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...
dreamzboy Posted November 4, 2013 Author Share Posted November 4, 2013 (edited) Kylomas, I've tried your method and it tends to work with a bit of a problem as illustrated in the screenshot below. Notice the value $host_Count and $ip_Count didn't match. Same result with Jos's suggestion. Edited November 4, 2013 by dreamzboy Link to comment Share on other sites More sharing options...
dreamzboy Posted November 4, 2013 Author Share Posted November 4, 2013 I can probably live with the wrong count but unfortunately, my next line of code depends on the $host_Count. For $i = 0 To UBound ($hostname) - 1 Link to comment Share on other sites More sharing options...
AdamUL Posted November 4, 2013 Share Posted November 4, 2013 (edited) Since you are working with 3 values you will have 3 conditions. Try this.If $host_Count = $ip_Count And $ip_Count = $pw_Count And $host_Count = $pw_Count Then MsgBox($MB_OK,'TRUE', $ip_Count & @crlf & $host_Count & @crlf & $pw_Count) Else MsgBox($MB_OK,'FALSE', $ip_Count & @crlf & $host_Count & @crlf & $pw_Count) endifAdam Edited November 4, 2013 by AdamUL Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 4, 2013 Moderators Share Posted November 4, 2013 dreamzboy,I think that the comparison should be coded like this:#include <Constants.au3> $host_Count = 3 $ip_Count = 2 $pw_Count= 2 If ($ip_Count = $host_Count) And ($pw_Count = $host_Count) Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< MsgBox($MB_SYSTEMMODAL, "Result!", "All match") Else MsgBox($MB_SYSTEMMODAL, "Error!", "There is a mismatch") EndIfYou check that both the ip and pw totals match the host total - if that is the case then all of them must be the same. It certainly works when I test it - how about you? 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...
Gianni Posted November 4, 2013 Share Posted November 4, 2013 this should work to check if 3 or more variables have all the same value: $host_Count = 2 $ip_Count = 2 $pw_Count = 2 If $host_Count = BitAND($ip_Count, $pw_Count) Then ; <---- you can add up to 255 variables inside parenthesis MsgBox(0,"","all variables has same value") Else MsgBox(0,"","all variables has NOT the same value") EndIf Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
dreamzboy Posted November 4, 2013 Author Share Posted November 4, 2013 Thank you guys. Everyone's method works but my script seems to have glitches that I need to sort it out. Link to comment Share on other sites More sharing options...
kylomas Posted November 4, 2013 Share Posted November 4, 2013 dreamzboy, This works for me... expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <ButtonConstants.au3> #include <GuiListBox.au3> #include <array.au3> #include <constants.au3> Opt ("TrayIconDebug", 1) Local $ribcl_temp = '', $xml_temp, $i Local $hn_input, $ip_input, $pw_input Local $host_Count, $ip_Count, $pw_Count Local $msg, $success, $password, $hostname, $ip_address Local $log_label, $generate_btn, $clrLog_btn Local $test_str0 = "dl360g7-25" & @CRLF & "dl360g7-26" & @CRLF & "dl360g7-27" Local $test_str1 = "10.112.15.22" & @CRLF & "10.112.15.23" & @CRLF & "10.112.15.24" Local $test_str2 = "pass1" & @CRLF & "pass2" & @CRLF & "pass3" GUICreate ("Test", 600, 450) GUICtrlCreateLabel ("1. Enter hostname (ex: dl360g7-25):", 30, 70, 250, 20) GUICtrlSetFont (-1, 10) $hn_input = GUICtrlCreateEdit ("", 30, 90, 215, 70) GUICtrlSetData ($hn_input, $test_str0) GUICtrlCreateLabel ("2. Enter iLO static IP address:", 30, 180, 250, 20) GUICtrlSetFont (-1, 10) $ip_input = GUICtrlCreateEdit ("", 30, 200, 215, 70) GUICtrlSetData ($ip_input, $test_str1) GUICtrlCreateLabel ("3. Enter iLO default password:", 30, 290, 200, 20) GUICtrlSetFont (-1, 10) $pw_input = GUICtrlCreateEdit ("", 30, 310, 215, 70) GUICtrlSetData ($pw_input, $test_str2) $log_label = GUICtrlCreateList ("", 300, 90, 270, 292, BitOR($WS_BORDER, $WS_VSCROLL, $WS_HSCROLL)) $generate_btn = GUICtrlCreateButton ("Generate XML File", 55, 400, 150, 30) GUICtrlSetFont (-1, 10) GUICtrlCreateLabel ("version 2.0", 530, 425, 70) GUICtrlSetColor (-1, 0x0000cd) $clrLog_btn = GUICtrlCreateButton ("Clear Log", 385, 400, 100, 30) GUICtrlSetFont (-1, 10) GUISetState () Do $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $generate_btn ; Check entry simliarity on all fields $hostname = StringSplit (GUICtrlRead ($hn_input), @CRLF, 3) $host_Count = UBound ($hostname) $ip_address = StringSplit (GUICtrlRead ($ip_input), @CRLF, 3) $ip_Count = UBound ($ip_address) $password = StringSplit (GUICtrlRead ($pw_input), @CRLF, 3) $pw_Count = UBound ($password) if $host_count = $ip_count and $host_count = $pw_count then msgbox($mb_ok,'TRUE', $ip_count & @crlf & $host_count & @crlf & $pw_count) Else GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & " Error - One or more fields doesn't match!") MsgBox (48, "Error", "One or more field does not match! Please check the entries and try again.") EndIf _GUICtrlListBox_UpdateHScroll ($log_label) Sleep (1000) Case $msg = $clrLog_btn GUICtrlSetData ($log_label, "") ; Clear log file EndSelect Until 0 If you want to enforce case sensitivity, check out post #12 above (PincoPanco). This is much less cumbersome for multiple variables. kylomas 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...
dreamzboy Posted November 5, 2013 Author Share Posted November 5, 2013 If there were to be an empty line "@CRLF" at the end of the input string, all of the checks mentioned above would failed. Is there a way to check for new line so that the if statement would work as intended? I know there's a way somewhere in the forum but if you know a quick way to fix this, please let me know. Much appreciated, Dreamzboy Link to comment Share on other sites More sharing options...
mikell Posted November 5, 2013 Share Posted November 5, 2013 You have to do the job using : StringStripWS($the_string, 3) Link to comment Share on other sites More sharing options...
BrewManNH Posted November 5, 2013 Share Posted November 5, 2013 You should probably be using a ListBox instead of an Edit control to prevent the possibility of extra lines in your data. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
dreamzboy Posted November 5, 2013 Author Share Posted November 5, 2013 Thanks Mikell. I'll give that a try. You should probably be using a ListBox instead of an Edit control to prevent the possibility of extra lines in your data. Can the user copy/paste a list string into the box? I'm assuming it's one by one input. Do you have any example? Thanks! Link to comment Share on other sites More sharing options...
dreamzboy Posted November 5, 2013 Author Share Posted November 5, 2013 Actually, the white space is controlled by the if statement above. If it detects a white space, the script shouldn't run if the condition is true. I was overly excited that the script is working and forgot about that logic. Link to comment Share on other sites More sharing options...
dreamzboy Posted November 11, 2013 Author Share Posted November 11, 2013 (edited) Sorry guys, I just discovered that the condition is true even if all 3 inputs are zero. This is a bug. I do not want the script to run if there's no input. In short, the script can be ran if all 3 inputs are the same and all 3 cannot be zero. I'm not sure how to write the syntax or logic for it. What I do know is that this statement does not work. If ($host_Count = $ip_Count And $ip_Count = $pw_Count And $host_Count = $pw_Count) And (Not ($host_Count And $ip_Count And $pw_Count) = 0) Then Return 1; EndIf Edited November 11, 2013 by dreamzboy 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