3jameo3 Posted June 25, 2014 Posted June 25, 2014 (edited) Ok I have searched and searched for a command to do as I was wanting but i cannot seem to find it, i did find one for commas but mine wont use commas except for Trillions (later). basically to go along with the picture (needs updated) im going to show i need some help finding a way to make each box except Mill stop at 999 and once it goes over 1000... 1 is added to the next box (Right to Left). Basically going:: If ($outputHundredss > 1000) Then $outputHundreds - 1000 And $outputThousands + 1 Until $outputHundreds < 1000 ; This goes for all the outputs except Millions ; Of course though AutoIt doesn't see this as a correct line of code seems logical though If you need the code here it is: expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: 3jameo3 Script Function: Calculator of sorts. Special Thanks to JohnOne, mikell and jdelaney for all the help thus far #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1_1 = GUICreate("Calculator of Sorts", 550, 291, 192, 114) GUISetBkColor(0xFF0000) $Label1 = GUICtrlCreateLabel("Price of Items", 8, 16, 150, 33) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") $Label2 = GUICtrlCreateLabel("Amount Per Bundle", 8, 72, 194, 41) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") $Label3 = GUICtrlCreateLabel("Number of Bundles", 8, 128, 194, 41) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") $Input1 = GUICtrlCreateInput("", 224, 24, 49, 21) $Input2 = GUICtrlCreateInput("", 312, 24, 49, 21) $Input3 = GUICtrlCreateInput("", 400, 24, 49, 21) $Input4 = GUICtrlCreateInput("", 488, 24, 49, 21) $Input5 = GUICtrlCreateInput("", 224, 80, 49, 21) $Input6 = GUICtrlCreateInput("", 224, 136, 49, 21) $Label4 = GUICtrlCreateLabel("Amount Needed", 8, 184, 179, 41) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") $var0 = GUICtrlRead($Input5) $var1 = GUICtrlRead($Input6) $var2 = GUICtrlRead($Input1) $var3 = GUICtrlRead($Input2) $var4 = GUICtrlRead($Input3) $var5 = GUICtrlRead($Input4) $var6 = $var0 * $var1 * $var2 $var7 = $var0 * $var1 * $var3 $var8 = $var0 * $var1 * $var4 $var9 = $var0 * $var1 * $var5 $outputTrillions = GUICtrlCreateInput($var6, 224, 192, 49, 21, BitOR($ES_CENTER, $ES_READONLY), $WS_EX_STATICEDGE) $outputMillions = GUICtrlCreateInput($var7, 312, 192, 49, 21, BitOR($ES_CENTER, $ES_READONLY), $WS_EX_STATICEDGE) $outputThousands = GUICtrlCreateInput($var8, 400, 192, 49, 21, BitOR($ES_CENTER, $ES_READONLY), $WS_EX_STATICEDGE) $outputHundreds = GUICtrlCreateInput($var9, 488, 192, 49, 21, BitOR($ES_CENTER, $ES_READONLY), $WS_EX_STATICEDGE) $Button1 = GUICtrlCreateButton("Calculate Amount Needed", 104, 240, 321, 41) GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0x00FFFF) $Label5 = GUICtrlCreateLabel("Tril", 224, 0, 44, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label6 = GUICtrlCreateLabel("Mill", 312, 0, 37, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label7 = GUICtrlCreateLabel("Thous", 400, 0, 44, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label8 = GUICtrlCreateLabel("Hund", 488, 0, 55, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label9 = GUICtrlCreateLabel("Tril", 224, 216, 44, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label10 = GUICtrlCreateLabel("Mill", 312, 216, 53, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label11 = GUICtrlCreateLabel("Thous", 400, 216, 44, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label12 = GUICtrlCreateLabel("Hund", 488, 216, 55, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) Local $i = 0 Local $msg Do $msg = GUIGetMsg() If ($msg = -3) Then $i = 1 EndIf Select Case ($msg = $Button1) $var0 = GUICtrlRead($Input5) $var1 = GUICtrlRead($Input6) $var2 = GUICtrlRead($Input1) $var3 = GUICtrlRead($Input2) $var4 = GUICtrlRead($Input3) $var5 = GUICtrlRead($Input4) GUICtrlSetData($outputTrillions, $var0 * $var1 * $var2) GUICtrlSetData($outputMillions, $var0 * $var1 * $var3) GUICtrlSetData($outputThousands, $var0 * $var1 * $var4) GUICtrlSetData($outputHundreds, $var0 * $var1 * $var5) EndSelect Until $i = 1 Any help would be greatly appreciated as i cannot find exactly or close to what I am looking for even after searching 50 pages of google with and without site:www.autoitscript.com/ Thanks in advance, 3jameo3 edit: corrected a major error pointed out by jdelaney thanks Edited June 25, 2014 by 3jameo3
jdelaney Posted June 25, 2014 Posted June 25, 2014 Seems that output of 'tens' should only be converted to 'hundreds' if there are 10 or more...not 1000: $outputTens = 101 $outputHundreds = 0 While $outputTens>=10 $outputTens -= 10 $outputHundreds += 1 WEnd ConsoleWrite($outputTens & @CRLF) ConsoleWrite($outputHundreds & @CRLF) IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
3jameo3 Posted June 25, 2014 Author Posted June 25, 2014 Seems that output of 'tens' should only be converted to 'hundreds' if there are 10 or more...not 1000: $outputTens = 101 $outputHundreds = 0 While $outputTens>=10 $outputTens -= 10 $outputHundreds += 1 WEnd ConsoleWrite($outputTens & @CRLF) ConsoleWrite($outputHundreds & @CRLF) to be honest i messed that part up should be in the format of Trillions Millions Thousands Hundreds i have no idea why i put it as Millions Thousands Hundreds Tens. Also that code seems logical but i have no idea where to add it to my script to make it work properly. Its still going over 10 in this case
3jameo3 Posted June 25, 2014 Author Posted June 25, 2014 ok i am really lost sadly besides being a total novice at this i am slowly learning on how to use autoit. at first it seemed like i would just add a func with that script and put the func name into the button and it would automatically do as expected... well that didnt work. so i tried making the while loop come after the endselect still no luck. then i tried to combine the case with with While and no matter the variations ive done it hasnt worked yet. ive also tried putting the while statement above the do statement no results either. so i had an idea and tried this: Local $i = 0 Local $msg While $outputHundreds >= 1000 $outputHundreds -= 1000 $outputThousands += 1 Do $msg = GUIGetMsg() If ($msg = -3) Then $i = 1 EndIf Select Case ($msg = $Button1) GUICtrlSetData($outputHundreds, $var0 * $var1 * $var5) $var0 = GUICtrlRead($Input5) $var1 = GUICtrlRead($Input6) $var5 = GUICtrlRead($Input4) EndSelect Until $i = 1 WEnd and it laughed at me no errors just instant open then close as you can see im attempting to make it work for one rather than all at this present time in order to fully understand what to do for the next ones. as always any input on what i'm doing wrong would be great. i have also looked through http://www.autoitscript.com/autoit3/docs/ under Language Reference to hopefully figure this out on my own but no such luck maybe im looking in the wrong place?
RichardL Posted June 26, 2014 Posted June 26, 2014 It looks like the numbers in the boxes are all part of one big number. So why not use one number as your counter, and display part of it each box? E.g. the number of thousands (without the millions) is Mod(x/1000,1000). To increment x simply add 1, and recalculate the parts for display.
3jameo3 Posted June 27, 2014 Author Posted June 27, 2014 Well i'm working on this calc for a buddy of mine because he sometimes loses track of where he is at while calculating his items for his company thus the reason its separated like this. The Mod param doesn't seem to fit this need unless i'm reading the help file wrong?
RichardL Posted June 27, 2014 Posted June 27, 2014 Much of your code seems to be implementing counting and carrying functions that are already built in to the language. In general it's better to have the data in the simplest form, and reformat in whatever way you want to see it. The code below splits a number into values for display in powers of 1000. Opt("MustDeclareVars", 1) Local $A, $B, $C, $Count, $Msg $Count = 0 While 1 $Count += 1 $A = Mod($Count, 1000) $B = Mod($Count/1000, 1000) $C = Mod($Count/1000000, 1000) $Msg = StringFormat("%03d %03d %03d", $C, $B, $A) ConsoleWrite($Msg & @CRLF) WEnd
3jameo3 Posted June 27, 2014 Author Posted June 27, 2014 Ok i just ran that it seems to be a never ending counting array of numbers, separated which is awesome, but i'm completely lost on how to control such power. That current code will infinitely loop no matter if $count = 0 or not, and im not sure on how to make it stop but also not sure on how to make it at all work for this script, Where all the boxes are completely different inputs and outputs, it seems impossible to do truly. Granting i'm a complete novice at this program and language but to me this doesn't make sense at all. Sorry in advance if i'm causing trouble for you id just like to understand where the help file is beyond useless for this param.
RichardL Posted June 27, 2014 Posted June 27, 2014 (edited) The counting is just making test numbers. A,B,C are the units, thousands, millions. Looking at your code, without understanding the full scheme, you seem to be counting units, thousands, millions etc. and carrying to the next number. Looks easier to me to us a single number and split out the powers of thousands with division and mod. If that doesn't do what you want, or not how you see it, then don't use it. / 'total novice' etc. Just keep trying things. Edited June 27, 2014 by RichardL
3jameo3 Posted June 28, 2014 Author Posted June 28, 2014 in a way i do need a counting number thing in order to separate the units into not going over 1000 but i also need it to do it only if a number goes over 999 and then it stops when the number is below 999 instead of continuing counting the thing is im not sure how to do this. While $outputHundreds >= 1000 $outputHundreds -= 1000 $outputThousands += 1 WEnd the above code would work IF i could figure out where to place it into my script for it to do as instructed your code would most likely would as well if there was a way to stop it and break it down into a format usable by my script.
JohnOne Posted June 28, 2014 Posted June 28, 2014 (edited) Is this anything like you're after? expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Example", 452, 164, 192, 124) $Input1 = GUICtrlCreateInput("", 32, 104, 73, 21) $Input2 = GUICtrlCreateInput("", 136, 104, 73, 21) $Input3 = GUICtrlCreateInput("", 240, 104, 73, 21) $Input4 = GUICtrlCreateInput("", 344, 104, 73, 21) $Input5 = GUICtrlCreateInput("Enter number", 32, 40, 169, 21, $ES_NUMBER) GUICtrlSetLimit(-1, 12) $Button1 = GUICtrlCreateButton("Calc", 344, 40, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _Calc(GUICtrlRead($Input5)) EndSwitch WEnd Func _Calc($sVal) $Len = StringLen($sVal) If $Len Then GUICtrlSetData($Input4, StringRight($sVal, 3)) $sVal = StringTrimRight($sVal, 3) $Len = StringLen($sVal) EndIf If $Len Then GUICtrlSetData($Input3, StringRight($sVal, 3)) $sVal = StringTrimRight($sVal, 3) $Len = StringLen($sVal) EndIf If $Len Then GUICtrlSetData($Input2, StringRight($sVal, 3)) $sVal = StringTrimRight($sVal, 3) $Len = StringLen($sVal) EndIf If $Len Then GUICtrlSetData($Input1, StringRight($sVal, 3)) $sVal = StringTrimRight($sVal, 3) $Len = StringLen($sVal) EndIf EndFunc ;==>_Calc Edited June 28, 2014 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
3jameo3 Posted July 1, 2014 Author Posted July 1, 2014 (edited) pretty much like i was looking for except that its a single input instead of 4 inputs for the numbers alone (trills etc) is there a way to do that or is it just a pipe dream? i do like the format of the outputs though that seems interesting and could be used Also could you explain how that function is working so i can get a better understanding on what it is doing for future reference? sorry for the late reply my internet has been messing up constantly the last few days Edited July 1, 2014 by 3jameo3
JohnOne Posted July 1, 2014 Posted July 1, 2014 (edited) The single input is just an example. As I understand you're not having a problem with calculating the input an what it amounts to. The output is simple, AutoIt is a loosely typed language and it does not care if the variable is a string or a numeric value, it deals with that internally. So I'm taking three digits from the right (tens) then next three (hundreds) etc... Edited July 1, 2014 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
3jameo3 Posted July 6, 2014 Author Posted July 6, 2014 (edited) My failed attempt in reworking your code to make this thing work: expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: 3jameo3 Script Function: Calculator of sorts. Special Thanks to JohnOne, mikell and jdelaney for all the help thus far #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1_1 = GUICreate("Calculator of Sorts", 550, 291, 192, 114) GUISetBkColor(0xFF0000) $Label1 = GUICtrlCreateLabel("Price of Items", 8, 16, 150, 33) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") $Label2 = GUICtrlCreateLabel("Amount Per Bundle", 8, 72, 194, 41) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") $Label3 = GUICtrlCreateLabel("Number of Bundles", 8, 128, 194, 41) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") $Input1 = GUICtrlCreateInput("", 224, 24, 49, 21) $Input2 = GUICtrlCreateInput("", 312, 24, 49, 21) $Input3 = GUICtrlCreateInput("", 400, 24, 49, 21) $Input4 = GUICtrlCreateInput("", 488, 24, 49, 21) $Input5 = GUICtrlCreateInput("", 224, 80, 49, 21) $Input6 = GUICtrlCreateInput("", 224, 136, 49, 21) $Label4 = GUICtrlCreateLabel("Amount Needed", 8, 184, 179, 41) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") $var0 = GUICtrlRead($Input5) $var1 = GUICtrlRead($Input6) $var2 = GUICtrlRead($Input1) $var3 = GUICtrlRead($Input2) $var4 = GUICtrlRead($Input3) $var5 = GUICtrlRead($Input4) $var6 = $var0 * $var1 * $var2 $var7 = $var0 * $var1 * $var3 $var8 = $var0 * $var1 * $var4 $var9 = $var0 * $var1 * $var5 $outputTrillions = GUICtrlCreateInput($var6, 224, 192, 49, 21, BitOR($ES_CENTER, $ES_READONLY), $WS_EX_STATICEDGE) $outputMillions = GUICtrlCreateInput($var7, 312, 192, 49, 21, BitOR($ES_CENTER, $ES_READONLY), $WS_EX_STATICEDGE) $outputThousands = GUICtrlCreateInput($var8, 400, 192, 49, 21, BitOR($ES_CENTER, $ES_READONLY), $WS_EX_STATICEDGE) $outputHundreds = GUICtrlCreateInput($var9, 488, 192, 49, 21, BitOR($ES_CENTER, $ES_READONLY), $WS_EX_STATICEDGE) $Button1 = GUICtrlCreateButton("Calculate Amount Needed", 104, 240, 321, 41) GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0x00FFFF) $Label5 = GUICtrlCreateLabel("Tril", 224, 0, 44, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label6 = GUICtrlCreateLabel("Mill", 312, 0, 37, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label7 = GUICtrlCreateLabel("Thous", 400, 0, 44, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label8 = GUICtrlCreateLabel("Hund", 488, 0, 55, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label9 = GUICtrlCreateLabel("Tril", 224, 216, 44, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label10 = GUICtrlCreateLabel("Mill", 312, 216, 53, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label11 = GUICtrlCreateLabel("Thous", 400, 216, 44, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label12 = GUICtrlCreateLabel("Hund", 488, 216, 55, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _Calc(GUICtrlRead($Input4)) _Calc1(GUICtrlRead($Input3)) _Calc2(GUICtrlRead($Input2)) _Calc3(GUICtrlRead($Input1)) EndSwitch WEnd Func _Calc($sVal) $Len = StringLen($sVal) If $Len Then GUICtrlSetData($outputHundreds, $var0 * $var1 * $var5, StringRight($sVal, 3)) $sVal = StringTrimRight($sVal, 3) $Len = StringLen($sVal) EndIf If $Len Then GUICtrlSetData($outputThousands, $outputThousands + 1, StringRight($sVal, 3)) $sVal = StringTrimRight($sVal, 3) $Len = StringLen($sVal) EndIf If $Len Then GUICtrlSetData($outputMillions, $outputMillions + 1, StringRight($sVal, 3)) $sVal = StringTrimRight($sVal, 3) $Len = StringLen($sVal) EndIf If $Len Then GUICtrlSetData($outputTrillions, $outputTrillions + 1, StringRight($sVal, 3)) $sVal = StringTrimRight($sVal, 3) $Len = StringLen($sVal) EndIf EndFunc ;==>_Calc Func _Calc1($sVal) $Len = StringLen($sVal) If $Len Then GUICtrlSetData($outputThousands, $var0 * $var1 * $var4, StringRight($sVal, 3)) $sVal = StringTrimRight($sVal, 3) $Len = StringLen($sVal) EndIf If $Len Then GUICtrlSetData($outputMillions, $outputMillions + 1, StringRight($sVal, 3)) $sVal = StringTrimRight($sVal, 3) $Len = StringLen($sVal) EndIf If $Len Then GUICtrlSetData($outputTrillions, $outputTrillions + 1, StringRight($sVal, 3)) $sVal = StringTrimRight($sVal, 3) $Len = StringLen($sVal) EndIf EndFunc ;==>_Calc1 Func _Calc2($sVal) $Len = StringLen($sVal) If $Len Then GUICtrlSetData($outputMillions, $var0 * $var1 * $var3, StringRight($sVal, 3)) $sVal = StringTrimRight($sVal, 3) $Len = StringLen($sVal) EndIf If $Len Then GUICtrlSetData($outputTrillions, $outputTrillions + 1, StringRight($sVal, 3)) $sVal = StringTrimRight($sVal, 3) $Len = StringLen($sVal) EndIf EndFunc ;==>_Calc2 Func _Calc3($sVal) $Len = StringLen($sVal) If $Len Then GUICtrlSetData($outputTrillions, $var0 * $var1 * $var2, StringRight($sVal, 3)) $sVal = StringTrimRight($sVal, 3) $Len = StringLen($sVal) EndIf EndFunc ;==>_Calc3 please let me know what i am doing completely wrong i know its something as all i get are alot of 0's. in my head it seemed to work but well i guess my head isnt as smart as this program lol Edited July 6, 2014 by 3jameo3
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