Jump to content

Recommended Posts

  • Moderators
Posted (edited)

dreamzboy,

Just add another check to my previous contribution: :)

#include <Constants.au3>

$host_Count = 0
$ip_Count = 0
$pw_Count= 0

If ($host_Count <> 0) And ($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 or all are zero")
EndIf
M23 Edited by Melba23
Fixed tags

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (edited)

Thanks Melba.  That looks easy enough; however, I'm suspecting there's a bug with AutoIT.

The script still executed regardless if I have no entry or with one field entered.

cy1d.jpg

crxr.jpg

#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, $j
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"
Local $tabs[4] = [3, 29, 0, 0]

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, $LBS_USETABSTOPS))
$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 ()

_GUICtrlListBox_SetTabStops ($log_label, $tabs)

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)
        ; MsgBox (0, "", $host_Count)
        $ip_address = StringSplit (GUICtrlRead ($ip_input), @CRLF, 3)
        $ip_Count = UBound ($ip_address)
        ; MsgBox (0, "", $ip_Count)
        $password = StringSplit (GUICtrlRead ($pw_input), @CRLF, 3)
        $pw_Count = UBound ($password)
        ; MsgBox (0, "", $pw_Count)

        If ($host_Count <> 0) And ($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)
            GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  It works!")
            For $i = 0 To $host_Count - 1
                ;MsgBox (0, "", $hostname[$i]
                _GUICtrlListBox_AddString ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  " & $hostname[$i] & @CRLF)
                _GUICtrlListBox_AddString ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  " & $ip_address[$i] & @CRLF)
                _GUICtrlListBox_AddString ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  " & $password[$i] & @CRLF)
            Next
        Else
            ;Msgbox($mb_ok,'FALSE', $ip_Count & @crlf & $host_Count & @crlf & $pw_Count)
            _GUICtrlListBox_AddString ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  Error - One or more fields doesn't match!")
            _GUICtrlListBox_AddString ($log_label, @TAB & "  Remove white space and/or extra entry ")
            _GUICtrlListBox_AddString ($log_label, @TAB & "  before trying again.")
            ;GUICtrlSetData ($log_label, @TAB & "  Remove white space and/or extra entry before trying again." & @CRLF)
        Endif

        _GUICtrlListBox_UpdateHScroll ($log_label)
        Sleep (1000)

    Case $msg = $clrLog_btn
        GUICtrlSetData ($log_label, "") ; Clear log file
   EndSelect
Until 0
Edited by dreamzboy
Posted

I found the problem to this.  The empty lines are considered as one entry.  If I place my cursor in the edit box and enter nothing, it would account it as one entry.

Posted (edited)

Right, you can avoid this by the use of StringRegExp instead of StringSplit

#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, $j
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"
Local $tabs[4] = [3, 29, 0, 0]

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, $LBS_USETABSTOPS))
$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 ()

_GUICtrlListBox_SetTabStops ($log_label, $tabs)

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)
        $hostname = StringRegExp(GUICtrlRead ($hn_input), '\V+', 3)
    ;_ArrayDisplay($hostname)
        $host_Count = UBound ($hostname)
        ; MsgBox (0, "", $host_Count)
        ;$ip_address = StringSplit (GUICtrlRead ($ip_input), @CRLF, 3)
        $ip_address = StringRegExp(GUICtrlRead ($ip_input), '\V+', 3) 
        $ip_Count = UBound ($ip_address)
        ; MsgBox (0, "", $ip_Count)
        ;$password = StringSplit (GUICtrlRead ($pw_input), @CRLF, 3)
        $password = StringRegExp(GUICtrlRead ($pw_input), '\V+', 3) 
        $pw_Count = UBound ($password)
        ; MsgBox (0, "", $pw_Count)

        If ($host_Count <> 0) And ($host_Count = $ip_Count And $host_Count = $pw_Count ) Then
            ;Msgbox($mb_ok,'TRUE', $host_Count & @crlf & $ip_Count & @crlf & $pw_Count)
            GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  It works!")
            For $i = 0 To $host_Count - 1
                ;MsgBox (0, "", $hostname[$i])
                _GUICtrlListBox_AddString ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  " & $hostname[$i]); & @CRLF)
                _GUICtrlListBox_AddString ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  " & $ip_address[$i]); & @CRLF)
                _GUICtrlListBox_AddString ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  " & $password[$i]); & @CRLF)
            Next
        Else
            ;Msgbox($mb_ok,'FALSE', $ip_Count & @crlf & $host_Count & @crlf & $pw_Count)
            _GUICtrlListBox_AddString ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  Error - One or more fields doesn't match!")
            _GUICtrlListBox_AddString ($log_label, @TAB & "  Remove white space and/or extra entry ")
            _GUICtrlListBox_AddString ($log_label, @TAB & "  before trying again.")
            ;GUICtrlSetData ($log_label, @TAB & "  Remove white space and/or extra entry before trying again." & @CRLF)
        Endif

        _GUICtrlListBox_UpdateHScroll ($log_label)
        Sleep (1000)

    Case $msg = $clrLog_btn
        GUICtrlSetData ($log_label, "") ; Clear log file
   EndSelect
Until 0

Edit

For whites spaces eventually remaining on an empty line better use this

$hostname = StringRegExp(GUICtrlRead ($hn_input), '(\V+)\s*', 3)
Edited by mikell

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...