FrancescoDiMuro

Field checking ( GUI )

14 posts in this topic

#1 ·  Posted (edited)

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

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
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

1 person likes this

Share this post


Link to post
Share on other sites

For your latter query: _GUICtrlListView_GetItemTextArray

Share this post


Link to post
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

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
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

Share this post


Link to post
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

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@jguinch, @Danyfirex
What about the reading of a listview?
Thanks :) 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#10 ·  Posted

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

 

Share this post


Link to post
Share on other sites

#11 ·  Posted

@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

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#12 ·  Posted

It only gets one line item, however you need to give it the index of the row, if you don't it returns just the number of columns in your case 2.

 

Share this post


Link to post
Share on other sites

#13 ·  Posted

@Subz
Thanks for your explanation and for your help buddy!
I mentioned you in my script as I promised to everyone who would help me :)
Have a wonderful day :) 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

@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

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

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

  • Similar Content

    • Skeletor
      By Skeletor
      MS Splash Screens
      The office 2016/17 office suite has made many people turn heads with its functions and especially their splash screen.
      I now present to you, the MS Style Splash Screen. For Rookies, Novices and anyone who wants a ready made splash screen for your gui application.

      You can now download it and also try it out yourself.
      You have three colors to choose from:
      Blue
      Red
      Green
      All three colours are from the famous programs.
      I also included the KODA form to you can have freedom with this splash screen.
      Note: the KODA form does not have the three colours as well as the correct blue. 

      Have fun and enjoy.
      Note:
      I will update the splash to add the automated 3 dots animation at a later stage. 
       
       
    • Skeletor
      By Skeletor
      A gui splash screen. Themed after the famous MS Office Suite.
      Three colours to choose from, Red, Blue and Green.
      You can change the labels to your own application.

      Also bundled with this is the KODA form. So you can open up and see the basic structure of this splash screen.
       
      Splash Screen GUI.zip
    • BlazerV60
      By BlazerV60
      Hello all,
      I've been trying to figure out how to launch Google Chrome in the background (hidden) but it doesn't seem possible. I've tried the following methods:
      ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "", "", "", @SW_HIDE) Also I've tried:
      ShellExecute(@ComSpec, "/c start chrome.exe","","",@SW_HIDE) Lastly I tried:
      RunWait('"'&@ProgramFilesDir&'\Google\Chrome\Application\chrome.exe" --silent-launch',@ScriptDir)  
      But all of them launch my chrome browser without hiding it. Does anyone know a workaround for this or if AutoIT just can't Chrome? 
      Bonus points if you know how to make it launch chrome hidden and make it go to https://www.autoitscript.com
       
      Thank you,
      Brian
    • SteveJM
      By SteveJM
      I have a working program currently driven largely through menu selections. I would like to add a toolbar where most of the tollbar button actions are basically the same as menu items, but quicker to access. I have been wading around in toolbar examples, MSDN pages etc, it's clearly going to be a bit of a slog to get everything right, including tooltips etc. I thought I would start with something simple to prove the principle.
      Using bits from the help file examples I have a small program that successfully displays a toolbar. However, what seemed like the most elegant way to deal with the button commands does not seem to work. My understanding was that a toolbar button fires a WM_COMMAND message, with the command Id set by the second parameter in the call to
      _GUICtrlToolbar_AddButton ( $hWnd, $iID, $iImage)
      so I though it would be a good idea to set this Id to the same value as my menu item Id; then it would run the same task which is what I wanted. This did not work. I am using message loop mode and would like to stick with this because some of my scripts run hardware at the same time as the gui; it is easier if I don't have to worry about code being interrupted with the hardware in an unknown state . So I added a handler for WM_COMMAND, with some cribbed display code to try and see why. The toolbar button defintely fired a WM_COMMAND message and the Id looked the same, so no explanation there.
      I guess the issue is with GUIGetMsg() which may be constructed to ignore all but a limited number of control handles, i.e. those made with the GuiCtrlCreate... commands; this is speculation.
      I would dearly love to find a tidy way to get around this. Having some controls handled in the message loop and some in a WM_COMMAND handler, performing the same task, feels ugly. I would be very grateful for further insight from someone experienced with handling a toolbar. Perhaps I should be trying to fire the menu item. I have attached a code snippet to try and illustrate the issue.
       
       
       
      ToolbarTrial.au3
    • XinYoung
      By XinYoung
      Hello all,
      I've been working on 4 standalone scripts. They each have their own GUI and are now independent .exe's. But instead of having 4 separate icons on my computer, is it possible to put them all together into one .exe?
      What I want is one interface with tabs. Each script's GUI would be on their own respective tab. Is this possible?
      The different scripts don't need to communicate with one another. I just want them all in one .exe.
      I can't find this anywhere... Any help would be greatly appreciated. Thank you!