Sign in to follow this  
Followers 0
future1995man

calculation

32 posts in this topic

Hi for all

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("autoitscript", 302, 153, 192, 124)
$Label1 = GUICtrlCreateLabel("1", 40, 32, 18, 17)
$Input1 = GUICtrlCreateInput("", 80, 32, 121, 21)
$Label2 = GUICtrlCreateLabel("2", 40, 72, 10, 17)
$Input2 = GUICtrlCreateInput("", 80, 64, 121, 21)
$Button1 = GUICtrlCreateButton("collect", 96, 97, 81, 31)
GUISetState(@SW_SHOW)
$Input=GUICtrlRead($Input1) * GUICtrlRead($Input1)
$text=$Input2 / $Input
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  case $Button1
   MsgBox(0,"",$text)
EndSwitch
WEnd

If user put 168 in INPUT1,, what is script that input 1 becomes 1,68

Another example: If you will put 172 in input1--- automatically it will be 1,72

If user put 77.3 in Input 2 ,, what is script that input 2 becomes 77 without ,3

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

Firstly there was several problems with your script. I've cleaned that up a little bit.

;#include <ButtonConstants.au3>
;#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
;#include <StaticConstants.au3>
;#include <WindowsConstants.au3>

Global $Form1 = GUICreate("autoitscript", 302, 153, 192, 124)
Global $Label1 = GUICtrlCreateLabel("1", 40, 32, 18, 17)
Global $Input1 = GUICtrlCreateInput("", 80, 32, 121, 21)
Global $Label2 = GUICtrlCreateLabel("2", 40, 72, 10, 17)
Global $Input2 = GUICtrlCreateInput("", 80, 64, 121, 21)
Global $Button1 = GUICtrlCreateButton("collect", 96, 97, 81, 31)
GUISetState(@SW_SHOW)

Global $Input, $text, $nMsg

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        case $Button1
            $Input = GUICtrlRead($Input1) * GUICtrlRead($Input1)
            $text = GUICtrlRead($Input2) / $Input
            MsgBox(0,"",$text)
    EndSwitch
WEnd

Now as far as your questions are concerned, they are not entirely clear. You should look at the functions: Round() and maybe Floor() and Ceiling() depending on what you want. These functions all do a similar thing. You can also use the opperator /= 100.

Edited by czardas

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

For Input1 (assuming all numbers will be 3 digits):

$Input1Left = StringTrimLeft ( $Input1, 1 )
$Input1Right = StringTrimRight ($Input1,2)
$Input1 = $Input1Left & "." & $Input1Right

For Input2 (assuming you want to round the number up or down):

Round ($Input2)
Edited by MuchTex

Share this post


Link to post
Share on other sites

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $Form1 = GUICreate("autoitscript", 302, 153, 192, 124)
Global $Label1 = GUICtrlCreateLabel("1", 40, 32, 18, 17)
Global $Input1 = GUICtrlCreateInput("", 80, 32, 121, 21)
Global $Label2 = GUICtrlCreateLabel("2", 40, 72, 10, 17)
Global $Input2 = GUICtrlCreateInput("", 80, 64, 121, 21)
Global $Button1 = GUICtrlCreateButton("collect", 96, 97, 81, 31)
GUISetState(@SW_SHOW)
Global $Input, $text, $nMsg
$Input1Left = StringTrimLeft ( $Input1, 1 )
$Input1Right = StringTrimRight ($Input1,2)
$Input1 = $Input1Left & "." & $Input1Right
$Input2=Round ($Input2)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        case $Button1
            $Input = GUICtrlRead($Input1) * GUICtrlRead($Input1)
            $text = GUICtrlRead($Input2) / GUICtrlRead($Input)
            MsgBox(0,"",GUICtrlRead($text))
    EndSwitch
WEnd

This is my attempt

Share this post


Link to post
Share on other sites

Hi,

Maybe this...

#include <GUIConstantsEx.au3>

#region GUI
Local Const $hGUI = GUICreate("autoitscript", 302, 153)

Local $iLabel1 = 0, $iInput1 = 0, $iLabel2 = 0, $iInput2 = 0, $iBtn1 = 0

$iLabel1 = GUICtrlCreateLabel("1", 40, 32, 18, 17)
$iInput1 = GUICtrlCreateInput("", 80, 32, 121, 21)

$iLabel2 = GUICtrlCreateLabel("2", 40, 72, 10, 17)
$iInput2 = GUICtrlCreateInput("", 80, 64, 121, 21)

$iBtn1 = GUICtrlCreateButton("collect", 96, 97, 81, 31)
GUISetState(@SW_SHOW, $hGUI)
#endregion

