Quesney

Inputbox and Numbers

11 posts in this topic

#1 ·  Posted

Hello all, 

Currently I have discovered that within the XSkinInPutBox when cancel is pressed it supplies the answer 2 and if Ok is pressed it supplies the answer of 1. My question is this "Is there a different option other then InputBox to use for numbers or a method for cancel to return a different value, like true or false?"

If the question has been asked and answered I apologize, I did a search and found no answers.


“Courage is being scared to death, but saddling up anyway”John Wayne

Share this post


Link to post
Share on other sites



#2 ·  Posted

According to the help file for InputBox when you press the cancel button you get:

Quote

Return Value

Success:  the string that was entered.
Failure: "" (empty string) and sets the @error flag to non-zero.
@error: 1 = The Cancel button was pushed.

So when the cancel button is pressed you get @error = 1 and a return value of "".


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

I am using the Xskininputbutton, this maybe my issue, I will attempt this with the normal inputbox to see what I get. Thank you for your response.


“Courage is being scared to death, but saddling up anyway”John Wayne

Share this post


Link to post
Share on other sites

#4 ·  Posted

@water Thank you for pointing this out to me. When I use the XSkinInputBox I get the issue, however if I use the normal InputBox and the If $MyAnswer = "" Then ExitLoop it cancels as it should. I was hoping to use the Xskins, but this helps me. Thank you again


“Courage is being scared to death, but saddling up anyway”John Wayne

Share this post


Link to post
Share on other sites

#5 ·  Posted

Just out of curiosity, is there a reason you cannot use the result returned by the XSking Inputbox? What is prompting you to look for another way?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#6 ·  Posted

Within my code I have an inputbox that asks for a length of material, then a msgbox pops up with the answer (there is a formula in the code that takes the input number and uses it to find a required size. So if someone hits cancel it sends a 2 to the formula and I get an answer when I really did not want one.

$MyAnswer = InputBox("Length", What is the ending length of the part?,"","",500) ; Places the input box
                If $sAnswer = "" then ExitLoop
                XSkinMsgBoxOK("Required Length", "Your part needs to be atleast " & Round($MyAnswer + 0.125 + 0.08)), 4) & """") ; Display the result.

 


“Courage is being scared to death, but saddling up anyway”John Wayne

Share this post


Link to post
Share on other sites

#7 ·  Posted

You code is a bit confusing, as it looks as though your skinned inputbox is $MyAnswer but you're checking for the value of $sAnswer and then returning $MyAnswer in your MsgBox. If hitting cancel on the InputBox returns 2, you should be able to do something like this:

$MyAnswer = InputBox("Length", What is the ending length of the part?,"","",500) ; Places the input box
    If $MyAnswer = 2 OR $MyAnswer = "" Then
        ExitLoop
    Else
        XSkinMsgBoxOK("Required Length", "Your part needs to be atleast " & Round($MyAnswer + 0.125 + 0.08)), 4) & """") ; Display the result.
    EndIf

If this is not the case, please share the entirety of your code so we can get a better idea of what you are trying to do.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#8 ·  Posted

Here is the code in its entirety, I am sure it could be scripted better, but is my first attempt. I cannot use the If $MyAnswer = 2  Or $MyAnswer = "" Then for the cancel because the answer from the user may be 2 (which is the response from cancel), hence my issue.

#include <XSkin.au3>

$Skin_Folder = @ScriptDir & "\Skins\BlackJack" ; Folder of skin
$Icon_Folder = @ScriptDir & "\Skins\Default" ; Folder of Icons
$XSkinGui = XSkinGUICreate("Allocated Length Calculator", 400, 225, $Skin_Folder) ; Creates an XSkin dialog box
$XIcon = XSkinIcon($XSkinGui, 2) ; Adds the window close/minimize buttons
$MyButton= XSkinButton("Formula Criteria", 275, 150, 100, 35, "FormulaCriteria") ; Adds the Formula Criteria button
$sFinish = "Enter finished part length" & @CRLF & @CRLF & "NOTE: Part should have a diameter "

Local $idRadio1 = GUICtrlCreateRadio("Less than 4in diameter and less than 2in long", 20, 45, 250, 20)
Local $idRadio2 = GUICtrlCreateRadio("Less than 4in diameter and greater than 2in long", 20, 65, 250, 20)
Local $idRadio3 = GUICtrlCreateRadio("Between 4in to 12in diameter and less than 2in long", 20, 85, 275, 20)
Local $idRadio4 = GUICtrlCreateRadio("Between 4in to 12in diameter and greater 2in long", 20, 105, 250, 20)
Local $idRadio5 = GUICtrlCreateRadio("Greater than 12in diameter", 20, 125, 250, 20)

