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

Announcements

News and Announcements icon
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
    16,244 Super User 2026 Season 1 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,543 Super User 2026 Season 1 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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 464

#2
Haque Profile Picture

Haque 416

#3
David_MA Profile Picture

David_MA 323 Super User 2026 Season 1

Last 30 days Overall leaderboard