Local $iMsg = 0, $sInput1Read = "", $sInput2Read = ""

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $iBtn1
            $sInput1Read = GUICtrlRead($iInput1)
            If StringIsFloat($sInput1Read) = 0 Then
                GUICtrlSetData($iInput1, StringLeft($sInput1Read, 1) & "." & StringTrimLeft($sInput1Read, 1))
            EndIf

            $sInput2Read = GUICtrlRead($iInput2)
            If StringIsFloat($sInput2Read) = 1 Then
                GUICtrlSetData($iInput2, StringLeft($sInput2Read, StringInStr($sInput2Read, ".", 2) -1))
            EndIf
    EndSwitch
WEnd

GUIDelete($hGUI)

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

This is my attempt

Look at the first changes I made for you in the second post and compair that with your original first post. You have to put the arguments inside the loop. You also have to read the data from the input controls with GUICtrlRead before you can do anything with it. These are the most important things you are not doing correctly, which is why it doesn't work as you expect.

$input1 and $input2 are the input controls: they are not numbers. You have to read them.

Edited by czardas

Share this post


Link to post
Share on other sites

Here is a simplified example with comments explaining every step of the process in detail. You need to fully understand every line of code before you continue.

; Get external libraries needed for the script
#include <GUIConstantsEx.au3>

; Declare the varible names you need for the GUI
Global $hGUI, $hInput, $hButton

; Create the GUI
$hGUI = GUICreate("Example", 302, 153, 192, 124)

; Create a control
$hInput = GUICtrlCreateInput("", 80, 32, 121, 21)

; Create another control
$hButton = GUICtrlCreateButton("Read Input", 96, 97, 81, 31)

; Show the GUI
GUISetState(@SW_SHOW)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Declare the varibles used in the loop
Global $iMsg, $sData

; Loop forever
While 1
    ; Poll the controls to see if a message was received
    $iMsg = GUIGetMsg()

    ; See which message was received
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            ; Exit the loop
            ExitLoop
        case $hButton
            ; Read the input control
            $sData = GUICtrlRead($hInput)

            ; Do something with the data
            MsgBox(0 ,"Input Details", $sData)
    EndSwitch
    ; Go back to the start of the loop
WEnd

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

#include <GUIConstantsEx.au3>
#region GUI
Local Const $hGUI = GUICreate("autoitscript", 302, 153)
Local $iLabel1 = 0, $iInput1 = 0, $iLabel2 = 0, $iInput2 = 0, $iBtn1 = 0
$iLabel1 = GUICtrlCreateLabel("1", 40, 32, 18, 17)
$iInput1 = GUICtrlCreateInput("", 80, 32, 121, 21)
$iLabel2 = GUICtrlCreateLabel("2", 40, 72, 10, 17)
$iInput2 = GUICtrlCreateInput("", 80, 64, 121, 21)
$iBtn1 = GUICtrlCreateButton("collect", 96, 97, 81, 31)
GUISetState(@SW_SHOW, $hGUI)
#endregion
Local $iMsg = 0, $sInput1Read = "", $sInput2Read = ""
$sInput1Read = GUICtrlRead($iInput1)
         If StringIsFloat($sInput1Read) = 0 Then
             GUICtrlSetData($iInput1, StringLeft($sInput1Read, 1) & "." & StringTrimLeft($sInput1Read, 1))
         EndIf
