TheDcoder Posted June 27, 2015 Share Posted June 27, 2015 (edited) Hello , I am very sad today ... I (half) made a complicated function which already exists in AutoIt... I call it CalcStringExp (Calculates math expression which are enclosed in strings [or which are in a string variant]) which is a clone of Execute. Here is the source code if you wish to see it (its not fully complete):expandcollapse popupMsgBox(0, 0, CalcStringExp('$VAR1 + $VAR2', '$VAR1 = 1, $VAR2 = 2')) Func CalcStringExp($sStringExp, $sVariables) $sVariables = StringStripWS($sVariables, 8) ; Remove any spaces $sStringExp = StringStripWS($sStringExp, 8) ; Remove any spaces $bSolved = False If $sVariables = "" Then Local $aVariables[1] = [0] Else $aVariables = StringSplit($sVariables, ',') EndIf For $i = 1 To $aVariables[0] $aTempArray = StringSplit($aVariables[$i], '=') $sStringExp = StringReplace($sStringExp, $aTempArray[1], $aTempArray[2], 0, 2) Next $sOperatersPresent = "" If Not StringInStr($sStringExp, '^', 2) = 0 Then $sOperatersPresent &= '^' If Not StringInStr($sStringExp, '*', 2) = 0 Then $sOperatersPresent &= '*' If Not StringInStr($sStringExp, '/', 2) = 0 Then $sOperatersPresent &= '/' If Not StringInStr($sStringExp, '+', 2) = 0 Then $sOperatersPresent &= '+' If Not StringInStr($sStringExp, '-', 2) = 0 Then $sOperatersPresent &= '-' If $sOperatersPresent = "" Then $bSolved = True $sTempString = $sStringExp While $bSolved = False $sNum1 = Number($sTempString) $iTempStringLen = StringLen($iNum1) $sTempString = StringTrimLeft($sTempString, $iTempStringLen) $sOperator = StringLeft($sTempString, 1) $sTempString = StringTrimLeft($sTempString, 1) If $sOperator = "" Or $iNum1 = 0 Or $iNum2 = 0 Then $bSolved = True $sStringExp = $sTempString EndIf Switch WEnd Return $sStringExp EndFunc Lesson Learnt: Always search the help file as many times as possible before committing to anything! (like asking a question or making a function) TD P.S This thread was lost in yesterday's upgrade, so I re-posted it (that mean today = yesterday!) Edited June 27, 2015 by TheDcoder Added (AutoIt) code tags EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
guinness Posted June 27, 2015 Share Posted June 27, 2015 Still room for improvement by the looks of things. Perhaps add appropriate comments and remove the use of magic numbers (do a search for it) would be a good place to improve your coding skills 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 Link to comment Share on other sites More sharing options...
TheDcoder Posted June 27, 2015 Author Share Posted June 27, 2015 @guinness Its discontinued now... I made it for my Magic Number Calculator , I was gonna replace magic numbers with constants until I found the execute function TD EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Developers Jos Posted June 27, 2015 Developers Share Posted June 27, 2015 What is this thread doing in the dev forum?maybe you should simply refrain from posting this stuff as it feels you merely are seeking attention.jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
TheDcoder Posted June 27, 2015 Author Share Posted June 27, 2015 maybe you should simply refrain from posting this stuff as it feels you merely are seeking attention.Oh no, I wanted to post the code, maybe someone can find my work usefulWhat is this thread doing in the dev forum?It has code in it, so I think it would fit in dev forum, . But if you feel like moving it to example script, do it! I don't have any objections TD EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
James Posted June 27, 2015 Share Posted June 27, 2015 Dev isn't really related to AutoIt code itself, that's Examples. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
TheDcoder Posted June 27, 2015 Author Share Posted June 27, 2015 @James Oh, Sorry, I didn't noticed that EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Guest Posted June 27, 2015 Share Posted June 27, 2015 I don't thing that you wasted your time.I also made few functions which already exist in Autoit such as Array2DSearch but I know that even if I didn't have to develop these functions, it is still not wasted time because that's how you develop "programing thinking" ability. If you will keep doing it a lot then you may come to a state that when it is about simple functions - it is faster to develop then then find then in the help file.If you will only based on the help file (In a way that you don't create new functions) then this is bad thing. But I see that this sentence is unnecessary for you because you know it. Link to comment Share on other sites More sharing options...
James Posted June 27, 2015 Share Posted June 27, 2015 Also, no, you didn't waste your time.It's good practise to re-implement a function without looking at the source. You may come up with a better implementation. czardas 1 Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
TheDcoder Posted June 27, 2015 Author Share Posted June 27, 2015 Thanks! EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Developers Jos Posted June 27, 2015 Developers Share Posted June 27, 2015 Oh no, I wanted to post the code, maybe someone can find my work usefulIt has code in it, so I think it would fit in dev forum, . But if you feel like moving it to example script, do it! I don't have any objections TD My friend, let me tell something essential; When people write a post like I did it isn't really open for debate but merely a friendly way of telling you something.So there is no need to respond but just listen to what was said.Hope I made myself more clear this time.Jos TheDcoder 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts