Phaser Posted January 14, 2011 Share Posted January 14, 2011 Hi everyone Could someone show me the correct way to do this in Autoit please Local $order,$bags_needed[6] Local $bag_values[7] = [25,10,5,1,0.50,0.10,0.01] $order = 799.16 ;-- current order For $i = 0 to UBound($bag_values) $bags_needed = floor($order/$bag_values[$i]) $order = $bag_values[$i]*$bags_needed[] ;<----- error here Next _ArrayDisplay($bags_needed) I would like it to produce the following for the order of 799.16 grams 25 bag x 31 10 bag x 2 1 bag x 4 0.50 bag x 0 0.10 bag x 1 0.01 bag x 6 Hope its explained good enough, is there an easier way for the above? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 14, 2011 Moderators Share Posted January 14, 2011 Phaser, I would do it this way: #include <Array.au3> Global $aBag_Values[7] = [25, 10, 5, 1, 0.50, 0.10, 0.01] Global $aBag_Number[7] Global $nOrder = 799.16 ;-- current order ; Make into an integer to avoid rounding errors ;) $nOrder = $nOrder * 100 For $i = 0 To UBound($aBag_Values) - 1 ; Note you need 1 less that the total number because you have element [0] ;) ; How many of this size bag can we get? $aBag_Number[$i] = Int($nOrder / ($aBag_Values[$i] * 100)) ; Reduce the value by that many bags $nOrder -= $aBag_Values[$i] * $aBag_Number[$i] * 100 Next _ArrayDisplay($aBag_Number) 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...
Phaser Posted January 14, 2011 Author Share Posted January 14, 2011 Many thanks M23 works as expected, cheers Link to comment Share on other sites More sharing options...
Phaser Posted January 14, 2011 Author Share Posted January 14, 2011 mm just noticed a problem, sometimes the order can be sent through for 799 x 0.10 grams, I would then like to calculate the 799 0.10 units to produce 79.9 which would give me 25 x 3 10 x 0 5 x 0 1 x 4 0.5 x 1 0.10 x 4 0.01 x 0 And if it was 799 x 0.01 grams it would be 7.99 25 x 0 10 x 0 5 x 1 1 x 2 0.50 x 1 0.10 x 4 0.01 x 9 Hope it makes sense, thanks again Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 14, 2011 Moderators Share Posted January 14, 2011 Phaser, Do you know any basic maths? Good job I am not starting to redecorate the kitchen until tomorrow! expandcollapse popup#include <Array.au3> Global $aBag_Values[7] = [25, 10, 5, 1, 0.50, 0.10, 0.01] Global $aBag_Number[7], $aLabels[7] #include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) GUICtrlCreateLabel("Chose Unit", 10, 10, 100, 20) $hCombo = GUICtrlCreateCombo("", 10, 30, 100, 20) GUICtrlSetData($hCombo, "25|10|5|1|0.50|0.10|0.01") GUICtrlCreateLabel("Input Number", 150, 10, 100, 20) $hInput = GUICtrlCreateInput("", 150, 30, 100, 20) $hButton = GUICtrlCreateButton("Calculate", 10, 100, 60, 30) For $i = 0 To 6 $aLabels[$i] = GUICtrlCreateLabel($aBag_Values[$i] & ":", 10, 150 + (20 * $i), 200, 20) Next GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton _Calculate() EndSwitch WEnd Func _Calculate() $nAmount = GUICtrlRead($hInput) * GUICtrlRead($hCombo) * 100 For $i = 0 To UBound($aBag_Values) - 1 $aBag_Number[$i] = Int($nAmount / ($aBag_Values[$i] * 100)) $nAmount -= $aBag_Values[$i] * $aBag_Number[$i] * 100 Next For $i = 0 To 6 GUICtrlSetData($aLabels[$i], $aBag_Values[$i] & ":" & @TAB & $aBag_Number[$i]) Next EndFunc 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...
Phaser Posted January 14, 2011 Author Share Posted January 14, 2011 Do you know any basic maths?I do actually but only as basic as making sure I get the correct change!!Sorry for my weakness but thanks you very much, I hope your kitchen refurb goes well and Mrs Melba is happy with the work.Thanks again, much appreciated Link to comment Share on other sites More sharing options...
Phaser Posted January 15, 2011 Author Share Posted January 15, 2011 Hi Melba23 I noticed a few incorrect results last night and, with my very limited basic maths, cant understand why it's not working properly. Try putting 0.01 unit size and 31 as the input number, it loses the 1 also 41 loses the 1 Try 25 unit and enter 100 in the input it should return 25 x4 it says 25 x 100 I hope you can figure it out while on coffee break from your kitchen redecorating. Many thanks if you find the time. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 15, 2011 Moderators Share Posted January 15, 2011 Phaser,The redecorating is going fine, thanks. The missing 1 is a rounding problem - look up floating point arithmetic if you want to know more about it. I thought I had removed that problem with the "* 100" trick, but it raised its Hydra-like head again. Just change this line:$nAmount -= Round($aBag_Values[$i] * $aBag_Number[$i] * 100)and you should have it beaten. The second problem is not a problem. You asked for the amount to be the product of the unit and the amount. So why are you surprised when you are told you need 100 x 25-units to fill an order for (100 * 25) = 2500? If you want only 4 x 25-units, then you need to order 100 x 1-units or 4 x 25-units. All clear? 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