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!!!

Report
All responses (
Answers (