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
 
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

Top