GUISetState(@SW_SHOW)

RadioRequest()

Func RadioRequest()

    While 1
        MouseOver() ; Makes the buttons flash on mouseover
        Sleep(10)

        $idMsg = GUIGetMsg()

        Select
            Case $idMsg = $XIcon[1]
                Exit
            Case $idMsg = $XIcon[2]
                GUISetState(@SW_MINIMIZE)
            Case $idMsg = $idRadio1
                $MyAnswer =XSkinInputBox("Finished Length", $sFinish & "less than 4"" and finished length less than 2""") ; Places the input box
                If $MyAnswer = "" then ExitLoop
                XSkinMsgBoxOK("Allocated Length", "For a part with a diameter less than 4"" and a finished length of " & $MyAnswer & _
                        """ the allocated length is " & Round(144 / Floor(142 / ($MyAnswer + 0.125 + 0.08)), 4) & """") ; Display the result.
                Exit
            Case $idMsg = $idRadio2
                $MyAnswer = XSkinXSkinInputBox("Finished Length", $sFinish & "less than 4"" and finished length greater than 2""") ; Places the input box
                If $MyAnswer = "" then ExitLoop
                XSkinMsgBoxOK("Allocated Length", "For a part with a diameter less than 4"" and a finished length of " & $MyAnswer & _
                        """ the allocated length is " & Round(144 / Floor(144 / ($MyAnswer + 0.125 + 0.08)), 4) & """") ; Display the result.
                Exit
            Case $idMsg = $idRadio3
                $MyAnswer = XSkinXSkinInputBox("Finished Length", $sFinish & "between 4"" and 12"" and finished length less than 2""") ; Places the input box
                If $MyAnswer = "" then ExitLoop
                XSkinMsgBoxOK("Allocated Length", "For a part with a diameter between 4"" and 12"" and a finished length of " & $MyAnswer & _
                        """ the allocated length is " & Round(144 / Floor(142 / ($MyAnswer + 0.25 + 0.08)), 4) & """") ; Display the result.
                Exit
            Case $idMsg = $idRadio4
                $MyAnswer = XSkinInputBox("Finished Length", $sFinish & "between 4"" and 12"" and finished length greater than 2""") ; Places the input box
                If $MyAnswer = "" then ExitLoop
                XSkinMsgBoxOK("Allocated Length", "For a part with a diameter between 4"" and 12"" and a finished length of " & $MyAnswer & _
                        """ the allocated length is " & Round(144 / Floor(144 / ($MyAnswer + 0.25 + 0.08)), 4) & """") ; Display the result.
                Exit
            Case $idMsg = $idRadio5
                $MyAnswer = XSkinInputBox("Finished Length", $sFinish & "greater than 12""") ; Places the input box
                If $MyAnswer = "" then ExitLoop
                XSkinMsgBoxOK("Allocated Length", "For a part with a diameter greater then 12"" and a finished length of " & $MyAnswer & _
                        """ the allocated length is " & Round(144 / Floor(144 / ($MyAnswer + 0.375 + 0.08)), 4) & """") ; Display the result.
                Exit
        EndSelect
    WEnd
EndFunc   ;==>RadioRequest

Func FormulaCriteria()
    XSkinMsgBoxOK("Formula Criteria", "Example: 6.5"" Diameter and 22.931"" Finished length" & @CRLF & _
            "1) Add 0.25"" to barstock for machining" & @CRLF & _
            "2) Add 0.08"" for saw blade width" & @CRLF & _
            "     A) 22.931"" + 0.25"" + 0.08"" = 23.261""" & @CRLF & @CRLF & _
            "3) Barstock is generally 144"" long (12')" & @CRLF & _
            "     A) 144"" / 23.261"" = 6.190 (6 parts per 144"")" & @CRLF & _
            "     B) 6 * 23.261"" = 139.566"" (Not enough stock for 7 parts)" & @CRLF & _
            "     C) 144"" / 6 = 24"" Allocated Length")
EndFunc   ;==>FormulaCriteria

 


“Courage is being scared to death, but saddling up anyway”John Wayne

Share this post


Link to post
Share on other sites

#9 ·  Posted

My apologies, @Quesney just re-read my reply and realize it probably could not be more confusing if I had been trying (chalk it up to answering questions from my mobile phone). As water pointed out, the standard InputBox has a return value; either the string in the input field if OK is pressed, or a numeric @error value otherwise. I don't have XSkin loaded to play with, but it should be the same, even if it is returning 2 for Cancel instead of 1. Here is an (accurate) example of InputBox and checking for something in the field, which should translate to your XSkinInputBox:

$myAnswer = InputBox("Functionality Test", "Please enter a measurement")
    If @error Then ;Either quit or handle based on @error number
       ExitLoop
    ElseIf $myAnswer = "" Then
       MsgBox($MB_OK, "Return", "You need to enter a measurement") ;Catch empty input
       ExitLoop
    Else
       MsgBox($MB_OK, "Return", "Your part needs to be at least " & Round(($myAnswer + 0.125 + 0.08), 4))
    EndIf

Again, apologies on muddying the waters.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#10 ·  Posted

Thank you for the reply, But I think for what I want to do I will have to just remove using XSkins. If I use the XSkin pressing the cancel button always returns 2 and Ok returns 1, so if I leave the input box blank and hit ok the calculations go through as if I entered 1 and if I hit cancel it goes through as if I entered 2. Maybe an issue with the Xskininputbox, but again, thank you for your assistance on the issue.


“Courage is being scared to death, but saddling up anyway”John Wayne

Share this post


Link to post
Share on other sites

#11 ·  Posted

@JLogan3o13 Thank you again, wanted to share the final code, you really helped. I am sure there are things I could change and make the code "prettier" but for my first little program I am pleased.

#include <GUIConstantsEx.au3>
#include <ColorConstantS.au3>
#include <MsgBoxConstants.au3>

GUICreate("Allocated Length Calculator", 420, 170) ; Creates a dialog box
GUISetBkColor($COLOR_WHITE) ; will change background color
Local $sFinish = @CRLF & "Enter finished part length" & @CRLF & @CRLF & "NOTE: Part should have a diameter "
Local $idButton1 = GUICtrlCreateButton("Criteria Example", 10, 130, 100, 20)
Local $idRadio1 = GUICtrlCreateRadio("Less than 4"" diameter and finished length less than 2""", 10, 10, 300, 20)
Local $idRadio2 = GUICtrlCreateRadio("Less than 4"" diameter and finished length greater than or equal to 2""", 10, 30, 400, 20)
Local $idRadio3 = GUICtrlCreateRadio("Between 4"" to 12"" diameter and finished length less than 2""", 10, 50, 400, 20)
Local $idRadio4 = GUICtrlCreateRadio("Between 4"" to 12"" diameter and finished length greater than or equal to 2""", 10, 70, 400, 20)
Local $idRadio5 = GUICtrlCreateRadio("Greater than 12"" diameter", 10, 90, 150, 20)

GUISetState(@SW_SHOW)

RadioRequest()

Func RadioRequest()

    Local $idMsg, $myAnswer

    While 1

        $idMsg = GUIGetMsg()

        Select
            Case $idMsg = $GUI_EVENT_CLOSE
                ExitLoop

            Case $idMsg = $idRadio1
                $myAnswer = InputBox("Finished Length", $sFinish & "less than 4"" and finished length less than 2""", "", "", 450) ; Places the input box
                If @error Then ; On @error return to main gui
                    Return RadioRequest()
                ElseIf $myAnswer = "" Then
                    MsgBox($MB_ICONERROR, "ERROR:", "You need to enter a finished length") ; Catch empty input
                    Return RadioRequest()
                ElseIf $myAnswer >= "2" Then
                    MsgBox($MB_ICONERROR, "ERROR:", "Finished length must be less then 2""") ; Catch incorrect input
                    Return RadioRequest()
                Else
                    MsgBox($MB_ICONINFORMATION, "Stock/Length Breakdown", Floor(142 / ($myAnswer + 0.125 + 0.08)) & " pieces per 144"" length of bar stock" & _
                            @CRLF & @CRLF & "The allocated length per piece is " & Round(144 / Floor(142 / ($myAnswer + 0.125 + 0.08)), 4) & """") ; Display the result.
                    Return RadioRequest()
                EndIf

            Case $idMsg = $idRadio2
                $myAnswer = InputBox("Finished Length", $sFinish & "less than 4"" and finished length greater than or equal to 2""", "", "", 500) ; Places the input box
                If @error Then ; On @error return to main gui
                    Return RadioRequest()
                ElseIf $myAnswer = "" Then
                    MsgBox($MB_ICONERROR, "ERROR:", "You need to enter a finished length") ; Catch empty input
                    Return RadioRequest()
                ElseIf $myAnswer < "2" Then
                    MsgBox($MB_ICONERROR, "ERROR:", "Finished length must be 2"" or greater") ; Catch incorrect input
                    Return RadioRequest()
                Else
                    MsgBox($MB_ICONINFORMATION, "Stock/Length Breakdown", Floor(144 / ($myAnswer + 0.125 + 0.08)) & " pieces per 144"" length of bar stock" & _
                            @CRLF & @CRLF & "The allocated length is " & Round(144 / Floor(144 / ($myAnswer + 0.125 + 0.08)), 4) & """") ; Display the result.
                    Return RadioRequest()
                EndIf

            Case $idMsg = $idRadio3
                $myAnswer = InputBox("Finished Length", $sFinish & "between 4"" and 12"" and finished length less than 2""", "", "", 460) ; Places the input box
                If @error Then ; On @error return to main gui
                    Return RadioRequest()
                ElseIf $myAnswer = "" Then
                    MsgBox($MB_ICONERROR, "ERROR:", "You need to enter a finished length") ; Catch empty input
                    Return RadioRequest()
                ElseIf $myAnswer >= "2" Then
                    MsgBox($MB_ICONERROR, "ERROR:", "Finished length must be less then 2""") ; Catch incorrect input
                    Return RadioRequest()
                Else
                    MsgBox($MB_ICONINFORMATION, "Stock/Length Breakdown", Floor(142 / ($myAnswer + 0.25 + 0.08)) & " pieces per 144"" length of bar stock" & _
                            @CRLF & @CRLF & "The allocated length is " & Round(144 / Floor(142 / ($myAnswer + 0.25 + 0.08)), 4) & """") ; Display the result.
                    Return RadioRequest()
                EndIf

            Case $idMsg = $idRadio4
                $myAnswer = InputBox("Finished Length", $sFinish & "between 4"" and 12"" and finished length greater than 2""", "", "", 480) ; Places the input box
                If @error Then ; On @error return to main gui
                    Return RadioRequest()
                ElseIf $myAnswer = "" Then
                    MsgBox($MB_ICONERROR, "ERROR:", "You need to enter a finished length") ; Catch empty input
                    Return RadioRequest()
                ElseIf $myAnswer < "2" Then
                    MsgBox($MB_ICONERROR, "ERROR:", "Finished length must be 2"" or greater") ; Catch incorrect input
                    Return RadioRequest()
                Else
                    MsgBox($MB_ICONINFORMATION, "Stock/Length Breakdown", Floor(144 / ($myAnswer + 0.25 + 0.08)) & " pieces per 144"" length of bar stock" & _
                            @CRLF & @CRLF & "The allocated length is " & Round(144 / Floor(144 / ($myAnswer + 0.25 + 0.08)), 4) & """") ; Display the result.
                    Return RadioRequest()
                EndIf

            Case $idMsg = $idRadio5
                $myAnswer = InputBox("Finished Length", $sFinish & "greater than 12""", "", "", 450) ; Places the input box
                If @error Then ; On @error return to main gui
                    Return RadioRequest()
                ElseIf $myAnswer = "" Then
                    MsgBox($MB_ICONERROR, "ERROR:", "You need to enter a finished length") ; Catch empty input
                    Return RadioRequest()
                Else
                    MsgBox($MB_ICONINFORMATION, "Stock/Length Breakdown", Floor(144 / ($myAnswer + 0.375 + 0.08)) & " pieces per 144"" length of bar stock" & _
                            @CRLF & @CRLF & "The allocated length is " & Round(144 / Floor(144 / ($myAnswer + 0.375 + 0.08)), 4) & """") ; Display the result.
                    Return RadioRequest()
                EndIf

            Case $idMsg = $idButton1
                MsgBox($MB_ICONINFORMATION, "Formula Criteria", "Example: 6.5"" Diameter and 22.931"" Finished length" & @CRLF & @CRLF & _
                        "1) Add 0.25"" to barstock for machining" & @CRLF & _
                        "2) Add 0.08"" for saw blade width" & @CRLF & _
                        "     A) 22.931"" + 0.25"" + 0.08"" = 23.261""" & @CRLF & @CRLF & _
                        "3) Barstock is generally 144"" long" & @CRLF & _
                        "     A) 144"" / 23.261"" = 6.190 (6 parts per 144"")" & @CRLF & _
                        "     B) 6 * 23.261"" = 139.566"" (Not enough stock for 7 parts)" & @CRLF & _
                        "     C) 144"" / 6 = 24"" Allocated Length")
        EndSelect
    WEnd
EndFunc   ;==>RadioRequest

 


“Courage is being scared to death, but saddling up anyway”John Wayne

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