Jump to content

Using a String as Expression


Go to solution Solved by IUtilizeScripts,

Recommended Posts

Hello,

I'm having difficulty understanding how to evaluate as String as a Boolean expression in an IF statement. Will one of you please assist me in accomplishing this?

Here is the code I have so far:

#include <Array.au3>

Local $aTest[5] = [1,2,3,4,5]
Local $iLimit = 3
Local $sCriteria = "$avArray[$i] >" & $iLimit

_ArrayDisplay($aTest)
$aTest = CondenseArray($aTest, $sCriteria)
_ArrayDisplay($aTest)


Func CondenseArray($avArray, $sCriteria)
   Local $Keep[UBound($avArray)]
   Local $HitNo = 0
   For $i = 0 to Ubound($avArray) - 1 Step 1
      If $sCriteria Then
         $Keep[$HitNo] = $i
         $HitNo = $HitNo + 1
      EndIf
   Next
   ReDim $Keep[$HitNo]
   Local $avRevisedArray[UBound($Keep)]
   
   If UBound($avArray, 0) = 1 Then
      For $row = 0 to Ubound($Keep, 1) - 1
         $avRevisedArray[$row] = $avArray[$Keep[$row]]
      Next
   EndIf
   Return $avRevisedArray  
EndFunc

Thank you.

Edited by IUtilizeScripts
Link to comment
Share on other sites

  • Solution

Hi,

You're talking about evaluation, but I don't see the Eval function anywhere.

Br, FireFox.

 

Thanks for the help! I didn't know that the Eval or Execute functions existed.

The solution was the Execute function:

#include <Array.au3>

Local $aTest[5] = [1,2,3,4,5]
Local $iLimit = 3
Local $sCriteria = "$avArray[$i] >" & $iLimit
_ArrayDisplay($aTest)
$aTest = CondenseArray($aTest, $sCriteria)
_ArrayDisplay($aTest)


Func CondenseArray($avArray, $sCriteria)
   Local $Keep[UBound($avArray)]
   Local $HitNo = 0
   For $i = 0 to Ubound($avArray) - 1 Step 1
      If Execute($sCriteria) Then
         $Keep[$HitNo] = $i
         $HitNo = $HitNo + 1
      EndIf
   Next
   ReDim $Keep[$HitNo]
   Local $avRevisedArray[UBound($Keep)]
   
   If UBound($avArray, 0) = 1 Then
      For $row = 0 to Ubound($Keep, 1) - 1
         $avRevisedArray[$row] = $avArray[$Keep[$row]]
      Next
   EndIf
   Return $avRevisedArray  
EndFunc
Edited by IUtilizeScripts
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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