Static Method!!

M

Mr Ideas Man

Hi all,

I am trying to create the following class:

My problem is i can't seem to use this static function (VB)

The error i am getting is "methods can not be declared static"

Can anyone enlighten me?

Imports System.IO

Public Class Stationery : Inherits Page

Public Static Function GetStationery(ByVal strFileName)

Dim objStreamReader As StreamReader
Dim strFileContents As String

Try

'open file
objStreamReader = File.OpenText(strFileName)

'read the entire file into a string
strFileContents = objStreamReader.ReadToEnd()

'close file
objStreamReader.Close()

Catch ex As Exception

'output exception error
Response.Write(("The following exception occurred: " +
ex.ToString()))

End Try

'return file contents string
GetStationery = strFileContents

End Function

End Class
 
J

Juan T. Llibre

If you're using VB, use Public Shared Function.

Public Static is a C# and/or JScript construct.
 
M

m.posseth

static is for local variabel declarations ( they behave as if they were
declared private outside the method )

the C# static equivalant for VB is the Shared keyword


so your code would become

Public Shared Function GetStationery(ByVal strFileName)

Dim objStreamReader As StreamReader
Dim strFileContents As String

Try

'open file
objStreamReader = File.OpenText(strFileName)

'read the entire file into a string
strFileContents = objStreamReader.ReadToEnd()

'close file
objStreamReader.Close()

Catch ex As Exception

'output exception error
Response.Write(("The following exception occurred: " +
ex.ToString()))

End Try

'return file contents string
GetStationery = strFileContents
End Function


regards

Michel Posseth [MCP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top