$sInput2Read = GUICtrlRead($iInput2)
         If StringIsFloat($sInput2Read) = 1 Then
             $xinput= GUICtrlSetData($iInput2, StringLeft($sInput2Read, StringInStr($sInput2Read, ".", 2) -1))*GUICtrlSetData($iInput2, StringLeft($sInput2Read, StringInStr($sInput2Read, ".", 2) -1)
         EndIf
$text= GUICtrlRead($sInput2Read) / $xinput
$XTEXT=GUICtrlRead($text)
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
     Case $GUI_EVENT_CLOSE
         ExitLoop
     Case $iBtn1
         MsgBox(0,"",$XTEXT)

EndSwitch
WEnd
GUIDelete($hGUI)

Edited by future1995man

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

czardasFirefox(#6 )

thanks

Edited by future1995man

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

#include <GUIConstantsEx.au3>
#region GUI
Local Const $hGUI = GUICreate("autoitscript", 302, 153)
Local $iLabel1 = 0, $iInput1 = 0, $iLabel2 = 0, $iInput2 = 0, $iBtn1 = 0
$iLabel1 = GUICtrlCreateLabel("1", 40, 32, 18, 17)
$iInput1 = GUICtrlCreateInput("", 80, 32, 121, 21)
$iLabel2 = GUICtrlCreateLabel("2", 40, 72, 10, 17)
$iInput2 = GUICtrlCreateInput("", 80, 64, 121, 21)
$iBtn1 = GUICtrlCreateButton("collect", 96, 97, 81, 31)
GUISetState(@SW_SHOW, $hGUI)
#endregion
Local $iMsg = 0, $sInput1Read = "", $sInput2Read = ""
$sInput1Read = GUICtrlRead($iInput1)
         If StringIsFloat($sInput1Read) = 0 Then
             GUICtrlSetData($iInput1, StringLeft($sInput1Read, 1) & "." & StringTrimLeft($sInput1Read, 1))
         EndIf
$sInput2Read = GUICtrlRead($iInput2)
         If StringIsFloat($sInput2Read) = 1 Then
             $xinput= GUICtrlSetData($iInput2, StringLeft($sInput2Read, StringInStr($sInput2Read, ".", 2) -1))*GUICtrlSetData($iInput2, StringLeft($sInput2Read, StringInStr($sInput2Read, ".", 2) -1)
         EndIf
$text= GUICtrlRead($sInput2Read) / $xinput
$XTEXT=GUICtrlRead($text)
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
     Case $GUI_EVENT_CLOSE
         ExitLoop
     Case $iBtn1
         MsgBox(0,"",$XTEXT)

EndSwitch
WEnd
GUIDelete($hGUI)

I want the result show in message

for example

INPUT 1 = 168

INPUT 2 = 88.3 OR 88,3

When I press collect button, It will show result in msgbox

The result will be as number from following operation

88 / (1.68*1.68)

result = INPUT 2 / (input1*input1)

Edited by future1995man

Share this post


Link to post
Share on other sites

Hmm, you are still reading the input controls before you type anything in them. You only read the control after you click the button - as I have shown in my previous post. Please look at it again.

Share this post


Link to post
Share on other sites

Hmm, you are still reading the input controls before you type anything in them. You only read the control after you click the button - as I have shown in my previous post. Please look at it again.

I look it more one time but I can not do that.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I don't understand you. You are reading the controls (one time only) before you have time to type anything into them. So you are doing a calculation on nothing. The answer you get will always be wrong, unless you put GUICtrlRead in the right place (inside the while loop). I can't think of any simpler way to explain this.

Edited by czardas
1 person likes this

Share this post


Link to post
Share on other sites

#include <GUIConstantsEx.au3>
#region GUI
Local Const $hGUI = GUICreate("autoitscript", 302, 153)
Local $iLabel1 = 0, $iInput1 = 0, $iLabel2 = 0, $iInput2 = 0, $iBtn1 = 0
$iLabel1 = GUICtrlCreateLabel("height", 40, 32, 40, 17)
$iInput1 = GUICtrlCreateInput("", 80, 32, 121, 21)
$iLabel2 = GUICtrlCreateLabel("mass", 40, 72, 30, 17)
$iInput2 = GUICtrlCreateInput("", 80, 64, 121, 21)
$iBtn1 = GUICtrlCreateButton("Body mass index", 90, 97, 100, 31)
GUISetState(@SW_SHOW, $hGUI)
#endregion
Local $iMsg = 0, $sInput1Read = "", $sInput2Read = ""
$sInput1Read = GUICtrlRead($iInput1)
            If StringIsFloat($sInput1Read) = 0 Then
                GUICtrlSetData($iInput1, StringLeft($sInput1Read, 1) & "." & StringTrimLeft($sInput1Read, 1))
    EndIf
   
    $sInput2Read = GUICtrlRead($iInput2)
            If StringIsFloat($sInput2Read) = 1 Then
                GUICtrlSetData($iInput2, StringLeft($sInput2Read, StringInStr($sInput2Read, ".", 2) -1))
    EndIf
    $height=$sinput1read*$siInput1Read
    $Bodymassindex=$sInput2Read/$height
   
While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $iBtn1
           
    MsgBox(0,"","Body mass index is"&$bodymassindex")
   
  
           
    EndSwitch
WEnd
GUIDelete($hGUI)

I wait experts in this forum.

Share this post


Link to post
Share on other sites

Can you be at least one time enough clear to explain your problem?


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

This is more vague than what you already said...


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

This is more vague than what you already said...

If any one enter his height(m) & weight(kg) inside boxex then calculate bottun, it will appear BMI

Share this post


Link to post
Share on other sites

Are you the poster of

If so, be aware that using multiple accounts is not within forum rules (link at the bottom right of these pages).


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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  
Followers 0