Jump to content

Autmatic inputbox value


Recommended Posts

hi guys,,,, I wanna add an automatic Total value to my GUI. But, I dont know the correct way to do this.

My GUI is looping all time and value is flashing (cause inside While).

I need some help to get correct total value after I tape amount and price.

thx

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $total = ""

gui()
Func gui()
#Region ### START Koda GUI section ###
Global $main = GUICreate("I need total value!!!", 465, 340, 269, 193) ; 465, 245, 269, 193
GUICtrlCreateLabel("product", 10, 20)
$pro = GUICtrlCreateInput("balas", 50, 20, 80, 20)
GUICtrlCreateLabel("Amount", 10, 50)
$qtd = GUICtrlCreateInput("10000", 50, 50, 80, 20)
GUICtrlCreateLabel("Price", 10, 90)
$uni = GUICtrlCreateInput("50", 50, 90, 80, 20)
GUICtrlCreateLabel("Total", 10, 130)

#EndRegion ### END Koda GUI section ###
GUISetState()


While 1
$pro1 = GUICtrlRead($pro)
$qtd1 = GUICtrlRead($qtd)
$qtd1 = StringReplace($qtd1, ".","")
$uni1 = GUICtrlRead($uni)
$uni1 = StringReplace($uni1, "$","")
$uni1 = StringReplace($uni1, "R","")
$uni1 = StringReplace($uni1, " ","")
$uni1 = StringReplace($uni1, ",",".")
$t = StringSplit($pro1, " ")


If $t[1] = "balas" or $t[1] = "bala" or $t[1] = " balas" Then
$qtd1 = $qtd1/1000
$total = "RS " & $qtd1*$uni1
EndIf

If $qtd <> "" and $uni <> "" Then
    $tot = GUICtrlCreateInput($total, 50, 130, 80, 20)
EndIf

    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
        Exit
EndSwitch
WEnd
EndFunc
Link to comment
Share on other sites

Hope this help Posted Image

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

gui()
Func gui()

Global $main = GUICreate("I need total value!!!", 465, 340, 269, 193) ; 465, 245, 269, 193
GUICtrlCreateLabel("product", 10, 20)
$pro = GUICtrlCreateInput("balas", 50, 20, 80, 20)
GUICtrlCreateLabel("Amount", 10, 50)
$qtd = GUICtrlCreateInput("10000", 50, 50, 80, 20)
GUICtrlCreateLabel("Price", 10, 90)
$uni = GUICtrlCreateInput("500", 50, 90, 80, 20)
GUICtrlCreateLabel("Total", 10, 130)
$TotalP = GUICtrlCreateInput("", 50, 130, 80, 20)

GUISetState()


While 1

    If $qtd <> "" and $uni <> "" Then
        $qtd1 = GUICtrlRead($qtd) / 1000
        $uni1 = GUICtrlRead($uni)
        GUICtrlSetData($TotalP, "RS " & $uni1*$qtd1)
    EndIf

    Switch GUIGetMsg()
        
        Case $GUI_EVENT_CLOSE
            Exit
            
    EndSwitch
WEnd
EndFunc
Edited by Jayson
Link to comment
Share on other sites

Try this:

#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 236, 174, -1, -1)
$lProduct = GUICtrlCreateLabel("Product:", 17, 18, 44, 17, $SS_RIGHT)
$Combo = GUICtrlCreateCombo("Apples", 64, 16, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Banana|Pears", "Apples")
GUICtrlSetOnEvent(-1, "Combo")
$lAmount = GUICtrlCreateLabel("Amount:", 18, 50, 43, 17, $SS_RIGHT)
$iAmount = GUICtrlCreateInput("100", 64, 48, 145, 21)
GUICtrlSetOnEvent(-1, "Calculate")
$lPrice = GUICtrlCreateLabel("Price:", 30, 82, 31, 17, $SS_RIGHT)
$iPrice = GUICtrlCreateInput("5000", 64, 80, 145, 21)
GUICtrlSetOnEvent(-1, "Calculate")
$lTotal = GUICtrlCreateLabel("Total:", 24, 131, 37, 17, $SS_RIGHT)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$iTotal = GUICtrlCreateInput("", 64, 128, 145, 21)
Calculate()
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")


While Sleep(10000)
WEnd

Func Combo()
    Local $product = GUICtrlRead($Combo)
    Switch $product
        Case "Apples"
            GUICtrlSetData($iPrice, "5000")
        Case "Banana"
            GUICtrlSetData($iPrice, "6000")
        Case "Pears"
            GUICtrlSetData($iPrice, "5500")
    EndSwitch
    Calculate()
EndFunc

Func Calculate()
    GUICtrlSetData($iTotal, GUICtrlRead($iAmount) * GUICtrlRead($iPrice)& " $")
EndFunc

Func _Exit()
    GUIDelete($hGUI)
    Exit
EndFunc

You have to modify the code for your needs.

To improve it you can use windows message code for e.g. realtime calculation, etc.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

To insert new values you have to rewrite the code using e.g. an ini file where you can store the values.

The version I did can only handle static values.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

as I thought.

1 last question...

Im using your solution UEZ but im having a problem,,, I have a Main GUI to start my program. But, when I start this another GUI, I cant use GUIdelete() and exitloop to go back to main gui. how can i fix this???

Link to comment
Share on other sites

as I thought.

1 last question...

Im using your solution UEZ but im having a problem,,, I have a Main GUI to start my program. But, when I start this another GUI, I cant use GUIdelete() and exitloop to go back to main gui. how can i fix this???

This will help!

Link to comment
Share on other sites

This will help!

sry man,, but I know that and it doesnt answer my doubt,,, but I fixed yesterday.

Just posting my solution to help any1 wuth same problem. I dont know if it is the correct or the best way to do this,, but it was a simple solution and worked fine.

#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


gui1()

Func gui1()

    $hGUI1 = GUICreate("MAIN GUI", 200, 200, 100, 100)
    $hButton1 = GUICtrlCreateButton("GUI2", 10, 10, 80, 30)
    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $hButton1
                GUI2()
        EndSwitch
    WEnd

EndFunc  



Func GUI2()
Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 236, 174, -1, -1)
$lProduct = GUICtrlCreateLabel("Product:", 17, 18, 44, 17, $SS_RIGHT)
$Combo = GUICtrlCreateCombo("Apples", 64, 16, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Banana|Pears", "Apples")
GUICtrlSetOnEvent(-1, "Combo")
$lAmount = GUICtrlCreateLabel("Amount:", 18, 50, 43, 17, $SS_RIGHT)
Global $iAmount = GUICtrlCreateInput("100", 64, 48, 145, 21)
GUICtrlSetOnEvent(-1, "Calculate")
$lPrice = GUICtrlCreateLabel("Price:", 30, 82, 31, 17, $SS_RIGHT)
Global $iPrice = GUICtrlCreateInput("5000", 64, 80, 145, 21)
GUICtrlSetOnEvent(-1, "Calculate")
$lTotal = GUICtrlCreateLabel("Total:", 24, 131, 37, 17, $SS_RIGHT)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
Global $iTotal = GUICtrlCreateInput("", 64, 128, 145, 21)
Calculate()
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")


While 1 
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        GUIDelete()
        ExitLoop
    EndSwitch
WEnd
EndFunc


Func Combo()
    Local $product = GUICtrlRead($Combo)
    Switch $product
        Case "Apples"
            GUICtrlSetData($iPrice, "5000")
        Case "Banana"
            GUICtrlSetData($iPrice, "6000")
        Case "Pears"
            GUICtrlSetData($iPrice, "5500")
    EndSwitch
    Calculate()
EndFunc

Func Calculate()
    GUICtrlSetData($iTotal, GUICtrlRead($iAmount) * GUICtrlRead($iPrice)& " $")
EndFunc

Func _Exit()
    Opt("GUIOnEventMode", 0)
    Send("{ESC}")
    Return
EndFunc

thx all guys who helped me,..

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...