Jump to content
Sign in to follow this  
Queener

need help with msgbox yes no

Recommended Posts

Queener

if GUICtrlRead($inputmodel) = "" Then
        $ans = MsgBox(4, "Empty", "Model field is empty. Do you want to leave it blank?")
        if $ans = 6 Then
            if GUICtrlRead($InputLoc) = "" Then
                $ans = MsgBox(4, "Empty", "Location field is empty. Do you want to leave it blank?")
                if $ans = 6 Then
                        if GUICtrlRead($InputDept) = "" Then
                            $ans = MsgBox(4, "Empty", "Model field is empty. Do you want to leave it blank?")
                            if $ans = 6 Then
                                if GUICtrlRead($Inputrm) = "" Then
                                    $ans = MsgBox(4, "Empty", "Model field is empty. Do you want to leave it blank?")
                                    if $ans = 6 Then
                                        if GUICtrlRead($inputbuild) = "" Then
                                            $ans = MsgBox(4, "Empty", "Model field is empty. Do you want to leave it blank?")
                                            if $ans = 6 Then
                                                UpdateRecords()
                                            Else
                                                Return
                                            EndIf
                                            MsgBox(0, "Empty", $ans)
                                        Else
                                            Return
                                        EndIf
                                        MsgBox(0, "Empty", $ans)
                                    Else
                                        Return
                                    EndIf
                                    MsgBox(0, "Empty", $ans)
                                Else
                                    Return
                                EndIf
                                MsgBox(0, "Empty", $ans)
                            Else
                                Return
                            EndIf
                            MsgBox(0, "Empty", $ans)
                        Else
                            Return
                        EndIf
                        MsgBox(0, "Empty", $ans)
                Else
                    Return
                EndIf
                MsgBox(0, "Empty", $ans)
            Else
                Return
            EndIf
            MsgBox(0, "Empty", $ans)
        Else
            Return
        EndIf
        MsgBox(0, "Empty", $ans)
    Else
        Return
    EndIf
    MsgBox(0, "Empty", $ans)

 

What I'm trying to accomplish is I have a total of 5 input box. They (inboxes) could be empty, but I want to implement a message box to ask them to see if they have forgotten to fill in the blank anyways. I tried the switch and select case as well, but when I click yes, it just go ahead and run the function called UpdateRecords() without asking if the next fields are needed to fill in. It only ask the first question. Let me know if the way I'm doing is wrong and tell me the right way to accomplish this goal. Thanks


Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites
ViciousXUSMC

Since all your IF statements seem to be nested, each condition is dependent on the last.

So if only the last field was blank, I would never answer the first X number of MsgBoxes to even trigger the last.

Thats what it looks like to me at a glance. 

Your full code is missing so its hard to say what you should/could do, but just based on what make sense to me.  I would not have a message box for each and every field what I would do instead is when the "submit" or "ok" or what have you is pressed at the end it would notify you that you have blank fields and ask if you want to fix them or continue so you only get a single prompt rather than one for every field. 

Also without the full code its hard to tell but it looks like a GUI so I assume all input areas are available at one time?  But you said you were using Inputboxes and those would show up one at a time like a MsgBox.  If you are using the later perhaps a GUI is better suited?

Edited by ViciousXUSMC

Share this post


Link to post
Share on other sites
SadBunny

Your code only ever gets to the check for $inputLoc if the $inputModel was empty AND the user chose yes.

It only ever gets to the check for $InputDept if the $inputModel was empty AND the user answered yes AND the $inputLoc was empty AND the user answered yes.

... etc. It's nested incorrectly. Which is why it looks so weird.

You'll also notice that you have a lot of code repeating. That's always a sign that you are doing something wrong, or rather, that you're doing something that you shouldn't do. Try a function instead. I would write an example, but I'm not sure what you want to do with the result of the confirmation box. What should happen if the user presses no, and what should happen when the user presses yes? Try writing that for a single field, and then putting that in a function that you call for every field. (Will also make it A LOT easier to add other fields later.)

/edit: maybe you can check all fields periodically and set any empty field to a red background color or something? Will save a lot of trouble for the user clicking all those boxes.

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
Queener

EDIT:

Ok, I did a work around and it worked, but the codes are quite the messy.

 

    if GUICtrlRead($inputmodel) = "" Then
        $ans = MsgBox(4, "Empty", "Model field is empty. Do you want to skip?")
            if $ans = 6 then call("inboxck1")
            if $ans = 7 then Return
    Else
            UpdateRecords()
    EndIf
Func inboxck1()
    if GUICtrlRead($inputLoc) = "" Then
        $ans = MsgBox(4, "Empty", "Location field is empty. Do you want to skip?")
            if $ans = 6 then call("inboxck2")
            if $ans = 7 then Return
    Else
                inboxck2()
    EndIf
EndFunc
Func inboxck2()
    if GUICtrlRead($InputDept) = "" Then
        $ans = MsgBox(4, "Empty", "Department field is empty. Do you want to skip?")
            if $ans = 6 then call("inboxck3")
            if $ans = 7 then Return
                Else
                inboxck3()
    EndIf
EndFunc
etc...

 

Edited by asianqueen
resolved

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites
Joon

Something like this...

If _ConfirmInputBox($inputmodel,"Model") Then Return
If _ConfirmInputBox($InputLoc,"Location") Then Return
If _ConfirmInputBox($InputDept,"Dept") Then Return
If _ConfirmInputBox($Inputrm,"Model") Then Return
If _ConfirmInputBox($inputbuild,"Model") Then Return
UpdateRecords()


Func _ConfirmInputBox($handler, $fieldName)
    Local $ans
    If GUICtrlRead($handler) = "" Then
        $ans = MsgBox(4, "Empty", $fieldName & " field is empty. Do you want to leave it blank?")
        If $ans = 6 Then
            Return False
        Else
            Return True
        EndIf
    Else
        Return False
    EndIf
EndFunc   ;==>_ConfirmInputBox

 

Share this post


Link to post
Share on other sites
ajag

And think about using MsgBoxConstants for more readability.

Instead of

$ans = MsgBox(4, "Empty", $fieldName & " field is empty. Do you want to leave it blank?")
If $ans = 6 Then
    Return False
Else
    Return True
EndIf

Write this:

#include <MsgBoxConstants.au3>

$ans = MsgBox($MB_YESNO, "Empty", $fieldName & " field is empty. Do you want to leave it blank?")
If $ans = $IDYES Then
    Return False
Else
    Return True
EndIf

And you know even next year what your code means...

Ajag


Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

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
Sign in to follow this  

×