pezo89 Posted January 30, 2010 Share Posted January 30, 2010 Hi guys, i where just wondering if there is an easy way to do this, my knowledge with this subject is at the 1% thou, what i need calculated is first checkbox multiplied on the entered number in the KM input. then add the second or third checkbox in the same row ontop of that number and finaly add the last number called "bonus" ontop of there each row from the left example:1: 20km (15.80x20+40+89) checkbox: 1 =15,80(1) = 316 + 40 checkbox: 2 = 89(1) number to be shown in "Pris" =445 example:2: 40km (24x40+74+100) checkbox: 1 =24(7) = 1134 checkbox: 3 = 100(7) number to be shown in "Pris" =1134 expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <WindowsConstants.au3> ;priser: ;checkbox-3: ;1: 66 ,- ;2: 79 ,- ;3: 81 ,- ;4: 79 ,- ;5: 91 ,- ;6: 81 ,- ;7: 100 ,- ;checkbox-2: ;1: 89,- ;2: 109,- ;3: 109,- ;4: 109,- ;5: 130,- ;6: 109,- ;7: 135,- ;checkbox-1:multiplied with total KM ;1: 15.80,- ;2: 19,- ;3: 19,- ;4: 19,- ;5: 21,- ;6: 19,- ;7: 24,- ;Bonus: ;1: 40,- ;2: 46,- ;3: 50,- ;4: 46,- ;5: 58,- ;6: 50,- ;7: 74,- Opt('MustDeclareVars', 1) Example() Func Example() Local $checkCN, $msg GUICreate("Kalk",500,320,-1,-1,"$DS_SETFOREGROUND") ; will create a dialog box that when displayed is centered $checkCN = GUICtrlCreateCheckbox("Dag Hverdager Man-Fre (07-17)", 10, 30, 180, 20) $checkCN = GUICtrlCreateCheckbox("Kveld Hverdager Man-Fre (17-23)", 10, 50, 180, 20) $checkCN = GUICtrlCreateCheckbox("Natt Hverdager Man-Fre (23-07)", 10, 70, 180, 20) $checkCN = GUICtrlCreateCheckbox("Lørdag (07-23)", 10, 90, 180, 20) $checkCN = GUICtrlCreateCheckbox("Helg Natt(23-07)", 10, 110, 180, 20) $checkCN = GUICtrlCreateCheckbox("Søndag (07-07)", 10, 130, 180, 20) $checkCN = GUICtrlCreateCheckbox("Høytid ", 10, 150, 180, 20) ;$checkCN = GUICtrlCreateCheckbox("PÅSLAG", 300, 30, 150, 20) $checkCN = GUICtrlCreateLabel("FORHÅND", 250,10,100,20);<-lABEL $checkCN = GUICtrlCreateLabel("DIREKTE", 350,10,100,20);<-lABEL ;==============>1<==================; $checkCN = GUICtrlCreateCheckbox("", 270, 30, 20, 20);FORHÅND $checkCN = GUICtrlCreateCheckbox("", 370, 30, 150, 20);DIREKTE ;==============>2<==================; $checkCN = GUICtrlCreateCheckbox("", 270, 50, 20, 20);FORHÅND $checkCN = GUICtrlCreateCheckbox("", 370, 50, 150, 20);DIREKTE ;==============>3<==================; $checkCN = GUICtrlCreateCheckbox("", 270, 70, 20, 20);FORHÅND $checkCN = GUICtrlCreateCheckbox("", 370, 70, 150, 20);DIREKTE ;==============>4<==================; $checkCN = GUICtrlCreateCheckbox("", 270, 90, 20, 20);FORHÅND $checkCN = GUICtrlCreateCheckbox(" ", 370, 90, 150, 20);DIREKTE ;==============>5<==================; $checkCN = GUICtrlCreateCheckbox("", 270, 110, 20, 20);FORHÅND $checkCN = GUICtrlCreateCheckbox(" ", 370, 110, 150, 20);DIREKTE ;==============>6<==================; $checkCN = GUICtrlCreateCheckbox("", 270, 130, 20, 20);FORHÅND $checkCN = GUICtrlCreateCheckbox(" ", 370, 130, 150, 20);DIREKTE ;==============>7<==================; $checkCN = GUICtrlCreateCheckbox("", 270, 150, 20, 20);FORHÅND $checkCN = GUICtrlCreateCheckbox(" ", 370, 150, 150, 20);DIREKTE $checkCN = GUICtrlCreateInput("KM", 190, 190, 40, 20);KM numbers in here $checkCN = GUICtrlCreateInput("Pris", 150, 220, 300, 20 );calculated price ;CALC & EXIT BUTTON Local $Button_1, $Button_2, $msg $Button_1 = GUICtrlCreateButton("KALKULER", 250, 242, 100,20,$BS_DEFPUSHBUTTON) $Button_2 = GUICtrlCreateButton("AVSLUTT", 400,270,70,20) GUISetState() ; will display an dialog box with 2 button ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 ;;CALCULATE THE CHECKED BOXES + THE KM NUMBER Case $msg = $Button_2 Exit EndSelect WEnd ;==>Example GUISetState() ; will display an dialog box with 1 checkbox ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>Example Link to comment Share on other sites More sharing options...
water Posted January 30, 2010 Share Posted January 30, 2010 Had just a fast look at the code. Every GUI control has to have it's own variable assigned so that you can access the value of the GUI controls.GUICreate("Kalk",500,320,-1,-1,"$DS_SETFOREGROUND") $checkCN1 = GUICtrlCreateCheckbox("Dag Hverdager Man-Fre (07-17)", 10, 30, 180, 20) $checkCN2 = GUICtrlCreateCheckbox("Kveld Hverdager Man-Fre (17-23)", 10, 50, 180, 20) $checkCN3 = GUICtrlCreateCheckbox("Natt Hverdager Man-Fre (23-07)", 10, 70, 180, 20) $checkCN4 = GUICtrlCreateCheckbox("Lørdag (07-23)", 10, 90, 180, 20) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 30, 2010 Moderators Share Posted January 30, 2010 pezo89,You need to look at the tutorials you can find here and here - you have not quite grasped the way AutoIt works. Here is a version of your code which (I think) acts as you want - study it and see if you can work out why it does so.expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) ; Set the various values into an array Global $Values[7][4] =[ _ [15.8, 40, 89, 66], _ [19, 46, 109, 79], _ [19, 50, 109, 81], _ [19, 46, 109, 79], _ [21, 58, 130, 91], _ [19, 50, 109, 81], _ [24, 74, 135, 100]] Example() Func Example() Local $checkCN[7][3] ; This array holds the ControlIDs for the radios Local $msg, $Input1, $Input2, $Button_1, $Button_2 GUICreate("Kalk",500,320,-1,-1,"$DS_SETFOREGROUND") ; will create a dialog box that when displayed is centered ; Create the radios in groups so only 1 can be selected at a time GUIStartGroup() $checkCN[0][0] = GUICtrlCreateRadio("Dag Hverdager Man-Fre (07-17)", 10, 30, 180, 20) $checkCN[1][0] = GUICtrlCreateRadio("Kveld Hverdager Man-Fre (17-23)", 10, 50, 180, 20) $checkCN[2][0] = GUICtrlCreateRadio("Natt Hverdager Man-Fre (23-07)", 10, 70, 180, 20) $checkCN[3][0] = GUICtrlCreateRadio("Lørdag (07-23)", 10, 90, 180, 20) $checkCN[4][0] = GUICtrlCreateRadio("Helg Natt(23-07)", 10, 110, 180, 20) $checkCN[5][0] = GUICtrlCreateRadio("Søndag (07-07)", 10, 130, 180, 20) $checkCN[6][0] = GUICtrlCreateRadio("Høytid ", 10, 150, 180, 20) ;$checkCN = GUICtrlCreateRadio("PÅSLAG", 300, 30, 150, 20) GUICtrlCreateLabel("FORHÅND", 250,10,100,20);<-lABEL GUICtrlCreateLabel("DIREKTE", 350,10,100,20);<-lABEL GUIStartGroup() $checkCN[0][1] = GUICtrlCreateRadio("", 270, 30, 20, 20);FORHÅND GUICtrlSetState(-1, $GUI_CHECKED) $checkCN[0][2] = GUICtrlCreateRadio("", 370, 30, 150, 20);DIREKTE GUIStartGroup() $checkCN[1][1] = GUICtrlCreateRadio("", 270, 50, 20, 20);FORHÅND GUICtrlSetState(-1, $GUI_CHECKED) $checkCN[1][2] = GUICtrlCreateRadio("", 370, 50, 150, 20);DIREKTE GUIStartGroup() $checkCN[2][1] = GUICtrlCreateRadio("", 270, 70, 20, 20);FORHÅND GUICtrlSetState(-1, $GUI_CHECKED) $checkCN[2][2] = GUICtrlCreateRadio("", 370, 70, 150, 20);DIREKTE GUIStartGroup() $checkCN[3][1] = GUICtrlCreateRadio("", 270, 90, 20, 20);FORHÅND GUICtrlSetState(-1, $GUI_CHECKED) $checkCN[3][2] = GUICtrlCreateRadio(" ", 370, 90, 150, 20);DIREKTE GUIStartGroup() $checkCN[4][1] = GUICtrlCreateRadio("", 270, 110, 20, 20);FORHÅND GUICtrlSetState(-1, $GUI_CHECKED) $checkCN[4][2] = GUICtrlCreateRadio(" ", 370, 110, 150, 20);DIREKTE GUIStartGroup() $checkCN[5][1] = GUICtrlCreateRadio("", 270, 130, 20, 20);FORHÅND GUICtrlSetState(-1, $GUI_CHECKED) $checkCN[5][2] = GUICtrlCreateRadio(" ", 370, 130, 150, 20);DIREKTE GUIStartGroup() $checkCN[6][1] = GUICtrlCreateRadio("", 270, 150, 20, 20);FORHÅND GUICtrlSetState(-1, $GUI_CHECKED) $checkCN[6][2] = GUICtrlCreateRadio(" ", 370, 150, 150, 20);DIREKTE ; Deactivate the FORHAND/DIREKT radios For $i = 0 To 6 GUICtrlSetState($checkCN[$i][1], $GUI_DISABLE) GUICtrlSetState($checkCN[$i][2], $GUI_DISABLE) Next $Input1 = GUICtrlCreateInput("KM", 190, 190, 40, 20);KM numbers in here $Input2 = GUICtrlCreateInput("Pris", 150, 220, 300, 20 );calculated price $Button_1 = GUICtrlCreateButton("KALKULER", 250, 242, 100,20,$BS_DEFPUSHBUTTON) $Button_2 = GUICtrlCreateButton("AVSLUTT", 400,270,70,20) GUISetState() Local $iCurrSel = 7 ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 ;;CALCULATE THE CHECKED BOXES + THE KM NUMBER Local $nResult = _Calculate($checkCN, $Input1) GUICtrlSetData($Input2, $nResult) Case $msg = $Button_2 Exit EndSelect ; Activate the FORHAND/DIREKT radios for the selected option only For $i = 0 To 6 If GUICtrlRead($checkCN[$i][0]) = 1 Then ExitLoop Next If $i <> $iCurrSel Then GUICtrlSetState($checkCN[$i][1], $GUI_ENABLE) GUICtrlSetState($checkCN[$i][2], $GUI_ENABLE) If $iCurrSel <> 7 Then GUICtrlSetState($checkCN[$iCurrSel][1], $GUI_DISABLE) GUICtrlSetState($checkCN[$iCurrSel][2], $GUI_DISABLE) EndIf $iCurrSel = $i EndIf WEnd EndFunc Func _Calculate($checkCN, $Input1) Local $iCheck ; Read KM Input Local $sKM = GUICtrlRead($Input1) If $sKM = "KM" Or $sKM = "" Then ; No KM Input MsgBox(0, "Error", "Please enter a KM Value") Return 0 Else ; Find clicked radio in first row For $i = 0 To 6 If GUICtrlRead($checkCN[$i][0]) = 1 Then ExitLoop Next ; Check a radio was selected If $i = 7 Then MsgBox(0, "Error", "Please select a radio in the first column") Return 0 EndIf ; Get basic value and bonus Local $nValue = $Values[$i][0] Local $iBonus = $Values[$i][1] ; Check which of the FORHAND/DIREKT buttons is selected If GUICtrlRead($checkCN[$i][1]) = 1 Then $iCheck = $Values[$i][2] Else $iCheck = $Values[$i][3] EndIf ; Now do the calculation Local $nResult = ($sKM * $nValue) + $iBonus + $iCheck Return $nResult EndIf EndFuncAsk if anything is unclear - but be prepared to be told "Go and read the Help file and the tutorials"! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now