web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / URGENT ATTENTION ! How...
Power Automate
Unanswered

URGENT ATTENTION ! How I output value of vbscript action in PAD?

(0) ShareShare
ReportReport
Posted on by 357

Hi Team,
I am vb script action which reads the json file and extract the numbers from it.
and store it in an array then finding largest number from that array.

now i want to output this value in my desktop variable. 

Also I am passing the json file path via desktop variable.
set variable LargestNum.

here is my script 

' Create a FileSystemObject
Set fs = CreateObject("Scripting.FileSystemObject")

' Define the path to your JSON file
Dim filePath
filePath = %JsonFilePath%  ' Replace with your actual file path

' Array to store extracted numbers
Dim numbers()
ReDim numbers(-1)

' Check if the file exists
If fs.FileExists(filePath) Then
    ' Read JSON content from the file
    Dim jsonContent
    Set file = fs.OpenTextFile(filePath, 1) ' 1: ForReading
    jsonContent = file.ReadAll()
    file.Close
    
    ' Regular expression pattern to extract all numbers followed by a colon
    Dim regexPattern
    regexPattern = """(\d+)""\s*:"
    
    ' Create a RegExp object
    Dim regex
    Set regex = New RegExp
    
    ' Set properties for the RegExp object
    regex.Global = True ' Match all occurrences
    regex.IgnoreCase = True
    regex.MultiLine = True
    regex.Pattern = regexPattern
    
    ' Execute the regular expression on the JSON string
    Dim matches
    Set matches = regex.Execute(jsonContent)
    
    ' Check if matches are found
    If matches.Count > 0 Then
        ' Resize the array to hold all matches
        ReDim numbers(matches.Count - 1)
        
        ' Iterate over each match
        For i = 0 To matches.Count - 1
            ' Extract the matched number (from the first capturing group)
            numbers(i) = CInt(matches(i).SubMatches(0)) ' Convert to integer
        Next
        
        ' Find the largest number in the array
        Dim largestNumber
        largestNumber = numbers(0) ' Initialize with the first element
        
        For i = 1 To UBound(numbers)
            If numbers(i) > largestNumber Then
                largestNumber = numbers(i)
            End If
        Next
        
        ' Print the largest number found
        WScript.Echo "Largest number: " & largestNumber
        %LargestNumber% = largestNumber
    Else
        WScript.Echo "No numbers followed by colon found in the JSON."
    End If
Else
    WScript.Echo "File not found: " & filePath
End If

Please correct it .
Thanks in advance!!!






I have the same question (0)
  • Verified answer
    eetuRobo Profile Picture
    4,204 Super User 2025 Season 2 on at

    I think your line 61 is incorrect: %LargestNumber% = largestNumber
    You cant set PAD variable inside vbscript. You only use WScript.Echo to output values from VBscript. Then you can use trim, split, replace or just set variable in PAD after vbscript has outputted some values.
    So something like this:

    eetuRobo_7-1718731859213.png

     

    eetuRobo_5-1718731666733.png

     

    So if Larges number is found and its 98 VBScriptOutputs is: "Largest number: 98"
    if no numbers followed by colon is found it will produce this:

    eetuRobo_6-1718731769556.png
    Also you might need to have double quotes around filepath variable (or have the double quotes in the JsonFilePath variable around the file path):

    eetuRobo_0-1718731204079.png

     

    Tip:
    In your VBscript action have ScriptError variable enabled so it produces info on error:

    eetuRobo_1-1718731331815.png

    Then if it gives some text it should look something like this:

    eetuRobo_2-1718731429578.png

    That means that in row 6 there is error (so in my try it was file path not correct form).

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard