|
If we can use static variables inside instance constructor then why static method or constructor is required? When this will be used? Any practical usage of static or shared method.
|
|
|
|
|
A static method is a C# term. The vb.net equivalent is shared. A shared method can be called without creating an instance of your class. There are plenty of examples. For instance the 'string' class has a number of shared methods. There all over. A shared variable can also be accessed without creating an instance. A static variable is only good for a single instance of the class and can only be accessed if you have an instance. A shared variable on the other hand spans classes if you will.
|
|
|
|
|
TwoFaced wrote: A static variable is only good for a single instance of the class and can only be accessed if you have an instance
You mean a member variable, right ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
No, I meant static. My wording however was chosen poorly (and yes defines a member variable). I shouldn't write stuff when I'm tired. What I tried to say was the static variable requires an instance (Of course it has local scope and can't be seen outside the method it exists in). This is wrong, however, becuase you could use a static variable inside a shared method. Being awake certainly helps clarify things. Thanks for catching my mistake.
|
|
|
|
|
Shraddha Bhatt wrote: If we can use static variables inside instance constructor then why static method or constructor is required?
Because, you can access static variables and methods without ever calling an instance constructor. For example, the MessageBox class is static, you call MessageBox.Show(), without ever creating an instance constructor. If it needs to initialise anything, a static constructor is the only place to do it.
Shraddha Bhatt wrote: Any practical usage of static or shared method.
Usually, it comes down to offering stateless functionality ( i.e. methods that don't ever change any properties on a class instance ), so that you can call it without having to create an instance. An obvious example, is factory pattern methods. So, instead of saying
Dim f as Foo = new Foo()
you would say
Dim f as Foo = Foo.MakeOne();
There are benefits to this design, and obviously, I cannot call MakeOne to create a Foo, if it's not a static method, because, if the constructor is private, I could never have an instance of Foo on which to call the method.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi all,
I have created a small project in Vb.net 2005. When I try to debug the project with break point,the debuuger skips some breakpoints.
Can anybody help me regarding this?
Thanx in advance.
Max
|
|
|
|
|
Where are the break points located? If the code doesn't execute then the breakpoint won't stop the program. For instance if I have a breakpoint on the second line below it won't stop anything because that line will never execute.
If 1=2
msgbox("I won't be displayed")
end if
|
|
|
|
|
No man the code is being executed,but Debugger doesn´t stop on breakpoint.
When I try to do it on my machine it works,but on some other machine it falis to stop at the breakpoint.
Thankx for your quick response
Max
|
|
|
|
|
Dear All,
I have Table(MS SQL Sever 2000) name "Item" It has two colomn "ItemNo, IName") and it has relevant sample data also. Actually I can bind one colomn data to combo box(Using data set). But I need bind this two colomn("ItemNo", "IName") data in one combo box.
Pls, tell me or send sample code for that.
I'll think after binding two colomn like this.
00001 - Mother Board
00002 - Mouse
00003 - Key Board.
Thanks & Regrds
Kusal
|
|
|
|
|
You'll need to build a collection of strings that combines the values and bind to that.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Dear Christian ,
Many Thanks
Best Regards
Kusal
|
|
|
|
|
before doing collection of string tell me schould u want to make both in display
othervice set data member as one field and value member as other field so it will consider the the value member if u selected the data member i think i am saying in reverse any how it will give u a good result
with regards
Balagurunathan.B
|
|
|
|
|
Personally I would combine them in your query alone with the original 2 kept separate. So you would so something like the following.
SELECT (ItemNo + ' - ' + IName) AS CombinedColumns That way it is taken care of and you dont have to do any extra work in your code.
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that.'" - Tommy (Tommy Boy) "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
I would suggest that you construct SQL statement that concatenates the two column some thing like the following
Select (Col1 + ' - ' + Col2) as Col1, Col3 from Table
Once you do this you can always bind the col1 to dataText and col3 to datavalue
Hope that sounds good to you.
Regards,
Jaiprakash M Bankolli
jaiprakash.bankolli@gmail.com
|
|
|
|
|
I want the user to be able to point to a directory on their hard drive and the Images that are in there are then used to skin the form.
What I need to know is how to pre-load images when the form loads.
So that they are only loaded once.
Cheers
|
|
|
|
|
Just make them lazy initialised properties. That is, do this:
private Bitmap _mySkin;
private Bitmap MySkin
{
get
{
if (_mySkin == null)
{
_mySkin = LoadFromResources("mySkin");
}
return _mySkin;
}
}
Where LoadFromResources is a method you provide.
Then, you just reference MySkin, not _mySkin. Or, you can just load the bitmaps in your constructor or Load event.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I want to use VB2005 (VSTO) to create an add in for Outlook. I have read a lot, and tried a lot. I know how to create the add in, and how to show a dialog box when Outlook fires and when it's being closed. Those events are in the code that is created by VB. Now how can I add a button to the toolbar that, let's say, scans the messages of last week for a keyword entered by the user?
Any help would be greatly appericiated.
Thanks in advance,
Mark
|
|
|
|
|
How can I change VS 2005 shortcuts so CTRL + DOWN ARROW does the Edit.ScrollLineDown (Scrolls text down one line) command.
Thank you,
|
|
|
|
|
Tools -> Options -> Environment -> Keyboard -> Select command and apply new keyboard key combo
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that.'" - Tommy (Tommy Boy) "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
Thanks for the help – that's what I needed to know.
|
|
|
|
|
I need to develop a Windows Form application that has a sophisticated multipane or "paneled" User Interface.
I don't mean MDI, but various different panels that the user can move, resize, close, etc. to his/her own liking. Something like the Visual Studio UI.
Before re-inventing the wheel, I am wondering if there are any useful classes, examples, walkthroughs, articles or tips about this.
Thanks,
Jim
(I already found the articles:
"Using Paneled Forms in Windows Applications", and
"A guide to using Paneled Forms, Multi-Splash Screens, SQL Express, and many more in Windows Application Development"
on this website but they don't really discuss what I need)
|
|
|
|
|
I have added a combocolumn in a datagridview and added some items in it.
What i want is to autocomplete the combobox when i press a key?
How can i do so?
X
|
|
|
|
|
How can I make the function below to be performed from antoher sub?
Private Sub gain_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles gain.Scroll
You know there is a function PerformClick for Pushdown buttons. Appriciated for your help and support. Thanks.
B.B.
|
|
|
|
|
Raise Event Gain.Scroll(sender, e)
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that.'" - Tommy (Tommy Boy) "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
or if you just want the content executed:
gain_Scroll(nothing, nothing) 'when you don't care who's the sender or what's in e
|
|
|
|