Valnurat

Several small issues

14 posts in this topic

#1 ·  Posted (edited)

I have put all my small issues into one thread hope that is fine.

I have GUI with many GUICtrlCreateInput and it's working ok.

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=x86\Create Consultant.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <AD.au3>
#include <Array.au3>

Main()

Func Main()
    _AD_Open()
    If @error Then Exit MsgBox(0x40010, "ERROR", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended)
    Local $sUsername = InputBox('OPTIONAL', 'Please enter the username.' & @CRLF & @CRLF & 'Exampel: '& @UserName)
    If @error = 1 Then Exit
    If $sUsername <> "" Then
        Local $sFQDN = _AD_SamAccountNameToFQDN($sUsername)
        if @error = 1 Then
            MsgBox(64, "Info", "User '" & $sUsername & "' does not exist")
            Exit
        EndIf
;   MsgBox(64, "Info", "User '" & $sFQDN & @CRLF & _AD_GetObjectAttribute($sFQDN, 'department'))
    EndIf
;   MsgBox(64, "Info", "User '" & $sFQDN & @CRLF & _AD_GetManager($sFQDN, 'department'))

    local $aObj = _AD_GetObjectsInOU("OU=Users,OU=so,OU=dk,OU=company,DC=AD,DC=company,DC=ORG","(&(objectclass=person)(sAMAccountName=" & $sUsername & "))",2,"department,physicalDeliveryOfficeName,company", "")
_ArrayDisplay($aObj)
    _ArrayDelete($aObj,0)
; Create a GUI with various controls.
    Local $hGUI = GUICreate("Create Consultant")
    GUICtrlCreateLabel("First name:", 10, 13)
    Local $idFirst = GUICtrlCreateInput("", 90, 10, 150, 20)
    GUICtrlCreateLabel("Shortname:", 245, 13)
    Local $idShort = GUICtrlCreateInput("", 300, 10, 90, 20)
    GUICtrlCreateLabel("Last name:", 10, 43)
    Local $idLast = GUICtrlCreateInput("", 90, 40, 300, 20)
    GUICtrlCreateLabel("Display name:", 10, 73)
    Local $idDisplay = GUICtrlCreateInput("", 90, 70, 300, 20)
    GUICtrlCreateLabel("Description:", 10, 103)
    Local $idRadio1 = GUICtrlCreateRadio("Consultant", 90, 100)
    Local $idRadio2 = GUICtrlCreateRadio("Group Account", 190, 100)
    GUICtrlCreateLabel("Email:", 10, 133)
    Local $idEmail = GUICtrlCreateInput("", 90, 130, 300, 20)
    GUICtrlCreateLabel("Department:", 10, 163)
    If $sUsername <> "" Then
        Local $idDepart = GUICtrlCreateInput($aObj[0][0], 90, 160, 300, 20)
    Else
        Local $idDepart = GUICtrlCreateInput("", 90, 160, 300, 20)
    EndIf
    GUICtrlCreateLabel("Office:", 10, 193)
    If $sUsername <> "" Then
        Local $idOffice = GUICtrlCreateInput($aObj[0][1], 90, 190, 80, 20)
    Else
        Local $idOffice = GUICtrlCreateInput("", 90, 190, 80, 20)
    EndIf
    Local $idCheckBox = GUICtrlCreateCheckbox("End date", 330, 190, 80, 20)
    Local $idDate = GUICtrlCreateDate("", 200, 190, 120, 20)
    GUICtrlSetState($idDate,$gui_disable)

    GUICtrlCreateLabel("Manager:", 10, 223)
    Local $idComboBox = GUICtrlCreateCombo("", 90, 220, 150, 100)
    GUICtrlCreateLabel("Misal code:", 245, 223)
    If $sUsername <> "" Then
        Local $idMisalCode = GUICtrlCreateInput($aObj[0][2], 310, 220, 80, 20)
    Else
        Local $idMisalCode = GUICtrlCreateInput("", 310, 220, 80, 20)
    EndIf
    GUICtrlCreateLabel("Ticket no.:", 10, 253)
    Local $idTicketNo = GUICtrlCreateInput("", 90, 250, 150, 20)
    GUICtrlCreateLabel("Cost no.:", 245, 253)
    Local $idCostNo = GUICtrlCreateInput("", 290, 250, 100, 20)
    GUICtrlCreateLabel("Ext. Company:", 10, 283)
    Local $idExtComp = GUICtrlCreateInput("", 90, 280, 300, 20)

    GUICtrlCreateGroup("Optional, if no Email", 10, 310, 380, 55)
    GUICtrlCreateLabel("Ext. Email:", 20, 333)
    Local $idExtEmail = GUICtrlCreateInput("", 90, 330, 290, 20)


    local $aObject = _AD_GetObjectsInOU("OU=Users,OU=so,OU=dk,OU=company,DC=AD,DC=company,DC=ORG","(&(objectclass=person)(StaffManager=TRUE))",2,"sAMAccountName,distinguishedName,displayname", "displayname")
;   _ArrayDisplay($aObject,"")
    If IsArray($aObject) Then
        Local $sFill = ""
        For $i = 1 To $aObject[0][0]
            $sFill &= $aObject[$i][2] & "|"
        Next
        $sFill = StringTrimRight($sFill,1)
        ; Add additional items to the combobox.
        GUICtrlSetData($idComboBox, $sFill, "")
    EndIf
    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)
    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)
    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idOK
                MsgBox($MB_SYSTEMMODAL, "", "test")
                Global $sFirst = GUICtrlRead($idFirst)
                Global $sShort = GUICtrlRead($idShort)
                Global $sLast = GUICtrlRead($idLast)
                Global $sDisp = GUICtrlRead($idDisplay)
                If GUICtrlRead($idRadio1) = $GUI_CHECKED Then
                    MsgBox($MB_SYSTEMMODAL, "test", "Consultants")
                EndIf

                Global $sEmail = GUICtrlRead($idEmail)
                Global $sDepart = GUICtrlRead($idDepart)
                Global $sOffice = GUICtrlRead($idOffice)
                Global $sManager = GUICtrlRead($idComboBox)
                If $sManager <> "" Then
                    MsgBox($MB_SYSTEMMODAL, "test", $sManager)
                EndIf
                Global $sMisalCode = GUICtrlRead($idMisalCode)
                Global $sTicketNo = GUICtrlRead($idTicketNo)
                Global $sCostNo = GUICtrlRead($idCostNo)
                Global $sExtCompe = GUICtrlRead($idExtComp)
                Global $sExtEmail = GUICtrlRead($idExtEmail)
                ExitLoop
            Case $idCheckBox
                If _IsChecked($idCheckbox) Then
                    GUICtrlSetState($idDate,$gui_enable)
                Else
                    GUICtrlSetState($idDate,$gui_disable)
                EndIf

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
    ; Create a new user
#cs Global $iValue = _AD_CreateUser($sOU, $sShort, "Doe John")
    If $iValue = 1 Then
        MsgBox(64, "Active Directory Functions - Example 1", "User '" & $sUser & "' in OU '" & $sOU & "' successfully created")
    ElseIf @error = 1 Then
        MsgBox(64, "Active Directory Functions - Example 1", "User '" & $sUser & "' already exists")
    ElseIf @error = 2 Then
        MsgBox(64, "Active Directory Functions - Example 1", "OU '" & $sOU & "' does not exist")
    ElseIf @error = 3 Then
        MsgBox(64, "Active Directory Functions - Example 1", "Value for CN (e.g. Lastname Firstname) is missing")
    ElseIf @error = 4 Then
        MsgBox(64, "Active Directory Functions - Example 1", "Value for $sAD_User is missing")
    Else
        MsgBox(64, "Active Directory Functions - Example 1", "Return code '" & @error & "' from Active Directory")
#ce EndIf
    _AD_Close()
EndFunc

Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

Now I have to read all GUICtrlCreateInput and I want to be sure that all GUICtrlCreateInput is filled. Do I have to this for all of them:

Global $sManager = GUICtrlRead($idComboBox)
                If $sManager <> "" Then
                    MsgBox($MB_SYSTEMMODAL, "test", $sManager)
                    Global $bManager = True
                EndIf

Or is there a nice way of controlling that they all are filled out?

And how can I be in the loop until all fields are filled out?

 

I also have 2 radiobuttons. 1 with text "Consultants" and 1 with "Group account".

How do I get the text from the 1 that's active? I tried this and it's working, but is there another way?

If GUICtrlRead($idRadio1) = $GUI_CHECKED Then
                    MsgBox($MB_SYSTEMMODAL, "test", "Consultants")
                EndIf

 

Edited by Valnurat

Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites



Anyone who could help?


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
21 hours ago, Valnurat said:

Or is there a nice way of controlling that they all are filled out?

first, declare your variables at the top of your script, unconditionally. yes, i know it works for you; it does not work for everyone else trying to troubleshoot your issues, and it is by nature prone to more issues than you would care to tackle.

second, when you post a reproducer, do try to strip it down. why are you sending people, who are here to help you, on a quest to download the AD UDF? and worse, no-one can test your script without an Active Directory infrastructure! quite inconsiderate i dare say. yes, i know i can modify your script to eliminate those; but that's not my job, is it?

now, please revise your reproducer. then, you can create your inputs sequentially and loop their id for testing empty fields. i'd be happy to elaborate when a working reproducer, with variables properly declared, is available.

 

Share this post


Link to post
Share on other sites

1st, do you mean like this:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=x86\Create Consultant.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <AD.au3>
#include <Array.au3>

Global $sUsername, $sFQDN
Global $aObj
Global $hGUI
Global $idFirst, $idShort, $idLast, $idDisplay, $idRadio1, $idRadio2, $idEmail

Main()

ect...

if not, then I'm not sure what you mean that I need to declare my variables at the top.

If it is, then why is the exampels, that comes with AutoIT, not like this. I guess if the exampels is like what I started with, then it should be ok, but I was wrong.

2nd, I'm not asking people here to download AD.au3 at all. I'm asking if there is a nice way to control that all the fields are used. That, I think you don't need AD.au3 to accomplished, cause the AD.au3 and GUICtrlCreateInput is totally diffirent, right. And am I asking you to do the job for me? I don't think so, I'm asking for a nice way. Maybe there was a special command in AutoIT the could do it, that I was not aware of or someone could just give me an exampel on how to do it.

3rd, the reason for me to show my code, is

   3.1 - because someone might want to use it

   3.2 - that I have seen in this forum that, when people want to have help and didn't showed the code they was scold, like you do now, so tell me Mr. Orbs, what should n00bs - like me - do to fitt your needs?

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

42 minutes ago, Valnurat said:

that I have seen in this forum that, when people want to have help and didn't showed the code they was scold

there is a reason why people want to see your code. the reason is simple: it is easier to suggest and test solutions.

if you do not provide code, or provide a code that is not runnable, then the entire discussion becomes theoretical. not that i mind having a theoretical discussion, but this forum is about help and support, and if one wishes to get help and support, then usually one has a more concrete situation to resolve.

for example, if i were to ask your question about checking for existence of content in multiple input fields, i would post this reproducer - based on the GUICreate example, adding a few labels and input controls:

#include <GUIConstantsEx.au3>

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example")

    GUICtrlCreateLabel('input 1:', 20, 50)
    Local $idInput1 = GUICtrlCreateInput('', 120, 50, 100, 20)
    GUICtrlCreateLabel('input 2:', 20, 100)
    Local $idInput2 = GUICtrlCreateInput('', 120, 100, 100, 20)
    GUICtrlCreateLabel('input 3:', 20, 150)
    Local $idInput3 = GUICtrlCreateInput('', 120, 150, 100, 20)

    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)

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

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                ExitLoop

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

it is runnable, and so is my suggested solution:

1 hour ago, orbs said:

create your inputs sequentially and loop their id

which results in this code - note the change of order of creating the controls (all labels first, all inputs sequentially together), and what happens when you click the OK button:

#include <GUIConstantsEx.au3>

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example")

    GUICtrlCreateLabel('input 1:', 20, 50)
    GUICtrlCreateLabel('input 2:', 20, 100)
    GUICtrlCreateLabel('input 3:', 20, 150)
    Local $idInput1 = GUICtrlCreateInput('', 120, 50, 100, 20)
    Local $idInput2 = GUICtrlCreateInput('', 120, 100, 100, 20)
    Local $idInput3 = GUICtrlCreateInput('', 120, 150, 100, 20)

    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)

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

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $idOK
                ConsoleWrite('--- checking for empty input fields ---' & @CRLF)
                For $id = $idInput1 To $idInput3
                    If GUICtrlRead($id) = '' Then ConsoleWrite('at least one input is empty' & @CRLF)
                Next

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

now, about relying on help fie examples: do that with caution. it declares local variables inside functions, which is OK; but it declares variables while creating the controls, which is also OK but some people would find it to be trouble-inviting. this is because there is a short distance between that, and between what you are doing: declaring global variables inside a function, and declaring them conditionally. both cases can not end well. with the first slightest oversight your entire code goes kaboom, and these practices makes your life harder in debugging your own code.

23 hours ago, Valnurat said:

I also have 2 radiobuttons. 1 with text "Consultants" and 1 with "Group account".

How do I get the text from the 1 that's active?

for that, you can use GuiCtrlRead in "advanced" mode - see the help file.

42 minutes ago, Valnurat said:

3rd, the reason for me to show my code, is

   3.1 - because someone might want to use it

this is why we have the Example Scripts forum, and everyone is happy of any contribution. but before you post code for public use, make sure to describe its purpose, use case, dependencies, etc. don't send your users on a quest to discover all that.

Edited by orbs

Share this post


Link to post
Share on other sites

I have done this and I hope it's ok that I post it.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=x86\Create Consultant.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>

Global $hGUI, $sUsername, $aUserNfo
Global $idInput1, $idInput2, $idInput3, $idInput4, $idInput5, $idInput6, $idInput7, $idInput8, $idInput9, $idInput10, $idInput11, $idInput12, $idInput13, $idRadio1, $idRadio2, $idCheckBox ,$idDate, $idOKay

FormCreate()
Main()

Func Main()
    Local $bManager, $bGoodToGo
    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idOKay
                For $id = $idInput1 to $idInput13
                    if GUICtrlRead($id) = '' Then
                        MsgBox(64, "info", "At least one input is empty.")
                        ExitLoop
                    EndIf
                Next
                $sFirst = GUICtrlRead($idInput1)
                $sShort = GUICtrlRead($idInput2)
                $sLast = GUICtrlRead($idInput3)
                $sDisp = GUICtrlRead($idInput4)
            Case $idCheckBox
                If _IsChecked($idCheckbox) Then
                    GUICtrlSetState($idDate,$gui_enable)
                Else
                    GUICtrlSetState($idDate,$gui_disable)
                EndIf
        EndSwitch
    WEnd
    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc

Func FormCreate()
    Local $aObjManager
    $sUsername = ''
; Create a GUI with various controls.
    $hGUI = GUICreate("Create Consultant")
    GUICtrlCreateLabel("First name:", 10, 13)
    GUICtrlCreateLabel("Shortname:", 245, 13)
    GUICtrlCreateLabel("Last name:", 10, 43)
    GUICtrlCreateLabel("Display name:", 10, 73)
    GUICtrlCreateLabel("Description:", 10, 103)
    GUICtrlCreateLabel("Email:", 10, 133)
    GUICtrlCreateLabel("Department:", 10, 163)
    GUICtrlCreateLabel("Office:", 10, 193)
    GUICtrlCreateLabel("Manager:", 10, 223)
    GUICtrlCreateLabel("Misal code:", 245, 223)
    GUICtrlCreateLabel("Ticket no.:", 10, 253)
    GUICtrlCreateLabel("Cost no.:", 245, 253)
    GUICtrlCreateLabel("Ext. Company:", 10, 283)
    GUICtrlCreateLabel("Ext. Email:", 20, 333)
    $idInput1 = GUICtrlCreateInput("First", 90, 10, 150, 20)
    $idInput2 = GUICtrlCreateInput("Shortname", 300, 10, 90, 20)
    $idInput3 = GUICtrlCreateInput("Last", 90, 40, 300, 20)
    $idInput4 = GUICtrlCreateInput("Display", 90, 70, 300, 20)
    $idInput5 = GUICtrlCreateInput("Email", 90, 130, 300, 20)
    If $sUsername <> "" Then
        $idInput6 = GUICtrlCreateInput($aUserNfo[0][0], 90, 160, 300, 20)
    Else
        $idInput6 = GUICtrlCreateInput("Depart", 90, 160, 300, 20)
    EndIf
    If $sUsername <> "" Then
        $idInput7 = GUICtrlCreateInput($aUserNfo[0][1], 90, 190, 80, 20)
    Else
        $idInput7 = GUICtrlCreateInput("Office", 90, 190, 80, 20)
    EndIf
    $idInput8 = GUICtrlCreateInput("", 90, 220, 150, 20)
;   $idInput8 = GUICtrlCreateCombo("", 90, 220, 150, 100)
    If $sUsername <> "" Then
        $idInput9 = GUICtrlCreateInput($aUserNfo[0][2], 310, 220, 80, 20)
    Else
        $idInput9 = GUICtrlCreateInput("Misal", 310, 220, 80, 20)
    EndIf
    $idInput10 = GUICtrlCreateInput("Ticket", 90, 250, 150, 20)
    $idInput11 = GUICtrlCreateInput("Cost", 290, 250, 100, 20)
    $idInput12 = GUICtrlCreateInput("ExtComp", 90, 280, 300, 20)
    $idInput13 = GUICtrlCreateInput("ExtEmail", 90, 330, 290, 20)

    GUICtrlCreateGroup("Optional, if no Email", 10, 310, 380, 55)
    $idRadio1 = GUICtrlCreateRadio("Consultant", 90, 100)
    $idRadio2 = GUICtrlCreateRadio("Group Account", 190, 100)
    $idCheckBox = GUICtrlCreateCheckbox("End date", 330, 190, 80, 20)
    $idDate = GUICtrlCreateDate("", 200, 190, 120, 20)
    GUICtrlSetState($idDate,$gui_disable)
    $idOKay = GUICtrlCreateButton("OK", 310, 370, 85, 25)
    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)
EndFunc


Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

I do get the Info if some of the fields are not filled out, but how can I read the fields when all of them is filled out?

Right now the fields will be read no matter what.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
3 hours ago, Valnurat said:

how can I read the fields when all of them is filled out?

first you must define what exactly is "filled out". if you mean "all fields contain some text" then you will get the "all filled" signal immediately when the user start typing the first character in the last field. i'm certain this is not what you want. what's wrong with checking for empty fields when the user click OK?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Nothing is wrong by checking for empty fields when the user click ok.

But the in my code it will still read the fields even if they are empty. I want, after all fields contains some text, to read them and then close GUI and then I will create the user in our system.

At this point my application is looping in the While .. WEnd, but I need a ExitLoop to exit that, but if I do that, it will read empty fields and exitloop and delete my GUI.

Func Main()
    Local $bManager, $bGoodToGo
    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idOKay
                For $id = $idInput1 to $idInput13
                    if GUICtrlRead($id) = '' Then
                        MsgBox(64, "info", "At least one input is empty.")
                        ExitLoop
                    EndIf
                Next
                $sFirst = GUICtrlRead($idInput1)
                $sShort = GUICtrlRead($idInput2)
                $sLast = GUICtrlRead($idInput3)
                $sDisp = GUICtrlRead($idInput4)
                ExitLoop
            Case $idCheckBox
                If _IsChecked($idCheckbox) Then
                    GUICtrlSetState($idDate,$gui_enable)
                Else
                    GUICtrlSetState($idDate,$gui_disable)
                EndIf
        EndSwitch
    WEnd
    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc

Maybe my explaination for my goal is not so clear, sorry about that.

Edited by Valnurat

Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

replace this:

MsgBox(64, "info", "At least one input is empty.")
                        ExitLoop

with this:

MsgBox(64, "info", "At least one input is empty.", 0, $hGUI)
                        ContinueLoop 2

so instead of exiting the secondary loop (the For...Next loop) and proceeding on reading the fields and exiting the main loop, you just continue the main loop as if nothing happened. look at the help for ContinueLoop.

also, the for MsgBox call - add the last parameter to assign the MsgBox to your GUI, so the main GUI cannot become operational until the user acknowledges the MsgBox. because currently, if the user simply ignores the MsgBox and just clicks on the GUI, the GUI gets focus but the MsgBox is left behind, blocking the GUI actions. ugly.

EDIT: ignore snippets indentation. bloody forum software.

Edited by orbs

Share this post


Link to post
Share on other sites
On 8/26/2016 at 10:08 AM, orbs said:

... declare your variables at the top of your script, unconditionally. yes, i know it works for you; it does not work for everyone else trying to troubleshoot your issues, and it is by nature prone to more issues than you would care to tackle ...

well, it didn't take too long for someone to show up with this issue - caused directly by incorrectly declaring a variable.

Share this post


Link to post
Share on other sites
5 hours ago, orbs said:

replace this:

MsgBox(64, "info", "At least one input is empty.")
                        ExitLoop

with this:

MsgBox(64, "info", "At least one input is empty.", 0, $hGUI)
                        ContinueLoop 2

so instead of exiting the secondary loop (the For...Next loop) and proceeding on reading the fields and exiting the main loop, you just continue the main loop as if nothing happened. look at the help for ContinueLoop.

also, the for MsgBox call - add the last parameter to assign the MsgBox to your GUI, so the main GUI cannot become operational until the user acknowledges the MsgBox. because currently, if the user simply ignores the MsgBox and just clicks on the GUI, the GUI gets focus but the MsgBox is left behind, blocking the GUI actions. ugly.

EDIT: ignore snippets indentation. bloody forum software.

Thank you very much.

It was an instructive experience for the me.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

When I meantioned that I had 2 radiobuttons, you said for that, I can use GuiCtrlRead in "advanced" mode - see the help file.

Do I have to do this:

If GUICtrlRead($idRadio1) = $GUI_CHECKED Then
    $sres = GUICtrlRead($idRadio1, $GUI_READ_EXTENDED)
EndIf
If GUICtrlRead($idRadio2) = $GUI_CHECKED Then
    $sres = GUICtrlRead($idRadio2, $GUI_READ_EXTENDED)
EndIf

It seems to work, but I'm not sure it is correct, because then I feel I just could have done this:

If GUICtrlRead($idRadio1) = $GUI_CHECKED Then
    $sres = "Consultants"
EndIf
If GUICtrlRead($idRadio2) = $GUI_CHECKED Then
    $sres = "Group Account"
EndIf

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

when you have only two radio options, then you can just check them directly, with 6 lines of code.

but how many lines of such code would it take to check five or seven radio options?

15 to 21 lines of code.

but if you apply the same loop check that we did for the input fields, you would have only 3 lines of code for no matter how many radio options you have:

For $id = $idRadio1 To $idRadio7
    If GUICtrlRead($id) = $GUI_CHECKED Then $sres = GUICtrlRead($id, $GUI_READ_EXTENDED)
Next
; of the 7 radio options, $sres now holds the text of the selected one

 

Edited by orbs

Share this post


Link to post
Share on other sites

Yes, you are right.

I was not thinking clear.

Thank you.


Yours sincerely

Kenneth.

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

    • Viki
      By Viki
      This is my first time here so please dont bombard me that what a silly question I am asking!!
      I have 500 rows (A1:A500) in a spreadsheet and I just want to copy one by one row and then paste into another application and then press enter, loop should repeat this until finishes all 500 rows.
      I have looked at clipget(), clip(put() but dont know how to select next row in next turn. I also looked at Array to store but again no luck. Can some guide me please..
    • DineshPawar
      By DineshPawar
      0down votefavorite   In my current project, Excel macro open AutoIt script using a function Call Shell("location of autoit script").
      For proper functioning of AutoIt script it's need to be close parent Excel workbook, so this closing Excel action is written in AutoIt script itself.
      But as soon as AutoIt script close parent Excel workbook then script get pause and it do nothing.
      How open the AutoIt script from Excel workbook and after that parent Workbook get close?
    • AndroidZero
      By AndroidZero
      I want to animate transparent GIFs on my gui.
      I searched, read and tested a lot UDFs
      At the end none fits to me
      I wrote my own animated function, but its flickering sometimes just for a miliseconds but still doesnt looks good.

       
      Below is my code for Testing and also the GIF images you need for it.
      GUIChangeImage() is the Animation Function.
      CODE:
      ;************FOR GATHER HTML SOURCE CODE********************** #include <IE.au3> #include <InetConstants.au3> ;************FOR GUI*********** #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPIFiles.au3> ;**********FOR BUTTON ********** #include <ButtonConstants.au3> #include <StaticConstants.au3> ;**********FOR STRINGS ********** #include <StringConstants.au3> #include <String.au3> ;**********FOR COMBOBOX ********** #include <StringConstants.au3> #include <EditConstants.au3> #include <GuiEdit.au3> #include <GuiComboBox.au3> ;**********FOR FONTS ********** #include <FontConstants.au3> ;**********FOR GIF ANIMATION ********** #include <GIFAnimation.au3> ;**********FOR PROCESS ********** #include <Process.au3> #include <SendMessage.au3> #include <GDIPlus.au3> #include <WinAPIDiag.au3> Opt("GUIOnEventMode",1) Global Const $SC_DRAGMOVE = 0xF012 Global $hGUIAccountCreator Global $graphics_path = @ScriptDir & "\graphics" Global $fontSize_TextBody = 8.5, $fontName_TextBody = "", $fontWeight_TextBody = $FW_BOLD, $fontColor_TextBody = 0x5A2800 GUI_open_AccountCreator() Func GUI_open_AccountCreator() Global $hGUIAccountCreator = GUICreate("Tibia Account Creator - SubZero", 350, 400, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_Close_AccountCreator") GUICtrlCreatePic($graphics_path & "\WindowAccountCreator.gif", 0, 0, 350, 400) GUICtrlSetState(-1, $GUI_DISABLE) ;********* GUI CONTROLS (LABELS,INPUTS,COMBOBOXES) ********************************************************************** GUICtrlCreateLabel(" Create New Account", 25,47,103,14,$SS_CENTERIMAGE) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1,8,$fontWeight_TextBody,0,$fontName_TextBody,1) GUICtrlSetColor(-1,0xFFFFFF) GUICtrlCreateLabel("Account Name:",30,75,75,14) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1,8,$fontWeight_TextBody,0,$fontName_TextBody,1) GUICtrlSetColor(-1,0x5A2800) Global $inptBox_Acc = GUICtrlCreateInput("",130,75,150,20) GUICtrlCreateLabel("Email Adress:",30,100,70,14) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1,8,$fontWeight_TextBody,0,$fontName_TextBody,1) GUICtrlSetColor(-1,0x5A2800) Global $inptBox_Email = GUICtrlCreateInput("",130,100,150,20) GUICtrlCreateLabel("Password:",30,125,55,14) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1,8,$fontWeight_TextBody,0,$fontName_TextBody,1) GUICtrlSetColor(-1,0x5A2800) Global $inptBox_Passwd = GUICtrlCreateInput("",130,125,150,20,$ES_PASSWORD) GUICtrlSetData($inptBox_Passwd, "") GUICtrlCreateLabel("Character Name:",30,170,83,14) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1,8,$fontWeight_TextBody,0,$fontName_TextBody,1) GUICtrlSetColor(-1,0x5A2800) Global $inptBox_CharName = GUICtrlCreateInput("",130,170,150,20) GUICtrlCreateLabel("Sex:",30,195,23,14) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1,$fontSize_TextBody,$fontWeight_TextBody,0,$fontName_TextBody,1) GUICtrlSetFont(-1,8,$fontWeight_TextBody,0,$fontName_TextBody,1) GUICtrlSetColor(-1,$fontColor_TextBody) Global $comboBox_sex = GUICtrlCreateCombo("",130,195,150,20,$CBS_DROPDOWNLIST) ;LoadSexIntoComboBox() GUICtrlCreateLabel("World Location:",30,240,77) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1,$fontSize_TextBody,$fontWeight_TextBody,0,$fontName_TextBody,1) GUICtrlSetFont(-1,8,$fontWeight_TextBody,0,$fontName_TextBody,1) GUICtrlSetColor(-1,$fontColor_TextBody) Global $comboBox_world = GUICtrlCreateCombo("",130,240,150,20,BitOr($CBS_DROPDOWNLIST, $WS_VSCROLL)) ;LoadWorldsIntoComboBox() Global $label_status = GUICtrlCreateLabel("",20,360,200,30) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ;********* GUI CONTROLS (LABELS,INPUTS,COMBOBOXES) ********************************************************************** ;********* CONTROL PICS ********************************************************************** Global $btn_randAccName = GUICtrlCreatePic($graphics_path & "\Die_Static.gif", 280, 75, 26, 26) GUICtrlSetTip($btn_randAccName, "Generate a random account name") GUICtrlSetCursor($btn_randAccName,0) ;GUICtrlSetOnEvent($btn_randAccName,"GenerateRandomAccName") GUICtrlSetOnEvent($btn_randAccName,"GUIChangeImage") Global $btn_x = GUICtrlCreatePic("", 315, 5, 40, 36) GUICtrlSetTip($btn_x, "Close") GUICtrlSetCursor($btn_x,0) GUICtrlSetOnEvent($btn_x,"GUI_Close_AccountCreator") Global $btn_donate = GUICtrlCreatePic("", 112, 313, 126, 47) GUICtrlSetTip($btn_donate, "Donate") GUICtrlSetCursor($btn_donate,0) ;GUICtrlSetOnEvent($btn_donate,"Donate") ;********* CONTROL PICS ********************************************************************** ;********* GDI+ DRAW ********************************************************************** _GDIPlus_Startup() Local $hImg = _GDIPlus_ImageLoadFromFile($graphics_path & "\X_Tic-Tac-Toe_Token.gif") Local $hHBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImg) _WinAPI_DeleteObject(GUICtrlSendMsg($btn_x, 0x0172, $IMAGE_BITMAP, $hHBMP)) _GDIPlus_ImageDispose($hImg) Local $hImg = _GDIPlus_ImageLoadFromFile($graphics_path & "\Die_Static.gif") Local $hHBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImg) _WinAPI_DeleteObject(GUICtrlSendMsg($btn_randAccName, 0x0172, $IMAGE_BITMAP, $hHBMP)) _GDIPlus_ImageDispose($hImg) Local $hImg = _GDIPlus_ImageLoadFromFile($graphics_path & "\btn_donateCC_LG.gif") Local $hHBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImg) _WinAPI_DeleteObject(GUICtrlSendMsg($btn_donate, 0x0172, $IMAGE_BITMAP, $hHBMP)) _GDIPlus_ImageDispose($hImg) _GDIPlus_Shutdown() ;********* GDI+ DRAW ********************************************************************** _WinAPI_SetLayeredWindowAttributes($hGUIAccountCreator, 0x26f50b) GUISetIcon(@ScriptDir & "\TibiaInfo.ico") GUISetState(@SW_SHOW, $hGUIAccountCreator) WinSetOnTop($hGUIAccountCreator,"",1) GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") EndFunc Func GUIChangeImage() _GDIPlus_Startup() GUICtrlDelete($btn_randAccName) Local $btn_randAccName = GUICtrlCreatePic("", 280, 75, 26, 26) Local $hImg = _GDIPlus_ImageLoadFromFile($graphics_path & "\Die_Frame2.gif") Local $hHBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImg) _WinAPI_DeleteObject(GUICtrlSendMsg($btn_randAccName, 0x0172, $IMAGE_BITMAP, $hHBMP)) _GDIPlus_ImageDispose($hImg) _WinAPI_SetLayeredWindowAttributes($hGUIAccountCreator, 0x26f50b) Sleep(100) GUICtrlDelete($btn_randAccName) Local $btn_randAccName = GUICtrlCreatePic("", 280, 75, 26, 26) Local $hImg = _GDIPlus_ImageLoadFromFile($graphics_path & "\Die_Frame3.gif") Local $hHBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImg) _WinAPI_DeleteObject(GUICtrlSendMsg($btn_randAccName, 0x0172, $IMAGE_BITMAP, $hHBMP)) _GDIPlus_ImageDispose($hImg) _WinAPI_SetLayeredWindowAttributes($hGUIAccountCreator, 0x26f50b) Sleep(100) GUICtrlDelete($btn_randAccName) Local $btn_randAccName = GUICtrlCreatePic("", 280, 75, 26, 26) Local $hImg = _GDIPlus_ImageLoadFromFile($graphics_path & "\Die_Frame4.gif") Local $hHBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImg) _WinAPI_DeleteObject(GUICtrlSendMsg($btn_randAccName, 0x0172, $IMAGE_BITMAP, $hHBMP)) _GDIPlus_ImageDispose($hImg) _WinAPI_SetLayeredWindowAttributes($hGUIAccountCreator, 0x26f50b) Sleep(100) GUICtrlDelete($btn_randAccName) Local $btn_randAccName = GUICtrlCreatePic("", 280, 75, 26, 26) Local $hImg = _GDIPlus_ImageLoadFromFile($graphics_path & "\Die_Frame5.gif") Local $hHBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImg) _WinAPI_DeleteObject(GUICtrlSendMsg($btn_randAccName, 0x0172, $IMAGE_BITMAP, $hHBMP)) _GDIPlus_ImageDispose($hImg) _WinAPI_SetLayeredWindowAttributes($hGUIAccountCreator, 0x26f50b) Sleep(100) GUICtrlDelete($btn_randAccName) Local $btn_randAccName = GUICtrlCreatePic("", 280, 75, 26, 26) GUICtrlSetCursor($btn_randAccName,0) GUICtrlSetOnEvent($btn_randAccName,"GUIChangeImage") Local $hImg = _GDIPlus_ImageLoadFromFile($graphics_path & "\Die_Static.gif") Local $hHBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImg) _WinAPI_DeleteObject(GUICtrlSendMsg($btn_randAccName, 0x0172, $IMAGE_BITMAP, $hHBMP)) _GDIPlus_ImageDispose($hImg) _WinAPI_SetLayeredWindowAttributes($hGUIAccountCreator, 0x26f50b) _GDIPlus_Shutdown() EndFunc Func GUI_Close_AccountCreator() Exit EndFunc Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) _SendMessage($hGUIAccountCreator, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndFunc While 1 Sleep(10) WEnd  
      IMAGES:
       
       








    • ur
      By ur
      I am maintaining all the reusable code in a separate file as library.au3.
      In that file I have referenced some dependent files using fileinstall, so that they will be extracted when necessary.
       
      Problem is, if I use a function in the library.au3 in another script which doesn't require this dependent file, as I am including the whole file using include tag, it is embedding that file also.
      Is there any way to exclude that.
       
    • GAM
      By GAM
      Am trying to execute perl script from autoit script but its not running. Th command that I have given is...
      $rootDir = automation Run("cmd.exe /" & "C:\" & $rootDir & "\updatesource.pl") Can someone help please!