Jump to content

Made a complicated function which already exists in AutoIt :(


Recommended Posts

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):

MsgBox(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 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

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

@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 :P

 

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

  • Developers

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

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 useful

What 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

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

  • Developers

Oh no, I wanted to post the code, maybe someone can find my work useful

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 :)

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

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

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...