473,320 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Static Method!!

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
Mar 6 '06 #1
2 1147
If you're using VB, use Public Shared Function.

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

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mr Ideas Man" <ad**@pertrain.com.au> wrote in message
news:Of****************@TK2MSFTNGP12.phx.gbl...
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

Mar 6 '06 #2
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]
"Mr Ideas Man" <ad**@pertrain.com.au> wrote in message
news:Of****************@TK2MSFTNGP12.phx.gbl...
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

Mar 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have...
2
by: Tony Johansson | last post by:
Hello Experts! I know that you can't have virtual static methods and I know what a static method is. A static method exist only one time no matter how many object you have. You have this...
3
by: bauscharln | last post by:
hoi, I just wanted to add a static method to my interface, but that's not allowed! Is there a reason for this??? (Yes, I could make an abstract base class, but that's not what I want, since I...
8
by: Fernando Lopes | last post by:
Hi there! Someone has some code sample about when is recommend use a statis method? I know this methos don't want to be initialized and all but I want to know when I need to use it. Tks....
6
by: rlvladbob | last post by:
Hi, I've try to access a static method using an instance instead of a class. public class test{ public static void ShowAText(string ThisText) { System.Console.WriteLine("->{0}",ThisText); }
3
by: Bob | last post by:
I have an abstract class Thing which has a static method Thing GetThing(). Class Something inherits from Thing. SomeThing supplies static info for GetThing to get stuff from the database to create...
4
by: mfc | last post by:
How do i get the type info in a static method? for instance in the code below is it possible for the Method to get the type to know what type was used to call Method? thanks class C {
2
by: Anup Daware | last post by:
Hi Group, I have a little confusion over the use of static class in C#. I have a static method in my static class. This method reads an xml and returns a collection of objects. This collection...
9
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
5
by: DamienS | last post by:
Hi, I have a static method in a class and I need to be able to return a reference to "this". Googling around, I found a heap of discussions of the pros/cons of "abstract static" etc. It was...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.