|
|
|
|
![]() ![]() |
Jan 9 2006, 11:57 PM
Post
#1
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 1 Joined: 9-January 06 Member No.: 10,606 |
In Visual Basic, what is the difference between:
ResourceName ResourceName$ ResourceName& |
|
|
|
Jan 11 2006, 04:40 AM
Post
#2
|
|
|
Super Member Group: [HOSTED] Posts: 557 Joined: 25-April 05 Member No.: 4,374 myCENTs:17.04 |
ohhh, ohh, ohh, pick me, pick me (jumps up and down with hand raised)
I actually had to look this one up because at first I thought they were all completely valid and done the same thing. After typing the variable name in Visual Studio I quickly had to turn to the help. I started in .NET and as such I am mostly ignorant of VB6 which this crap almost certainly came from. My example is for .NET. In short, ResourceName valid variable name although it will not compile because no type is given (string, integer, etc.) ResourceName$ Dim ResourceName as String ResourceName& Dim ResourceName as Long Special characters are short hand for assigning a type to a variable name. I have seen this used in older VB6 code but I would never use such bad techniques myself. Other types include: % - Integer @ - Decimal ! – Single # - Double The MSDN Document 2.2.1 Type CharactersSee Also Identifiers A type character following a non-escaped identifier denotes the type of the identifier. The type character is not considered part of the identifier. If a declaration includes a type character, the type character must agree with the type specified in the declaration itself; otherwise a compile-time error occurs. If the declaration omits the type, the type character is implicitly substituted as the type of the declaration. No white space may come between an identifier and its type character. There are no type characters for Byte or Short. Appending a type character to an identifier that conceptually does not have a type (for example, a namespace name) will cause a compile-time error. The following example shows the use of type characters: CODE ' The following line will cause an error: standard modules have no type. Module Module1# End Module Module Module2 ' This function takes a Long parameter and returns a String. Function StringFunc$(ByVal LongParam&) ' The following line causes an error because the type ' character conflicts with the declared type of ' StringFunc and LongParam. StringFunc# = CStr(LongParam@) ' The following line is valid. StringFunc$ = CStr(LongParam&) End Function End Module TypeCharacter ::= IntegerTypeCharacter | LongTypeCharacter | DecimalTypeCharacter | SingleTypeCharacter | DoubleTypeCharacter | StringTypeCharacter IntegerTypeCharacter ::= % LongTypeCharacter ::= & DecimalTypeCharacter ::= @ SingleTypeCharacter ::= ! DoubleTypeCharacter ::= # StringTypeCharacter ::= $ Notice from jipman:
code-tags for code next time |
|
|
|
Jan 11 2006, 06:04 AM
Post
#3
|
|
|
Member [ Level 2 ] Group: Members Posts: 72 Joined: 1-January 06 From: Egypt Member No.: 10,410 |
Well, type-characters used to be very nice short-hands before Visual Basic 5. Some old-timers love it and will debate who says otherwise relentlessly :-).
But I suppose you're when you say it's bad; but it's not bad technique, merely bad coding style. At least, I think so. |
|
|
|
Jan 11 2006, 04:23 PM
Post
#4
|
|
|
Super Member Group: [HOSTED] Posts: 557 Joined: 25-April 05 Member No.: 4,374 myCENTs:17.04 |
OK I will agree with that, just bad coding style. I have just found out that bad coding style can sink a ship quicker than almost anythign else.
|
|
|
|
Jan 11 2006, 06:41 PM
Post
#5
|
|
|
Member [ Level 2 ] Group: Members Posts: 72 Joined: 1-January 06 From: Egypt Member No.: 10,410 |
Totally true, transgrx. :-)
Although proper coding styles were a merely means of convenience and maintenance in earlier versions, new features like inheritance, up- and down-casting, polymorphism and the like make it essential to adopt a consistent *correct* style, effectively deminishing the fine line between style and proper syntax. Actually, I come from a low-level programming background (e.g. C, C++) so I think by now I instinctively force myself to more strict coding styles even if the alternative can do the job well. :-) |
|
|
|
Feb 24 2006, 06:15 PM
Post
#6
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 11 Joined: 17-February 06 Member No.: 11,363 |
I agree absolutely. These short cuts are there because of backwards compatability. Don't use them if you can possibly avoid it. Something like 80% of software cost is on maintanance so it's worth your time to be clear about the type of a variable...
|
|
|
|
Feb 25 2006, 07:04 AM
Post
#7
|
|
|
Binary Geek Group: Members Posts: 444 Joined: 4-November 05 From: The Digital Arena Member No.: 9,440 |
Dont Kick my nuts if i am being too VB illiterate .. I just started learning VB as a course in university ..
Please explain in detail for the above, ResourceName$ Dim ResourceName as String and ResourceName& Dim ResourceName as Long Normally we were told to define a variable like Dim a As Integer , here a being the variable. Where does this ResourceName$ Dim ResourceName come in ? Just a little Inquisitive Regards Dhanesh. |
|
|
|
Oct 13 2006, 02:24 PM
Post
#8
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 11 Joined: 13-October 06 Member No.: 16,536 |
Dont Kick my nuts if i am being too VB illiterate .. I just started learning VB as a course in university .. Please explain in detail for the above, ResourceName$ Dim ResourceName as String and ResourceName& Dim ResourceName as Long Normally we were told to define a variable like Dim a As Integer , here a being the variable. Where does this ResourceName$ Dim ResourceName come in ? Just a little Inquisitive Regards Dhanesh. I'm not really trying to tease you here, but that is VB.NET. It has quite some difference to VB6. Doing this in VB6 will cause an error. That's why, trust your instincts, unless you do not feel the passion of programming (Purrr). Form what I could gather, it only exist in VB.NET. PS: VB.NET is a language for computer servers, hardly useful in a normal program. |
|
|
|
Oct 18 2006, 08:30 PM
Post
#9
|
|
|
Super Member Group: [HOSTED] Posts: 557 Joined: 25-April 05 Member No.: 4,374 myCENTs:17.04 |
I have to somewhat disagree with your observations that VB.NET is only a server language. I have written many standalone Windows Forms applications. The current program is 10K+ SLOC and I have had no problems with VB.NET yet (in the sense of being a poor programming language). With the advent of the .NET Framework, VB.NET is just as powerful and has 99.9% of the features as C#. It is true that the majority of uses of VB.NET have been with ASP and database applications but I don’t think this is because it is a “server” language.
I guess the bottom line is this. The choice between VB.NET and C# is only what you are used to program in. If you came from C++ then C# is naturally your choice, if coming from VB then you will feel quite at home with VB.NET. |
|
|
|
Jan 1 2007, 03:50 AM
Post
#10
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 11 Joined: 13-October 06 Member No.: 16,536 |
You may be right about this, but look at the main features of the two similar but different programming languages.
Visual Basic .NET's major advantage is that it has .asp (active server pages) and SQL and built in xml tools. But, it does not do that well with other aspects of programming such as OpenGL and Direct X. It aslo involves with a lot of web controls, giving the hint that it is meant for servers. Visual Basic 6 has a better capability over things such as graphic manipulation fares better, creating .ocx and .dll and slightly better in API (but not as good in C/C++). As you can see, these things are all local resource programs. Visual Basic 6's internet connection tools are really, bad. The only way it can comunicate is to use a plugin written in some other language, or with API, which is not that great. And additionally, .NET has this capability of a Client to Server capability included, which was why I said server language (althogh i meant server-client). I have used .NET before, don't think amade random assumtions. PS: Even if I use GNU C++, I do not really like Microsoft C#. It is just a lousy effort by Microsoft to monoplise the programming language (note that is why we don't get compilers for such programs (such as C# and VB) from non-Microsoft based companies). C++ and Java are open languages, like html, anybody could make compilers for them if they want. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 5th December 2008 - 03:14 PM |