Skip to main content

Notifications

Community site session details
Power Automate - Power Automate Desktop
Answered

Using power automate desktop variables in VBScript

Like (1) ShareShare
ReportReport
Posted on 6 Aug 2024 11:45:58 by 25
Hello!
I'm trying to write a VB script that will use a variable initialized within a flow. My variable is a list of numeric elements (%List%). I want the script to check if a given value in the %List% is less than 0 and if so, to save its position as a result. If the next value meets the same condition, its position in the list is to be appended to the result after the decimal point. Unfortunately, I run into a problem - I can't use the %List% variable. Depending on the way I try to use it, I get compilation errors. An example of a script I tried to use:
 

Dim list
list = Split(%List%, ",")
Dim result
result = ""
For i = 0 To UBound(list)

    If CInt(list(i)) < 0 Then

        If result = "" Then

            result = i

        Else

            result = result & "," & i

        End If

    End If

Next

WScript.Echo result
 
I will be very grateful for any help!
Best regards!
Iza
Categories:
  • Verified answer
    NathanAlvares24 Profile Picture
    1,673 Super User 2025 Season 1 on 07 Aug 2024 at 10:29:45
    Using power automate desktop variables in VBScript
     
    The List variable in PAD (Power Automate Desktop) is completely different than what an actual List used in scripting languages.
     
    See this example:
     
    Output of "Display message" action:
    As can be seen it is not like the list in scripting languages. A list in scripting languages usually has a ","(comma) as a delimiter.
     
    So you need this into one whole text. Use the "Join text" action to achieve this. See below:
     
     
    Output:
    As can be seen above, I get the list as one whole text and delimited by a comma.
     
    Then pass this variable to your script. I made some changes to the script, so use this one:
    ' Initialize the list with the actual Power Automate variable
    Dim list
    list = Split("%List%", ",") ' %List% should be a string like "1,2,-3,4,-5"
    
    ' Initialize the result variable
    Dim result
    result = ""
    
    ' Iterate through the list and check for negative values
    For i = 0 To UBound(list)
        If CInt(list(i)) < 0 Then
            If result = "" Then
                result = i
            Else
                result = result & "." & i
            End If
        End If
    Next
    
    ' Output the result
    WScript.Echo result
     
    Then finally your flow will look like this (just for reference):
     
    We have to use the "Trim text" action, since in PAD, the scripting languages give output as one extra line.
     
    Output:
     
    Flow (directly copy the code and paste onto your flow):
    Variables.CreateNewList List=> List
    Variables.AddItemToList Item: 1 List: List
    Variables.AddItemToList Item: 2 List: List
    Variables.AddItemToList Item: -3 List: List
    Variables.AddItemToList Item: 4 List: List
    Variables.AddItemToList Item: -5 List: List
    Text.JoinText.JoinWithCustomDelimiter List: List CustomDelimiter: $''',''' Result=> List
    @@copilotGeneratedAction: 'False'
    Scripting.RunVBScript.RunVBScript VBScriptCode: $'''\' Initialize the list with the actual Power Automate variable
    Dim list
    list = Split(\"%List%\", \",\") \' %List% should be a string like \"1,2,-3,4,-5\"
    
    \' Initialize the result variable
    Dim result
    result = \"\"
    
    \' Iterate through the list and check for negative values
    For i = 0 To UBound(list)
        If CInt(list(i)) < 0 Then
            If result = \"\" Then
                result = i
            Else
                result = result & \".\" & i
            End If
        End If
    Next
    
    \' Output the result
    WScript.Echo result
    ''' ScriptOutput=> VBScriptOutput ScriptError=> ScriptError
    Text.Trim Text: VBScriptOutput TrimOption: Text.TrimOption.Both TrimmedText=> VBScriptOutput
     
    I hope this helps.
     
    Regards,
    Nathan Alvares

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Power Automate Desktop

#1
eetuRobo Profile Picture

eetuRobo 20 Super User 2025 Season 1

#2
Nived_Nambiar Profile Picture

Nived_Nambiar 14 Super User 2025 Season 1

#3
stampcoin Profile Picture

stampcoin 6

Overall leaderboard
Loading started
Loading started