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 / Writing VB.NET functio...
Power Automate
Answered

Writing VB.NET functions using "run .net script" action

(4) ShareShare
ReportReport
Posted on by 22
Hi all,
 
Can someone give me an example of how to write and run any simple user-defined functions using VB.net in the "run .net script" action please?
 
Something I've tried but doesn't work is:
----------
Public Function EchoInput(input As String) As String
    Return input
End Function
 
sOutput = EchoInput("hello world")
----------
 
This is where sOutput is an out parameter of type string defined in the action.
 
The error I received is talking about "end sub is expected"..
 
Can someone try this, explain what is wrong and how to make this work in the expected way?
 
Thanks so much!
I have the same question (0)
  • Suggested answer
    trice602 Profile Picture
    15,404 Super User 2025 Season 2 on at
    Hi,
     
    Try this one.
     
    ' Define a function that returns "Hello, World!"
    Function GetHelloWorld() As String
        Return "Hello, World!"
    End Function
    
    ' Call the function and store the result in the output variable
    Dim result As String
    result = GetHelloWorld()
    
    ' Store the result in the output dictionary
    Output("result") = result
    
     
     
    ------------------------------------------------


    If this was helpful, please like and/or mark as a verified answer to help others find this too!


    Always glad to help! 💯💯💯💯💯

    Tom 

    Follow me on LinkedIn - Thomas Rice, PMP | LinkedIn

     

     
  • CU15081355-0 Profile Picture
    22 on at
    @trice602 

    ​​​​​​​
    Hi, thanks for the reply, but I believe you didn't try to run your code in PAD.
    Lets simplify what you gave, I will just define a function, I won't even call the function.

    ' Define a function that returns "Hello, World!"
    Function GetHelloWorld() As String
        Return "Hello, World!"
    End Function



    And I get the following error when I run it:
    'End Sub' expected., Statement cannot appear within a method body. End of method assumed., Compilation error found, in .NET script line:3: 'End Sub' must be preceded by a matching 'Sub'

    ​​​​​​​
  • Suggested answer
    eetuRobo Profile Picture
    4,204 Super User 2025 Season 2 on at
    I don't know why running functions does not seem to work in the VB.NET language in Power Automate Desktop. Seems to work just fine if you don't use any functions. 
     
    Do you need to specifically run functions in the VB.NET -action or could you do without?

    Result:
     
     
    One not clean way you could use it would be to save the functions in .vb file that you run from PowerShell script. But then if I am not mistaken it needs to be made into a project or executable file. 
    Make it to a project with PowerShell script:

    Run the vb program:
     
    You could even have the PAD write the vb.net script:


    After running the flow:
  • Verified answer
    CU15081355-0 Profile Picture
    22 on at
    Thanks for confirming that it doesn't work for you.  The workaround you mentioned is something I did think of already but thought user-defined functions should just work.  I would use them to keep my code neat and easy to read.  Sometimes you might even want to do some recursion, you never know!
     
    I'll just write everything in-line for now.  Boo Microsoft.

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 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard