|
roger6897 wrote: How can 'Instance' be best explained in Visual Basic
Well, it depends on what you mean by "instance"?
I'm guessing you mean in terms of object oriented programming (OOP)
An object is an instance of a class. A class is a type.
You create a new instance of a class with the New keyword.
Dim w As Widget = New Widget(someParameter)
w is the reference to the object (the instance of the class.
Widget is the name of the class
New instantiates the instance of the class.
Does that answer your question?
|
|
|
|
|
Hi all, Please help me with this... I'm developing a system using pocket pc.. i can connect to database (sql server mobile (northwind.sdf) - using sqlClientCe).. but at the same time i need to connect to (SQL SERVER - Northwind database)... my problem is.. i cant make any connection to a SQL Server to fetch my datas... thanks in advance..
|
|
|
|
|
Hey all.
I got a problem wih Aaron Eldreth's Real Time SynTax Colorizing tutorial/article. I've posted the problem on his article page, but i don't think he'll respond, since he made his last post in 2004, so i don't think he visits here anymore.
Thats why im posting the exact same issue here in the VB.NET forum hoping that some else has the solution. So here's the original post:
Hi Aaron!
Awesome code! Im using this in my application which is a front end compiler. This compiler creates a log file, and i want to use your code do colorize error messages in that logfile.
But anyway, something strange is happening, check it out: Screenshot
As you can see, something is wrong:
The word "hlcsg is colored yellow, which is working fine. But there's another instance of this word (Current hlcsg settings) in the log which is not colored yellow! Why?"
Also note that the word "estimate" is colored purple, but i haven't added this word to the Keywords on the left! What the.
The words "max texture memory" (below the purple estimate) is not colored at all.
The word "zhlt.wad" is colored red, but the word "wadinclude" is partially colored red, only the first character and the last character of that word is left white (which is the default color) and it not even in the Keywords! Below the second zhlt.wad is another instance of zhlt.wad, but this one is left white, while it should be colored red as well.
The words "discarded from clipping hulls" is colored greenyellow, only the last character of the word "hulls" is left white.
This is really weird, and i can't figure it out.
I guess this has something to do with text encoding, since the log text is actually being read from a .log file on my hard drive.
When i empty the RichtTextBox and start to type in words manually, it works fine.
If you know why this is happening and how to fix this, please tell me how, i would really appreciate it and ill give you credits in my app when i release it.
I hope knows what the problems is, because i can't figure this out. Its so weird.
- Atom
http://www.themightyatom.nl
|
|
|
|
|
You'll notice that further comments also discount the quality of this article due to its poor performance over many lines. This is because the way its done is not dealing with only the visible lines. Perhaps you should seek an alternative syntax coloring method. Not sure exactly what aaron uses, but, perhaps developing your own using Regex would be a good bet. I'd give you my syntax highlighting code but its still under construction, (i.e. only just started 2 days ago).
|
|
|
|
|
Hmmm, i tried RegEx numerous times, but never got it working, its kinda complicated to me.
If you have some code for me that i can use, i would appreciate it, and ill credit you for that.
I've trying to get this (coloring error message in my log file) for several weeks now, without any results. That article by Aaron was the only thing that (kinda works) if i wasn't for the fact that it has poor performance, like you said.
I really need some help. If you can, please do so.
Thanks.
- Atom.
http://www.themightyatom.nl
|
|
|
|
|
i emailed you some stuff, its just a modification of aarons. So no credit for me. I hope it works right for you. If not we will have to keep trying.
|
|
|
|
|
I don't have anything in my inbox.
It might have been removed by the spamfilter.
Could you send it to mdw DOT breddels1 AT hccnet DOT nl instead?
http://www.themightyatom.nl
|
|
|
|
|
I am using a FillBy method to get certain rows from the Table Adapter. How do I get the number of rows that are returned from the query?
|
|
|
|
|
Hi all,
I'm working in a system that was written in VB.NET, and I ran across a function library(gag) that uses the Shared modifier on all of the functions inside it. I know that this modifier is for accessing non-static members using static syntax, but does anyone know exactly what's going on under the hood? Since the function is NOT static, and is in fact an instance member, does a call to a Shared method implicitly instantiate the object, call the function, return the result and then have the implicit object go out of scope for garbage collection? (That's what I think it's probably doing...but I can't find any information to substantiate my thoughts) Does anyone know of anything that can refute this assumption?
"I need build Skynet. Plz send code"
|
|
|
|
|
Hi,
Alaric_ wrote: Since the function is NOT static ...
Wrong AFAIK.
I'm not a VB expert but this is how I understand it:
1. "static" in VB.NET is what used to be "static" in C, i.e. keep a local variable alive inside
a procedure even when the procedure has exited (so it holds its value for the next execution)
2. "shared" in VB.NET is what is "static" in OO languages such as C#, i.e. have class
members that exist only once, and are shared amongst all instances of the class;
and static methods are methods that do not belong to a specific instance, hence can only
access static class members.
So if you have a C/C++/C# background, you should think of "static" whenever you encounter
"Shared" in VB code...
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi Luc,
Yeah, my background is in C, C++, Java, and C#....was thrown onto a VB.NET project to come in and save the day : P
Luc Pattyn wrote: So if you have a C/C++/C# background, you should think of "static" whenever you encounter
"Shared" in VB code...
ok...that's exactly what I was thinking, because that's what you would immediately assume when you see tons of functions being invoked using the same syntactic structure as a static call in any other language....BUT, I saw that there is still a static modifier AND, I found out that yes you can invoke instance members inside a "Shared" function. (Did it just a second ago) ....As soon as I was able to invoke a private instance method, I threw all of the VB documentation out the window that said that "Shared" equated to "static"...because by the very nature of .NET, static members cannot interact with instance members....Does anyone know why VB allows you to do this?
"I need build Skynet. Plz send code"
modified on Saturday, January 19, 2008 6:48:04 PM
|
|
|
|
|
Alaric_ wrote: BUT, I saw that there is still a static modifier
The Static keywork in VB is something different. It lets you declare variables that has method scope but are stored in the class (for static methods) or in the instance (for member methods).
Alaric_ wrote: I found out that yes you can invoke instance members inside a "Shared" function.
Of course you can, if you have a reference to an instance of the class.
Alaric_ wrote: by the very nature of .NET, static members cannot interact with instance members...
Of course they can, as long as you have an instance of the class. If there is no instance of the class, you can't call a member method from a static method.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
The Shared keyword in VB.NET is synonymous with the static keyword in C#. If a method is defined as Shared, it is invoked against the class itself, not against an instance of the class.
Alaric_ wrote: Since the function is NOT static, and is in fact an instance member, does a call to a Shared method implicitly instantiate the object, call the function, return the result and then have the implicit object go out of scope for garbage collection?
If the method is defined as Shared it is a static, not an instance member of the class. The CLR will load an Type object for the class on the Managed Heap so that the method can be invoked. No instance of the class is created on the heap because an object instance is required to invoke a static method. Garbage collection does not apply since there are no object instances to be cleaned up.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Thanks for all of your help,
pmarfleet wrote: If the method is defined as Shared it is a static, not an instance member of the class. The CLR will load an Type object for the class on the Managed Heap so that the method can be invoked. No instance of the class is created on the heap because an object instance is required to invoke a static method. Garbage collection does not apply since there are no object instances to be cleaned up.
...then why is is that a "Shared" function can still be referenced in the context of an instance member? Just as non-static members cannot be referenced in a static context, static members cannot be referenced in a non-static context....or at least, that's the way it's SUPPOSED to be...I don't know why VB devs would have the need to do something different than the rest of the world
Dim manager As Manager
manager.InsertTransactionHeader()
and
Manager.InsertTransactionHeader()
both execute identically if InsertTransactionHeader is declared with the "Shared" modifier inside the Manager class (example is quite contrived, but I think it demonstrates my point)
"I need build Skynet. Plz send code"
|
|
|
|
|
Alaric_ wrote: ...then why is is that a "Shared" function can still be referenced in the context of an instance member?
I usually code in C#, not VB.NET. You can't do this in C#. At a guess this is just syntatical sugar, a feature of the VB.NET language that is designed to make it more 'user-friendly'. Internally, the method will be invoked against the type and not the object instance, because this is where the code resides.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
In C# you get an error if you try to do that. In VB you only get a warning, which in my opinion is a bit weak.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
ok...so if "Shared" is actually static, then why is there a static modifier? That's just plain confusing. ...and if "Shared" is static, I would assume that you are allowed to declare a method as "private shared". Is this assumption incorrect?
"I need build Skynet. Plz send code"
|
|
|
|
|
Alaric_ wrote: ok...so if "Shared" is actually static, then why is there a static modifier?
Luc already explained this point in his reply. The Static keyword I believe is a legacy of classic VB. In other languages (including C#), static has a different meaning which is synonymous with the Shared keyword in VB.
Alaric_ wrote: would assume that you are allowed to declare a method as "private shared". Is this assumption incorrect?
There's nothing wrong with declaring a method as Private and Shared . It just means that it is a static method that can only be invoked by other members internal to that class.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
pmarfleet wrote: No instance of the class is created on the heap because an object instance is required to invoke a static method
I think this is kind of ancillary, because you guys have already given me the answer that I need(Thanks guys) ...but pmarfleet: I'm having a hard time following the logic you used in the statement that I've quoted.
Classically:
...A "Class" is a "Type of" artifact...as in you write a "Person" class in which you define the state
information and behaviors of all instances of "Person"
...an "Object" is an instantiation of a Class. As in "Person person = new Person()"
If an instance of a class(which is an object) is created not created on the heap, then how is an "object instance" (which I assume you intend to mean something other than the classical definition of "Object") required. ...Your statement is turning into a Russell's paradox
Russell's Paradox = (Y is a member of Y iff( Y is not a member of Y))
"I need build Skynet. Plz send code"
|
|
|
|
|
It's a typo. What he means is:
No instance of the class is created on the heap because an object instance is not required to invoke a static method.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
I have an MDI project with, so far, 5 MDI child forms. One menu item on the main form, mnuWindows, is set as the MdiWindowListItem on the MenuStrip. Here's the puzzling behaviour.
Whenever one particular MDI child form, F_Import, is open, the form changes how the MdiWindowListItem drop down menu works. It doesn't matter which of the other 4 child forms are open or may be the active child, when I click on the MdiWindowListItem menu, F_Import immediately receives the focus and is checked on the drop down menu. Selecting another child from the menu gives that child the focus, but, opening the MdiWindowListItem drop down menu immediately places the focus back on F_Import.
When F_Import is not open, the MdiWindowListItem drop down menu acts as expected. When the drop down menu is opened, the child form currently having the focus is also the form checked on the menu.
I have not been able to identify any form or menustrip property that affects this errant behaviour. Nor has a search on the Internet revealed any related information. Anyone run into this issue before?
|
|
|
|
|
The errant behaviour stopped when I removed the word "Import" from the form Name property.
|
|
|
|
|
chalk it up to just being the nature of VB
"I need build Skynet. Plz send code"
|
|
|
|
|
Hi,
I have writen my own front-end for a carPC project and for a final touch I thought I would have an option to wirelessly update the MP3 shared folder on my PC when I am in the driveway.
Right, what I have done is set my home PC to a static IP address of '192.168.0.136' and a shared folder called 'mp3'
Here is a small bit of code demonstating what I want to do...
strHubComputerIP = "192.168.0.136"
strHubComputerMp3Folder = "mp3"
strRemoteDirectory = New DirectoryInfo("\\" & strHubComputerIP & "\" & strHubComputerMp3Folder & "\")
If strRemoteDirectory.Exists Then............
this works fine, but if I change the IP address to "192.168.0.135" or the 'hub' computer is off (the IP address can't be seen), the computer hangs for 2 minutes.
For example, if I pull into my drive and want to update, but my home PC is off, I don't want the computer in the car to hang. I want it to tell me that the IP address isn't found.
Hope someone can help, I've been working on my front-end for a year now as I've been saving up for the hardware. This is the last bit I need to sort out, then I can build the machine
|
|
|
|
|
Just incase anyone was going to answer this question, I have found a way of doing it.
Instead of using IP address, I use 'computer name'
strHubComputerName = "main-computer"
strHubComputerMp3Folder = "mp3"
strRemoteDirectory = New DirectoryInfo("\\" & strHubComputerName & "\" & strHubComputerMp3Folder & "\")
If strRemoteDirectory.Exists Then............
This only hangs for 2 seconds if the 'folder' isn't found. This is far better.
|
|
|
|
|