Jump to content

Get Rid Of Calculate Buton? - RESOLVED


Recommended Posts

I have made a converter for some variables and the script works but I am wanting to make the loop work like an onchange to when a variable is changed in either of three input boxes the calculation fires. I am including an SWF file as an example of what I am wanting. I have the code for the SWF File also if needed.

SWF Example File

#include <GUIConstants.au3>

$AForm1 = GUICreate("CARD CONVERTER", 270, 133, 417, 181)
$MainGrp = GUICtrlCreateGroup("CARD CONVERTER", 8, 8, 249, 113)
$pLabel = GUICtrlCreateLabel("P", 24, 56, 61, 17)
$sLabel = GUICtrlCreateLabel("S", 118, 56, 33, 17)
$cLabel = GUICtrlCreateLabel("C", 191, 56, 34, 17)
$p = GUICtrlCreateInput("", 16, 32, 73, 21)
$s = GUICtrlCreateInput("", 97, 32, 73, 21)
$c = GUICtrlCreateInput("", 176, 32, 73, 21)
$calculate = GUICtrlCreateButton("CALCULATE", 88, 72, 105, 25)
$clear = GUICtrlCreateButton("CLEAR", 88, 97, 105, 25)
GUISetState(@SW_SHOW)


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_Event_Close
            Exit 0
  Case $msg = $clear
   GUICtrlSetData($p,"")
   GUICtrlSetData($s,"")
   GUICtrlSetData($c,"")
        Case $msg = $calculate
   ;PConvert()
  If GUICtrlRead($p) <> 0 Then
   PConvert()
  ElseIf GUICtrlRead($s) <> 0 Then
   SConvert()
  ElseIf GUICtrlRead($c) <> 0 Then
   CConvert()
  Else
   MsgBox(4096,"", "You Must Enter A Digit")

  EndIf
    EndSelect
WEnd

Func PConvert()
If $p > 0 Then
 $r = GUICtrlRead($p)
 GUICtrlSetData($p, Round($r, 9))
 GUICtrlSetData($s, Round($r/24, 9))
 GUICtrlSetData($c, Round(($r/2)/24, 9))
ElseIf $p = 0 Then

        MsgBox(4096,"", "Please input P Number")
EndIf

EndFunc   ;==>PConvert

Func SConvert()
If $s > 0 Then
 $r = GUICtrlRead($s)
 GUICtrlSetData($p, Round(($r/2))*24)
 GUICtrlSetData($s, Round($r))
 GUICtrlSetData($c, Round($r/2))
ElseIf $s = 0 Then

        MsgBox(4096,"", "Please input S Number")
EndIf

EndFunc   ;==>SConvert

Func CConvert()
If $c > 0 Then
 $r = GUICtrlRead($c)
 GUICtrlSetData($p, Round(($r * 2) * 24))
 GUICtrlSetData($s, Round($r * 2))
 GUICtrlSetData($c, Round($r))
ElseIf $c = 0 Then

        MsgBox(4096,"", "Please input C Number")
EndIf

EndFunc   ;==>CConvert
Edited by gesller
Link to comment
Share on other sites

You have to use WM_COMMAND, and the MsgBoxes should displayed in a Status Bar.

#include <GUIConstants.au3>

$AForm1 = GUICreate("CARD CONVERTER", 270, 150, 417, 181)
$MainGrp = GUICtrlCreateGroup("CARD CONVERTER", 8, 8, 249, 113)
$pLabel = GUICtrlCreateLabel("P", 24, 56, 61, 17)
$sLabel = GUICtrlCreateLabel("S", 118, 56, 33, 17)
$cLabel = GUICtrlCreateLabel("C", 191, 56, 34, 17)
$p = GUICtrlCreateInput("", 16, 32, 73, 21)
$s = GUICtrlCreateInput("", 97, 32, 73, 21)
$c = GUICtrlCreateInput("", 176, 32, 73, 21)
$calculate = GUICtrlCreateButton("CALCULATE", 88, 72, 105, 25)
$clear = GUICtrlCreateButton("CLEAR", 88, 97, 105, 25)
$Status = GUICtrlCreateLabel("", 0, 133, 270, 17,$SS_SUNKEN)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND,"_TEST")
$i = 0
Func _TEST($hWnd, $Msg, $wParam, $lParam)
    Local $nNotifyCode    = BitShift($wParam, 16)
    Local $nID            = BitAnd($wParam, 0x0000FFFF)
    Local $hCtrl          = $lParam
    Local $EN_CHANGE =  0x0300
    If $nNotifyCode = $EN_CHANGE Then
    Switch $nID
        Case $p
            PConvert()
        Case $s
            SConvert()
        Case $c
            CConvert()
    EndSwitch
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_Event_Close
            Exit 0
  Case $msg = $clear
   GUICtrlSetData($p,"")
   GUICtrlSetData($s,"")
   GUICtrlSetData($c,"")
        Case $msg = $calculate
   ;PConvert()
  If GUICtrlRead($p) <> 0 Then
   PConvert()
  ElseIf GUICtrlRead($s) <> 0 Then
   SConvert()
  ElseIf GUICtrlRead($c) <> 0 Then
   CConvert()
  Else
   MsgBox(4096,"", "You Must Enter A Digit")

  EndIf
    EndSelect
WEnd

Func PConvert()
    $r = GUICtrlRead($p)
If $r > 0 Then
    GUICtrlSetData($Status,"")
 
 GUICtrlSetData($p, Round($r, 9))
 GUICtrlSetData($s, Round($r/24, 9))
 GUICtrlSetData($c, Round(($r/2)/24, 9))
Else
        GUICtrlSetData($Status,"Please input P Number")
EndIf

EndFunc   ;==>PConvert

Func SConvert()
    $r = GUICtrlRead($s)
If $r > 0 Then
 GUICtrlSetData($Status,"")
 GUICtrlSetData($p, Round(($r/2))*24)
 GUICtrlSetData($s, Round($r))
 GUICtrlSetData($c, Round($r/2))
Else
        GUICtrlSetData($Status,"Please input S Number")
EndIf

EndFunc   ;==>SConvert

Func CConvert()
    $r = GUICtrlRead($c)
If $r > 0 Then
 GUICtrlSetData($Status,"")
 GUICtrlSetData($p, Round(($r * 2) * 24))
 GUICtrlSetData($s, Round($r * 2))
 GUICtrlSetData($c, Round($r))
Else
        GUICtrlSetData($Status,"Please input C Number")
EndIf

EndFunc   ;==>CConvert

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...