Q:

Public Function Return VB.Net

I am starting to think more about using Functions to prevent me from writing the same code over and over but the more I read about them the more confused I am getting.
Here is a function I have placed inside a Module which basically gets the path to a folder under the AppData Local folder for the current User.
Public Function AppDataLocal() As String
    
    Dim AppData As String() = {GetFolderPath(SpecialFolder.LocalApplicationData), "MyApp"}
    Dim AppDataFullpath As String = Path.Combine(AppData)
    Return AppDataFullpath

End Function

Anytime I want find the path I am calling the function like this.
MsgBox(AppDataLocal)

Everything appears to be working but I would like to know if I am doing it correctly and also why I need to have the line Return AppDataFullpath in the Function. Without this line Visual Studio shows a squiggly line under End Function.

A:

You are doing is basically correctly, although I'd do it slightly differently.
The idea of a function is that it is a chunk of code identified by a name that does some work and then produces a value that you can use elsewhere in your code. In VB, a subroutine (identified by the Sub keyword) is similar but it does work without producing a value. The Return statement in the function is what tells the system what value the function produces. A subroutine generally has no Return statement or, if it does, no value is specified and it just indicates that the method should end at that point.
While it's not wrong to provide a String array to Path.Combine, it's parameter is actually declared as a ParamArray, which means that you can pass discrete values and the system packages them as a single array. That means that you could do this:
Dim AppData As String = GetFolderPath(SpecialFolder.LocalApplicationData)
Dim AppDataFullpath As String = Path.Combine(AppData, "MyApp")
Return AppDataFullpath

To be honest, I'd simplify that right down to a single line:
Return Path.Combine(GetFolderPath(SpecialFolder.LocalApplicationData), "MyApp")

Also, you should keep in mind that properties are data and methods are behaviour, so property names should be noun-based and method names should be verb-based. As such, that method would be better named GetLocalAppDataPath or the like. That is more self-documenting than what you currently have.

