tags:

views:

59

answers:

2

I am trying to add a new global function

I am doing it like that:

Function MessageYNC() As String

{ return "dd"; }

End Function

Public Class SatelliteAPI

End Class

But i am getting error -> Statement is not valid in a namespace. on the first line

Any idea what is wrong ?

+1  A: 

Put the function into a class or module. If you put it into a class, you need to make it Shared. So it's either

Module MyFunctions
    Function MessageYNC() As String
        Return "dd"
    End Function
End Module

or

Public Class SatelliteAPI
    Shared Function MessageYNC() As String
        Return "dd"
    End Function
End Class

in which case you would access it as StaelliteAPI.MessageYNC.

Heinzi
+3  A: 


Public Class SatelliteAPI
Public Shared Function MessageYNC() As String
        Return "dd"
    End Function
End Class 'SatelliteAPI

Public Class TestClass
    Public Sub TestMessageMethod()
        Console.WriteLine(SatelliteAPI.MessageYNC)
    End Sub
End Class 'TestClass
brad.huffman
Wow. Stackoverflow destroyed my code sample. Completely removed line breaks.
brad.huffman
Fixed by adding horizontal rule between list and code sample. Weird.
brad.huffman
Thanks for the link.
Night Walker