MikahS Posted August 7, 2014 Posted August 7, 2014 @JLogan3o13 currently trying to figure that out , but thank you for the kind words Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
Moderators JLogan3o13 Posted August 7, 2014 Moderators Posted August 7, 2014 No, problem. Something like this may point you in the right direction: $WMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\wmi") $aClasses = $WMI.SubclassesOf() For $class In $aClasses If StringInStr($class.Path_.Path, "thermalzonetemp") Then ConsoleWrite($class.Path_.Path & @CRLF) Next "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
MikahS Posted August 8, 2014 Posted August 8, 2014 @JLogan3o13 That is exactly what I was looking for, thanks for the push See my OP for update. Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
Guest Posted August 15, 2014 Posted August 15, 2014 (edited) Hello,I wrote a function that detects whether a message is pure spam .The function returns the correct answer in most cases. expandcollapse popup#include <Array.au3> $test = FileRead(@ScriptDir&"\test.txt") $Output = SpamDetector($test) ConsoleWrite($Output & @CRLF) ; 1 = Spam , 0 = No Spam Func SpamDetector($Text) Local $Output = 0 , $tmp , $tmp2 , $tmp3 , $aTmp2[1][2] , $aTmp[1] $aTmp[0] = 0 $aTmp2[0][0] = 0 $tmp = StringSplit($Text,@CRLF,1) For $a = 1 To $tmp[0] $tmp2 = StringSplit($tmp[$a]," ",1) For $a2 = 1 To $tmp2[0] If $tmp2[$a2] = "" Then ContinueLoop $tmp3 = Array2DSearch($aTmp2,$tmp2[$a2],0) If $tmp3 <= 0 Then $aTmp2[0][0] += 1 ReDim $aTmp2[$aTmp2[0][0]+1][2] $aTmp2[$aTmp2[0][0]][0] = $tmp2[$a2] $aTmp2[$aTmp2[0][0]][1] = 1 Else $aTmp2[$tmp3][1] += 1 EndIf Next Next ;~ _ArrayDisplay($aTmp2) $tmp = 0 For $a = 1 To $aTmp2[0][0] If $aTmp2[$a][1] > 3 Or StringLen($aTmp2[$a][0]) > 10 Then $tmp += 1 ; Count all the words that written more than 3 times or with more then 10 characters Next If $tmp/$aTmp2[0][0] > 0.70 Then $Output = 1 ; If more then 70% words are written more than 3 times then this is means that the message is very likely spam Return $Output EndFunc ; ________________________________________________________________________________________________________________________________________ Func Array2DSearch($aArray,$String,$Dimension,$StartIndex = 1,$EndIndex = "") Local $Output = -1 , $a ;If IsArray($aArray) Then ; Local $a If $EndIndex = "" Then $EndIndex = UBound($aArray)-1 If $StartIndex >= 0 And $StartIndex <= $EndIndex Then For $a = $StartIndex To $EndIndex If $aArray[$a][$Dimension] = $String Then $Output = $a ExitLoop EndIf Next EndIf ;EndIf Return $Output EndFunc Edited August 15, 2014 by Guest
JohnOne Posted August 15, 2014 Posted August 15, 2014 Do you know what spam means? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Guest Posted August 15, 2014 Posted August 15, 2014 (edited) When I say i "pure spam", I means to something like this: blabla blabla blabla blabla blabla blabla blabla blabla blabla Test Test Test Test Test Test Test Test Test Test Test xxxxxxxxxxxxxxxxxxxxxxx This is the kind of spam/text that my function can identify as a junk message. but my function can't identify a smart spam.. I mean, my function can not identify Message that speaks bullshit as junk message Edited August 15, 2014 by Guest
jchd Posted August 15, 2014 Posted August 15, 2014 Isn't this approach clearly inferior to the bayesian + keywords + other rules filter that comes with essentially every mail client? 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 hereRegExp tutorial: enough to get startedPCRE 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)
Guest Posted August 15, 2014 Posted August 15, 2014 Isn't this approach clearly inferior to the bayesian + keywords + other rules filter that comes with essentially every mail client? I have not checked thoroughly my mail client.. But anyway, every message that sent to my client cost me place for another message.. I can get up to X messags per month. So i want to block the ability to send the message in my program when the message is "spam" in order to save space for messages(that i can receive each month) I hope you understand
jchd Posted August 15, 2014 Posted August 15, 2014 I do understand: I receive an average of 650 messages a day and I heavily rely on spam filtering. I only have 1-2 false positives per month and no false negative in the last 10 years. 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 hereRegExp tutorial: enough to get startedPCRE 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)
ResNullius Posted August 16, 2014 Posted August 16, 2014 Simplified (?) version of a function originally posted by guinness @ Improvements (?): Does not require Date.au3 include and Date string can be passed with or without separators ConsoleWrite(_IsDateOrAboveEx(@YEAR & "/" & @MON & '/' & @MDAY-3) & @CRLF) ; Returns False ConsoleWrite(_IsDateOrAboveEx(@YEAR & @MON & @MDAY+1) & @CRLF) ; Returns True Func _IsDateOrAboveEx($sDateString) ;Check if a date is equal to/or has passed the current date. ;Pass the string as YYYYMMDD, with or without separators e.g. 20140815 or 2014/08/15, or 2014-08-15, or 2014.08.15 ;Original concept by guinness http://www.autoitscript.com/forum/topic/139260-autoit-snippets/#entry1005153 Return Number(StringRegExpReplace($sDateString, "\D|$", "")) >= NUMBER(@YEAR & @MON & @MDAY) EndFunc JScript 1
JScript Posted September 7, 2014 Posted September 7, 2014 (edited) @ResNulliusYeah, sure, it makes more sense to me because I always thought the "snippets" should not have includes ...I also noticed that here is a little slow, I posted several snippets that are still here: http://www.autoitscript.com/forum/index.php?app=core&module=search&do=search&fromMainBar=1JS Edited September 7, 2014 by JScript http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere!
mLipok Posted September 26, 2014 Posted September 26, 2014 expandcollapse popupMsgBox(0, '', _WinIsMinimized('Bez tytułu')) MsgBox(0, '', _WinIsActive('Total')) MsgBox(0, '', _WinIsInactive('Total')) Func _WinIsVisible($vTitle, $sText = '') Return BitAND(WinGetState($vTitle, $sText), 2) <> 0 EndFunc ;==>_WinIsVisible Func _WinIsHidden($vTitle, $sText = '') Return BitAND(WinGetState($vTitle, $sText), 2) = 0 EndFunc ;==>_WinIsHidden Func _WinIsEnabled($vTitle, $sText = '') Return BitAND(WinGetState($vTitle, $sText), 4) <> 0 EndFunc ;==>_WinIsEnabled Func _WinIsDisabled($vTitle, $sText = '') Return BitAND(WinGetState($vTitle, $sText), 4) = 0 EndFunc ;==>_WinIsDisabled Func _WinIsActive($vTitle, $sText = '') Return BitAND(WinGetState($vTitle, $sText), 8) <> 0 EndFunc ;==>_WinIsActive Func _WinIsInactive($vTitle, $sText = '') Return BitAND(WinGetState($vTitle, $sText), 8) = 0 EndFunc ;==>_WinIsInactive Func _WinIsMinimized($vTitle, $sText = '') Return BitAND(WinGetState($vTitle, $sText), 16) <> 0 EndFunc ;==>_WinIsMinimized Func _WinIsNotMinimized($vTitle, $sText = '') Return BitAND(WinGetState($vTitle, $sText), 16) = 0 EndFunc ;==>_WinIsNotMinimized Func _WinIsMaximized($vTitle, $sText = '') Return BitAND(WinGetState($vTitle, $sText), 32) <> 0 EndFunc ;==>_WinIsMaximized Func _WinIsNotMaximized($vTitle, $sText = '') Return BitAND(WinGetState($vTitle, $sText), 32) = 0 EndFunc ;==>_WinIsNotMaximized Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
mLipok Posted October 10, 2014 Posted October 10, 2014 Thanks to @JLogan3o13 Originally posted here. #include <Array.au3> #include <File.au3> _UnPinFromTaskBar("Windows Explorer") Func _UnPinFromTaskBar($sNameToUnPin) Local $Folder = @AppDataDir & "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar" Local $aArray = _FileListToArray($Folder, "*.lnk", Default, True) For $sFile In $aArray If StringInStr($sFile, "Windows Explorer""Windows Explorer") Then FileDelete($sFile) EndIf Next EndFunc ;==>_UnpinFromTaskBar Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
Moderators JLogan3o13 Posted October 11, 2014 Moderators Posted October 11, 2014 Thanks to @JLogan3o13 Originally posted here. #include <Array.au3> #include <File.au3> _UnPinFromTaskBar("Windows Explorer") Func _UnPinFromTaskBar($sNameToUnPin) Local $Folder = @AppDataDir & "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar" Local $aArray = _FileListToArray($Folder, "*.lnk", Default, True) For $sFile In $aArray If StringInStr($sFile, "Windows Explorer""Windows Explorer") Then FileDelete($sFile) EndIf Next EndFunc ;==>_UnpinFromTaskBar Not sure that is worth being here. It was a suggestion to delete rather than truly unpin an icon from the taskbar, and wasn't a tested solution. Depending on the OS, it may well leave a blank icon behind on the taskbar when you delete the file. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Morthawt Posted October 13, 2014 Posted October 13, 2014 here is a snippet of code I wrote to do mathematical mean averaging. I am not sure how this implementation compares to how other people would write it, but here is how I did it: Func MeanAverage($_NumberInput = Default) Local Static $_results[0] Local $_temp, $_return If IsNumber($_NumberInput) Then ReDim $_results[UBound($_results) + 1] $_results[UBound($_results) - 1] = $_NumberInput Else If Not UBound($_results) Then Return SetError(1, 0, '') For $_a = 0 To UBound($_results) - 1 $_temp += $_results[$_a] Next $_return = $_temp / UBound($_results) ReDim $_results[0] Return $_return EndIf EndFunc ;==>MeanAverage How you use it is you plug numbers into it one per call and when done call it without parameters: MeanAverage(8) MeanAverage(4) MeanAverage(23.5) MeanAverage(7) $average1 = MeanAverage() MeanAverage(150) MeanAverage(50) $average2 = MeanAverage() ConsoleWrite('First average: ' & $average1 & @LF & 'Second average: ' & $average2 & @LF) I would be interested what you think to this implementation and if you have a better way of doing it I would be interested in seeing it. Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials.
guinness Posted October 13, 2014 Posted October 13, 2014 What if a user wants to reset the "internal" array? UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
Morthawt Posted October 13, 2014 Posted October 13, 2014 What if a user wants to reset the "internal" array? If nothing was typed, the array will have 0 elements already. If there was a number, when it is called without a parameter it will wipe the array back to 0 elements and offer the original number back as the return. So calling it without a parameter serves both functions. Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials.
guinness Posted October 13, 2014 Posted October 13, 2014 expandcollapse popupGlobal Const $MEANAVERAGE_GUID = '1AF3DE1C-7227-427D-B06C-6144336EA201' Global Enum $MEANAVERAGE_COUNTER, $MEANAVERAGE_ID, $MEANAVERAGE_SUM, $MEANAVERAGE_MAX Example() ; Do you like object orientated programming? I do, so here is the same example but with an OOP-like approach. Func Example() Local $hMean ; Create a variable to hold our "object". $hMean = MeanAverage() MeanAverage_Add($hMean, 8) MeanAverage_Add($hMean, 4) MeanAverage_Add($hMean, 23.5) MeanAverage_Add($hMean, 7) Local $iAverage_1 = MeanAverage_Get($hMean) MeanAverage_Destroy($hMean) ; Destroy the "object". $hMean = MeanAverage() MeanAverage_Add($hMean, 150) MeanAverage_Add($hMean, 50) Local $iAverage_2 = MeanAverage_Get($hMean) MeanAverage_Destroy($hMean) ; Destroy the "object". ConsoleWrite('First average: ' & $iAverage_1 & @CRLF & 'Second average: ' & $iAverage_2 & @CRLF) EndFunc ;==>Example Func MeanAverage() Local $aMeanAverage[$MEANAVERAGE_MAX] $aMeanAverage[$MEANAVERAGE_COUNTER] = 0 $aMeanAverage[$MEANAVERAGE_ID] = $MEANAVERAGE_GUID $aMeanAverage[$MEANAVERAGE_SUM] = 0 Return $aMeanAverage EndFunc ;==>MeanAverage Func MeanAverage_Add(ByRef $aMeanAverage, $iNumber) Local $bReturn = False If __MeanAverage_IsAPI($aMeanAverage) And IsNumber($iNumber) Then $aMeanAverage[$MEANAVERAGE_COUNTER] += 1 ; Increase the counter. $aMeanAverage[$MEANAVERAGE_SUM] += $iNumber ; Increase the sum value $bReturn = True EndIf Return $bReturn EndFunc ;==>MeanAverage_Add Func MeanAverage_Destroy(ByRef $aMeanAverage) Local $bReturn = False If __MeanAverage_IsAPI($aMeanAverage) And IsNumber($iNumber) Then $aMeanAverage = 0 $bReturn = True EndIf Return $bReturn EndFunc ;==>MeanAverage_Destroy Func MeanAverage_Get(ByRef $aMeanAverage) Local $iMeanValue = Null If __MeanAverage_IsAPI($aMeanAverage) Then $iMeanValue = $aMeanAverage[$MEANAVERAGE_SUM] / $aMeanAverage[$MEANAVERAGE_COUNTER] ; Determine the mean value. EndIf Return $iMeanValue EndFunc ;==>MeanAverage_Get Func __MeanAverage_IsAPI(ByRef $aMeanAverage) Return UBound($aMeanAverage) = $MEANAVERAGE_MAX And $aMeanAverage[$MEANAVERAGE_ID] = $MEANAVERAGE_GUID EndFunc ;==>__MeanAverage_IsAPI UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
Morthawt Posted October 13, 2014 Posted October 13, 2014 (edited) What on earth?... I do not understand any of that code at all. What are the benefits to all that code over the code I wrote? Edited October 13, 2014 by Morthawt Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials.
jaberwacky Posted October 14, 2014 Posted October 14, 2014 Neat snippets! Here is my try: ConsoleWrite(Average(1) & @CRLF) ConsoleWrite(Average(2) & @CRLF) ConsoleWrite(Average(3) & @CRLF) ConsoleWrite(Average(4) & @CRLF) ConsoleWrite(Average(5) & @CRLF) ConsoleWrite(Average(6) & @CRLF) ConsoleWrite(Average(7) & @CRLF) ConsoleWrite(Average(8) & @CRLF) ConsoleWrite(Average(9) & @CRLF) ConsoleWrite(Average(10) & @CRLF) Average() ConsoleWrite(Average(150) & @CRLF) ConsoleWrite(Average(50) & @CRLF) Func Average(Const $number = Default) Local Static $counter = 0 Local Static $count = 0 If $number = Default Then $counter = 0 $count = 0 Return EndIf $counter += $number $count += 1 Return $counter / $count EndFunc Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
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