|
-
Aug 3rd, 2004, 11:20 PM
#1
Thread Starter
Frenzied Member
Reference to a non-shared member
what do you mean by this?
im very new in this thing
VB Code:
Dim s As String
s = Format(txtamt.Text, "Standard")
the format has a blue line. Error: Reference to a non-shared member requires an object reference:
-
Aug 4th, 2004, 04:49 AM
#2
PowerPoster
Hi,
Have a close look at your code again. The code you posted works OK.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Aug 4th, 2004, 08:20 PM
#3
Thread Starter
Frenzied Member
sorry my fault..I imports a class that has a format method.
-
Aug 5th, 2004, 12:47 PM
#4
Hyperactive Member
If your Format method is not shared, but only Public, you can access it only if you create an instance of your class.
For example, let's call 'I' the instance and 'MyC' your class
VB Code:
Dim I as new MyC
Dim s As String
s = I.Format(txtamt.Text, "Standard")
Live long and prosper (Mr. Spock)
-
Aug 5th, 2004, 06:53 PM
#5
PowerPoster
Originally posted by mar_zim
sorry my fault..I imports a class that has a format method.
I don't think you should use a VB.NET function name as a method name. It is confusing to say the least
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Aug 5th, 2004, 09:24 PM
#6
Frenzied Member
or you can do this:
VB Code:
dim s as string
s = s.Format(txtamt.Text, "Standard")
-
Aug 6th, 2004, 12:48 AM
#7
If you are using the Format method of the string object then you don't even need an instance of string, since Format is a shared function.
VB Code:
Dim s As String=String.Format(txtamt.Text, "Standard")
-
Aug 6th, 2004, 01:24 PM
#8
Hyperactive Member
Once again the doubt of my ability to understand english....is your class' Format method (Taxes is perfectly right, this choice make a lot of confusion) shared as Edneeis says or it isn't as your error message seems to say?
I'm very confused. I think it's better if I remain in stand by on this thread!
Live long and prosper (Mr. Spock)
-
Aug 6th, 2004, 03:21 PM
#9
PowerPoster
Originally posted by Edneeis
If you are using the Format method of the string object then you don't even need an instance of string, since Format is a shared function.
VB Code:
Dim s As String=String.Format(txtamt.Text, "Standard")
For my education please.
Surely you have created s as an instance of string so why do you say you don't need it?
Knowing you I expect you will come up with a simple explanation I am missing
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Aug 6th, 2004, 11:32 PM
#10
The instance of string (s) in this case is only to hold the result but is not required to use the Format function. Perhaps this is a better example:
VB Code:
Msgbox(String.Format(txtamt.Text, "Standard"))
Since Format is a shared method of the String object you don't need to make an instance of string to use the Format method of the string object. Although you may want an instance variable to store the results of the function.
Also String.Format performs an argument style replace. Here are some examples:
VB Code:
Dim name As String="Edneeis"
Msgbox(String.Format("Your name is {0}!",name))
'result: [b]Your name is Edneeis![/b]
Msgbox(String.Format("Your name is {0} and today is {1:MM/dd/yy}!",name, Date.Today))
'result: [b]Your name is Edneeis and today is 08/06/04![/b]
'notice how I added formatting to the date in the format string
Msgbox(String.Format("Your name is {0}!{2}Today is {1:MM/dd/yy}!{2}{2}This is a line down.",name, Date.Today, ControlChars.NewLine))
'result: [b]Your name is Edneeis!
'Today is 08/06/04!
'
'This is a line down.[/b]
-
Aug 7th, 2004, 07:09 AM
#11
PowerPoster
Hi Edneeis,
Many thanks. My education is proceeding slowly.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|