Home All Groups Group Topic Archive Search About

Reason for 'Set' keyword

Author
27 Feb 2007 11:28 PM
kramer31
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)?

Author
27 Feb 2007 11:47 PM
Michael C
"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)?

This is one of the many examples in VB of how they tried to make things
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
Author
27 Feb 2007 11:48 PM
Karl E. Peterson
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?

It's because some genious decided it'd be "easier" if objects supported default
properties.

> 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)?

That was done to perplex the snobs.  True newbs aren't bothered by those things,
generally. ;-)
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
27 Feb 2007 11:57 PM
Bob Butler
"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'?

Correct

> Why is that?  Most other languages just use '=' whether it is a
> reference or a primitive?

VB allows for the use of default properties; for example:
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
> make it more difficult to pick up (witness the myriad of ways to end
> blocks)?

All languages have their idiosyncracies.  VB, IMO, is a very easy language
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..."
Author
28 Feb 2007 12:12 AM
Robert Morley
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)?
>
Author
28 Feb 2007 12:49 AM
Bob Butler
"Robert Morley" <rmor***@magma.ca.N0.Freak1n.sparn> wrote in message
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.

It's not in VB.Net but I wouldn't call that being removed since it's based
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..."
Author
28 Feb 2007 12:57 AM
Michael C
"Robert Morley" <rmor***@magma.ca.N0.Freak1n.sparn> wrote in message
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.

They removed default properties so have no need for the set keyword. I
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
Author
28 Feb 2007 12:13 AM
Michael Cole
kramer31 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'?

Set is used for assigning objects, Let is used for assigning variables.  Let
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
> 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 do other languages have so many strange differences from VB?

Why does Fortran differ from COBOL?

Why is English different from French, or Spanish, or even Mongolian?

--
Regards,

Michael Cole
Author
28 Feb 2007 1:12 AM
Kramer
> Why is English different from French, or Spanish, or even Mongolian?

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.

> Why does Fortran differ from COBOL?

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.

> I see the myriad ways of ending blocks as very simple since
> 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

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.
Author
28 Feb 2007 1:44 AM
Jim Mack
Kramer wrote:

> 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.

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.

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
Author
28 Feb 2007 10:44 PM
kramer31
> 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 syntax
everyday, it still can be a good way to blow off steam.
Author
28 Feb 2007 2:34 AM
Michael C
"Kramer" <johnlkra***@gmail.com> wrote in message
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
Author
28 Feb 2007 2:43 AM
Paul Lambert
Michael C wrote:
Show quoteHide quote
> "Kramer" <johnlkra***@gmail.com> wrote in message
> 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
>
>

I have to look them up every time I need to do a file operation.

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.

--
Posted via a free Usenet account from http://www.teranews.com
Author
28 Feb 2007 7:38 AM
Michael Cole
Kramer wrote:
>> Why is English different from French, or Spanish, or even Mongolian?
>
> 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.

Actually, programming languages evolve too.  That's why we have versions of
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?
>
> 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.

C evolved too.  http://dotnetmasters.com/HistoryOfCFamily.htm

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
>> 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

If you insist, how about: -

Do While
End Do

Oh, that is already acceptable syntax...


> 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.

Except that it didn't.  It actually originally came from the ass of a couple
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
Author
28 Feb 2007 1:40 PM
Bob Butler
"Kramer" <johnlkra***@gmail.com> wrote in message
news:1172625169.093036.307070@z35g2000cwz.googlegroups.com
<cut>
> 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.

VB syntax has evolved over many years and, until recently, striven hard to
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
> language syntax which must have come deep from the ass of some early
> MS employee.

Actually it's stuff like you just proposed that came deep from the ass of
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..."
Author
28 Feb 2007 8:25 AM
J French
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)?

A reference to an object is just 4 bytes that contain the location of
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
Author
28 Feb 2007 2:10 PM
Paul Clement
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)