Just in case you don't understand what DeepBlue has said I'll restate it.
If you are creating a method that does not return anything then you should define it as a Sub.
For example, the following method definition is of a method that does not return a value:
-
Private Sub ExportToCSV()
-
'Your code goes here
-
End Sub
-
If your method returns something (say the path to the file you created) then you would define it as a Function.
For example, the following method returns a String:
-
Private Function ExportToCSV() As String
-
Dim path As String = "C:\MyFolder\MyCVSFileName.cvs"
-
-
'Your code goes here
-
-
return path
-
End Function
You are getting that message because your Function is not returning a value.
If you have an "if" statement in your function that returns a value, you must also have a "default" return value for the function. In other words your function must always return something if it's a function.
For example, the following will cause an error because there is no default return value:
-
Private Function ExportToCSV() As String
-
Dim path As String = "C:\MyFolder\MyCVSFileName.cvs"
-
If someBoolean = True Then
-
return path
-
End If
-
-
'Your code goes here
-
-
End Function
It is advisable to always have 1 return statement in a method just to keep things less confusing and to avoid this type of error.
-Frinny