what do you mean by this?:ehh:
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:
Printable View
what do you mean by this?:ehh:
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:
Hi,
Have a close look at your code again. The code you posted works OK.
sorry my fault..I imports a class that has a format method.:p
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")
I don't think you should use a VB.NET function name as a method name. It is confusing to say the least:eek:Quote:
Originally posted by mar_zim
sorry my fault..I imports a class that has a format method.:p
or you can do this:
VB Code:
dim s as string s = s.Format(txtamt.Text, "Standard")
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")
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?:confused:
I'm very confused. I think it's better if I remain in stand by on this thread!:p
For my education please.Quote:
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")
Surely you have created s as an instance of string so why do you say you don't need it? :confused:
Knowing you I expect you will come up with a simple explanation I am missing:sick:
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]
Hi Edneeis,
Many thanks. My education is proceeding slowly.:wave: