|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Reason for 'Set' keywordHi. Could someone please explain to me the reason for the 'Set'
keyword in VB. Am I correct in thinking that Set is used for assigning to a reference whereas assignment to primitives is done without 'Set'? Why is that? Most other languages just use '=' whether it is a reference or a primitive? Why does VB have so many strange differences from other languages that make it more difficult to pick up (witness the myriad of ways to end blocks)? "kramer31" <kramer.newsrea***@gmail.com> wrote in message This is one of the many examples in VB of how they tried to make things news:1172618882.707095.25840@h3g2000cwc.googlegroups.com... > Hi. Could someone please explain to me the reason for the 'Set' > keyword in VB. Am I correct in thinking that Set is used for > assigning to a reference whereas assignment to primitives is done > without 'Set'? > > Why is that? Most other languages just use '=' whether it is a > reference or a primitive? > > Why does VB have so many strange differences from other languages that > make it more difficult to pick up (witness the myriad of ways to end > blocks)? easier but just made it more difficult. The reason it's there is because of default properties. eg dim x as variant x = MyTextBox this code is treated as x = MyTextBox.Text because Text is the default property of TextBox. But if you actually wanted to assign the MyTextBox reference to x you would need to use Set. Michael kramer31 <kramer.newsrea***@gmail.com> wrote:
> Hi. Could someone please explain to me the reason for the 'Set' It's because some genious decided it'd be "easier" if objects supported default > keyword in VB. Am I correct in thinking that Set is used for > assigning to a reference whereas assignment to primitives is done > without 'Set'? > > Why is that? Most other languages just use '=' whether it is a > reference or a primitive? properties. > Why does VB have so many strange differences from other languages that That was done to perplex the snobs. True newbs aren't bothered by those things, > make it more difficult to pick up (witness the myriad of ways to end > blocks)? generally. ;-) "kramer31" <kramer.newsrea***@gmail.com> wrote in message Correctnews:1172618882.707095.25840@h3g2000cwc.googlegroups.com > Hi. Could someone please explain to me the reason for the 'Set' > keyword in VB. Am I correct in thinking that Set is used for > assigning to a reference whereas assignment to primitives is done > without 'Set'? > Why is that? Most other languages just use '=' whether it is a VB allows for the use of default properties; for example:> reference or a primitive? x = Label1 ' gets the default property, .Caption, and assigns that to x Set x = Label1 ' makes x a reference to the Label1 object > Why does VB have so many strange differences from other languages that All languages have their idiosyncracies. VB, IMO, is a very easy language> make it more difficult to pick up (witness the myriad of ways to end > blocks)? to pick up and I see the myriad ways of ending blocks as very simple since they align nicely with the myriad ways of starting blocks. When using a language like C and trying to code something that has an if inside a loop inside another if it can be a pain in the butt to figure out which closing brace goes with what, especially if the indentation has gotten messed up. It's really all in what you are used to. -- Reply to the group so all can participate VB.Net: "Fool me once..." I'm not really a .NET expert, and I know many people here hate it, but just
FYI, as I understand it, they've removed (or perhaps deprecated?) the Set keyword in VB.NET. Rob Show quoteHide quote "kramer31" <kramer.newsrea***@gmail.com> wrote in message news:1172618882.707095.25840@h3g2000cwc.googlegroups.com... > Hi. Could someone please explain to me the reason for the 'Set' > keyword in VB. Am I correct in thinking that Set is used for > assigning to a reference whereas assignment to primitives is done > without 'Set'? > > Why is that? Most other languages just use '=' whether it is a > reference or a primitive? > > Why does VB have so many strange differences from other languages that > make it more difficult to pick up (witness the myriad of ways to end > blocks)? > "Robert Morley" <rmor***@magma.ca.N0.Freak1n.sparn> wrote in message It's not in VB.Net but I wouldn't call that being removed since it's basednews:uzNvJ6sWHHA.528@TK2MSFTNGP03.phx.gbl > I'm not really a .NET expert, and I know many people here hate it, > but just FYI, as I understand it, they've removed (or perhaps > deprecated?) the Set keyword in VB.NET. on C#, not VB. They just never added it. And MS doesn't deprecate anything. That'd be too valuable for the developers. -- Reply to the group so all can participate VB.Net: "Fool me once..." "Robert Morley" <rmor***@magma.ca.N0.Freak1n.sparn> wrote in message They removed default properties so have no need for the set keyword. I news:uzNvJ6sWHHA.528@TK2MSFTNGP03.phx.gbl... > I'm not really a .NET expert, and I know many people here hate it, but > just FYI, as I understand it, they've removed (or perhaps deprecated?) the > Set keyword in VB.NET. believe the only time you can use a default property is when it has brackets, eg: MyRecordset.Fields("X") will work as MyRecordset("X"). Of course dot net doesn't have a recordset object but it's just an example. Michael kramer31 wrote:
> Hi. Could someone please explain to me the reason for the 'Set' Set is used for assigning objects, Let is used for assigning variables. Let > keyword in VB. Am I correct in thinking that Set is used for > assigning to a reference whereas assignment to primitives is done > without 'Set'? is not required to be used, thus generally won't appear in code. > Why is that? Most other languages just use '=' whether it is a Why do other languages have so many strange differences from VB?> reference or a primitive? > > Why does VB have so many strange differences from other languages that > make it more difficult to pick up (witness the myriad of ways to end > blocks)? Why does Fortran differ from COBOL? Why is English different from French, or Spanish, or even Mongolian? -- Regards, Michael Cole > Why is English different from French, or Spanish, or even Mongolian? Programming languages are different than natural languages. Naturallanguages have evolved whereas programming languages were designed. As such the designers of programming languages are responsible for poorly designed languages. In my opinion, VB is a marvel of confusing syntax. > Why does Fortran differ from COBOL? Not being familiar with either one, I wouldn't know. If you'd like todiscuss why C differs from C++ or Java or PERL, I can discuss those. They are well designed for what they do. Even without using them on a regular basis, I can't still write syntactically correct code quite quickly. > I see the myriad ways of ending blocks as very simple since Not if you nest blocks of the same type. Anyway, a better text editor> they align nicely with the myriad ways of starting blocks. or commenting system will correct that. I just can't remember how to end the damned things. I don't even mind keywords ending blocks, let me propose a better scheme (which I believe I've seen in some language...): while end while for end for if end if There. Now that's easy to remember. Please note that I am not criticizing the VB object model just the language syntax which must have come deep from the ass of some early MS employee. Kramer wrote:
> Please note that I am not criticizing the VB object model just the It's always amusing when someone complains about the perceived shortcomings of some language or other. I've seen it from every direction, and it's just as pointless in every one.> language syntax which must have come deep from the ass of some early > MS employee. You have the same two choices you always have: deal with it or don't use it. Complaining is not productive, especially with a language like VB which is EOL and so will never change. And while Ford knows that MS has a lot to answer for, blaming them for 'for..next' shows a distinct lack of awareness of history. -- Jim > You have the same two choices you always have: deal with it or don't use it. Complaining is not productive, especially with a language like VB which is EOL and so will never change. I don't know about you but VB is not the language that I use for fun.I only have one choice: Deal with it. I only use it because it is a legacy app that I have to use. There are a LOT of differences between natural languages and programming languages. Programming languages change over time, but they are still designed. Some one still approves each spec whether for VB 4 or VB 6 or VB.NET. No one approved the addition of nanobot, automagically, or adware to the English language. Those words may have achieved some measure of validation by being added to the OED, but the OED observes the lexical aspects of the English language--it does not create them. Another key difference between natural languages and programming languages is that programming languages are formal. One can determine with certainty whether a string belongs or does not. Furthermore, the semantics of those strings (which actually are programs) are unambiguous. The same can't be said for (even well-formed) natural language sentences. > It's always amusing when someone complains about the perceived shortcomings of some language or other. I've seen it from every direction, and it's just as pointless in every one. Yeah, but if one is forced to slog through this garbage syntaxeveryday, it still can be a good way to blow off steam. "Kramer" <johnlkra***@gmail.com> wrote in message Wend etc are not the worst parts. Try opening a filenews:1172625169.093036.307070@z35g2000cwz.googlegroups.com... > Please note that I am not criticizing the VB object model just the > language syntax which must have come deep from the ass of some early > MS employee. filenum = FreeFile 'ok so far open filename for input as binary access readonly as filenum 'yikes! get FreeFile or is it put or read? Close FreeFile The above lines are more than likely close but not quite correct. This is not good because I've been using vb for 10 years and still can't remember them. Obviously all the VBers will think this is my fault but can anyone actually remember all the variations? Michael Michael C wrote:
Show quoteHide quote > "Kramer" <johnlkra***@gmail.com> wrote in message I have to look them up every time I need to do a file operation.> news:1172625169.093036.307070@z35g2000cwz.googlegroups.com... >> Please note that I am not criticizing the VB object model just the >> language syntax which must have come deep from the ass of some early >> MS employee. > > Wend etc are not the worst parts. Try opening a file > > filenum = FreeFile 'ok so far > open filename for input as binary access readonly as filenum 'yikes! > get FreeFile or is it put or read? > Close FreeFile > > The above lines are more than likely close but not quite correct. This is > not good because I've been using vb for 10 years and still can't remember > them. Obviously all the VBers will think this is my fault but can anyone > actually remember all the variations? > > Michael > > My main one is for opening a logfile at the start of an application, I have a stock standard: Open App_Path + STRLOGFILENAME For Append Access Write Shared As log_file (where app_path and STRLOGFILENAME are variable and constants set up in the declarations of the project) Most of the time I can't remember exactly what the access write shared means to other applications etc that attempt to access the file. All I know is it seems to work for the purposes I need it. I don't do much file reading at all so I definitely have to look that up each time I need to do something to find out which parameters I should be using. P. Kramer wrote:
>> Why is English different from French, or Spanish, or even Mongolian? Actually, programming languages evolve too. That's why we have versions of > > Programming languages are different than natural languages. Natural > languages have evolved whereas programming languages were designed. > As such the designers of programming languages are responsible for > poorly designed languages. In my opinion, VB is a marvel of confusing > syntax. the stuff. VB6 evolved from VB5 from VB4 from ... Basic. Perhaps you should have a look at the history of VB - http://dotnetmasters.com/HistoryOfBasic.htm >> Why does Fortran differ from COBOL? C evolved too. http://dotnetmasters.com/HistoryOfCFamily.htm> > Not being familiar with either one, I wouldn't know. If you'd like to > discuss why C differs from C++ or Java or PERL, I can discuss those. > They are well designed for what they do. Even without using them on a > regular basis, I can't still write syntactically correct code quite > quickly. In fact, there really isn't all that much difference between Programming languages and natural languages. Oh, and which particular designer of BASIc are you having a go at? Dartmouth College Instructors circa 1964? Or doesn't your memory stretch back that far? >> I see the myriad ways of ending blocks as very simple since If you insist, how about: ->> they align nicely with the myriad ways of starting blocks. > > Not if you nest blocks of the same type. Anyway, a better text editor > or commenting system will correct that. I just can't remember how to > end the damned things. I don't even mind keywords ending blocks, let > me propose a better scheme (which I believe I've seen in some > language...): > > while > end while Do While End Do Oh, that is already acceptable syntax... > Please note that I am not criticizing the VB object model just the Except that it didn't. It actually originally came from the ass of a couple > language syntax which must have come deep from the ass of some early > MS employee. of Dartmouth College instructors. But hey, don't let that stop you having a go at MS, they certainly deserve it for something... -- Regards, Michael Cole "Kramer" <johnlkra***@gmail.com> wrote in message <cut>news:1172625169.093036.307070@z35g2000cwz.googlegroups.com > let me propose a better scheme (which I believe I've seen in some VB syntax has evolved over many years and, until recently, striven hard to> language...): > > while > end while > > for > end for > > if > end if > > There. Now that's easy to remember. maintain compatibility with earlier versions in order to maintain some degree of stability. That may mean there are some things that can seem inconsistent to a newbie who doesn't have a lot of history with VB or other variations of basic. The fact that your ability to learn a new languag is limisted is no reason to change the language to suit you. > Please note that I am not criticizing the VB object model just the Actually it's stuff like you just proposed that came deep from the ass of> language syntax which must have come deep from the ass of some early > MS employee. some recent MS employee who has the same mindset that you do. If you don't like VB syntax then go pick another language. VB is a dead language now and complaining about it's syntax is as pointless as it gets. If you feel the need to continue trolling, have fun. I've got much better things to do than waste time on somebody with your approach to things. plonk. -- Reply to the group so all can participate VB.Net: "Fool me once..." On 27 Feb 2007 15:28:02 -0800, "kramer31"
<kramer.newsrea***@gmail.com> wrote: >Hi. Could someone please explain to me the reason for the 'Set' A reference to an object is just 4 bytes that contain the location of>keyword in VB. Am I correct in thinking that Set is used for >assigning to a reference whereas assignment to primitives is done >without 'Set'? >Why is that? Most other languages just use '=' whether it is a >reference or a primitive? >Why does VB have so many strange differences from other languages that >make it more difficult to pick up (witness the myriad of ways to end >blocks)? the real object. You can have hundreds of Object References pointing to the same single Object Set is used to distinguish between making a copy of a variable and making another reference to the same Object Default properties may have come into it, but making a distinction between an Object Reference and a simple variable is a BASIC like approach. Personally I find it benign On 27 Feb 2007 15:28:02 -0800, "kramer31" <kramer.newsrea***@gmail.com> wrote: ¤ Hi. Could someone please explain to me the reason for the 'Set'¤ keyword in VB. Am I correct in thinking that Set is used for ¤ assigning to a reference whereas assignment to primitives is done ¤ without 'Set'? ¤ ¤ Why is that? Most other languages just use '=' whether it is a ¤ reference or a primitive? ¤ ¤ Why does VB have so many strange differences from other languages that ¤ make it more difficult to pick up (witness the myriad of ways to end ¤ blocks)? I think you pretty much identified why Set is used in Classic Visual Basic. It distinguishes between an object data type and primitives. In addition, the BASIC language has always been a bit more verbose, for the purpose of readability, and that was simply carried over into Visual Basic. The Set operator was subsequently removed from Visual Basic.NET since the distinction between object data types and primitives has essentially been blurred. In any event, you could ask similar questions about other languages. For example, why does C use braces, semi-colons, case-sensitivity, and different comparison operators? Why does Pascal use Begin...End statements and semi-colons? Most languages do not require these extraneous language components that result in unintentional syntax and logic errors. Paul ~~~~ Microsoft MVP (Visual Basic)
SendKeys command fails on Vista
Error in reading large csv file Sending email Should I or shouldn't I include excel.exe in my app distribution package? Run-time Error 430, WITH non-broken binary compatibility? TaskBar won't show when hidden. cropping rectangle My DataReport Problem Beginner: List of Color Values Open Excel when user press OK button |
|||||||||||||||||||||||