Jump to content

Field checking ( GUI )


Recommended Posts

Good morning guys :)
How are you? Hope you're fine :)
I'm doing some field checking...
Can you suggest me something? Something like: If the user doesn't prompt anything in a field, MsgBox and focus on the "blank" field, else, keep up with the script.
I thought on a nested If...Else, but I have something like 10+ edit to control...
Thanks guys! 

EDIT:

And I would like to know either how to retrieve all listview item ( 2 columns ) from a ListView...
Column A|Column B
abcd         | 1234
bcda         | 1432
How can I retrieve an array with abcd|1234|bcda|1432 ?
Thanks :D 
 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

You can do something like this.

#include <GUIConstantsEx.au3>
#include <GUIToolTip.au3>

; Create a GUI with various controls.
Global $hGUI = GUICreate("Example", 210, 670)
Global $idBtnCheck = GUICtrlCreateButton("Check", 60, 630, 80, 30)
Global $aEdit[20]

For $i = 0 To UBound($aEdit) - 1
    $aEdit[$i] = GUICtrlCreateInput("", 30, ($i + 1) * 30, 150,20)
Next

; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)


; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $idBtnCheck
            If _CheckEdits() Then
                MsgBox(0,"","All fields OK")
            EndIf
    EndSwitch
WEnd

; Delete the previous GUI and all controls.
GUIDelete($hGUI)


Func _CheckEdits()
    For $i=0 to UBound($aEdit)-1
        If GUICtrlRead($aEdit[$i])="" Then
            ConsoleWrite($i & @CRLF)
            Local $aGUIPos = WinGetPos($hGUI)
            Local $aCtrlPos = ControlGetPos($hGUI, "", $aEdit[$i])
            ToolTip("You must fill this input", $aGUIPos[0] + $aCtrlPos[0] + 150, $aGUIPos[1] + $aCtrlPos[1] + 30,"",0,1)
            AdlibRegister(_HideToolTip,2000)
            _ColorNotification($aEdit[$i])
            Return False
        EndIf
    Next
    Return True
EndFunc

Func _ColorNotification($ID)
    For $i=1 to 15
        GUICtrlSetBkColor($ID,Random(0, 0xFFFFFF, 1))
        Sleep(50)
    Next
    GUICtrlSetBkColor($ID,0xFFFFFF)
EndFunc

Func _HideToolTip()
    ToolTip("")
    AdlibUnRegister(_HideToolTip)
EndFunc

Saludos

Link to comment
Share on other sites

@Danyfirex
Thanks for your reply :) It's literally what I was looking for... But, I was asking to me... There's nothing a little "easier"? Because, I have edit(s) with different names, so, I don't know how to apply your great code to my case...

4 minutes ago, Subz said:

For your latter query: _GUICtrlListView_GetItemTextArray

I did with that function, but it returns me an array with a number instead of data...
Thanks guys :) 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

If you want to apply to your code just create  the array $aEdit with the id of your inputs.  

If you have 3 inputs

 

just do

global $aEdit[3]=[$yourinput1,$yourinput2,$yourinput3]

and add the required functions.

 

Saludos

Link to comment
Share on other sites

@Danyfirex
And If I have these edit in a function, how can I do it?
I have something like this:
 

; I work with Opt(GUIOnEventMode, "1")...

Global $input_1

Func Example()
    $sInput = GUICtrlRead($input_1)
    ; There's no other way to get what I would like to do ( see above ) 
    ; If all "required" inputs have been filled, then do a query...
EndFunc

Thanks for your help :) 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

It should be something like this:

Global $input_1,$input_2,$input_3
Global $aEdit[3]


Func Example()
    $sInput1 = GUICtrlRead($input_1)
    $sInput2 = GUICtrlRead($input_2)
    $sInput3 = GUICtrlRead($input_3)
   $aEdit[0]=$input_1
   $aEdit[1]=$input_2
   $aEdit[2]=$input_3
    ; There's no other way to get what I would like to do ( see above )
    ; If all "required" inputs have been filled, then do a query...
    
    ;in Your botton or event  add
    If _CheckEdits() Then
            ;do the query   
    EndIf
EndFunc

 

@jguinch I know. I just stole a Melba23's old snippet.

 

Saludos

Link to comment
Share on other sites

You can try the following function, just change the second parameter to False to return a string or True for an Array

Func _GuiCtrlListView_GetArray($hWnd, $bArray = True)
    Local $iListView = _GUICtrlListView_GetItemCount($hWnd)
    Local $aListViewItem
    If $iListView > 0 Then
        Local $aListView[1][_GUICtrlListView_GetColumnCount($hWnd)]
        For $i = 0 To $iListView - 1
            $aListViewItem = _GUICtrlListView_GetItemTextArray($hWnd, $i)
            _ArrayDelete($aListViewItem, 0)
            _ArrayTranspose($aListViewItem)
            _ArrayAdd($aListView, _ArrayToString($aListViewItem))
        Next
    EndIf
    $aListView[0][0] = UBound($aListView) - 1
    If $bArray = True Then
        Return $aListView
    Else
        $sListView = _ArrayToString($aListView, '|', 1, -1, '|')
        Return $sListView
    EndIf
EndFunc

 

Link to comment
Share on other sites

@Subz
It works perfectly, thanks! :D
But, why does _GUICtrlListView_GetItemTextArray() doesn't work?
Maybe I'm not using it properly?
Theoretically, If I use it in this way:

 

Local $aArray = _GUICtrlListView_GetItemTextArray($lv_Listview)
_ArrayDisplay($aArray)

it should return all the listview item, or not?
Because, in my case, it returns just the number 2...
Can you please explain me why? Thanks :D 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

@Subz
Good morning :)
How can I access to single elements of the array that your function returns? Thanks :) 

EDIT:

I found how... I asked because I don't know how to write them through _Excel_RangeWrite() :)

EDIT2:

The array returns with 1 blank line... How could I fix it? :) 
Thanks :D 

EDIT3:

Done :D

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
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
 Share

×
×
  • Create New...