Which do you prefer?

  • Thread starter Master Programmer
  • Start date
M

Master Programmer

Which do you prefer?

Classic VB example:
*************************
Private Sub Command1_Click()
MsgBox "Hello, World"
End Sub

A VB.NET example:
**************************
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MessageBox.Show("Hello, World")
End Sub
 
S

Stephany Young

Playing your silly game:

When I'm developing/maintaining something using VB6, I use the former.

When I'm developing/maintaining something using VB.NET, I use the latter.
 
B

Blake

Which do you prefer?

Classic VB example:
*************************
Private Sub Command1_Click()
MsgBox "Hello, World"
End Sub

A VB.NET example:
**************************
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MessageBox.Show("Hello, World")
End Sub

What do you prefer?

Classic VB example:
*************************

Private Sub Command1_Click()
MsgBox "Hello, World"
End Sub

Private Sub Command2_Click()
MsgBox "Hello, World"
End Sub

Private Sub Command3_Click()
MsgBox "Hello, World"
End Sub

Private Sub Command4_Click()
MsgBox "Hello, World"
End Sub

Private Sub Command5_Click()
MsgBox "Hello, World"
End Sub

Private Sub Command6_Click()
MsgBox "Hello, World"
End Sub

Private Sub Command7_Click()
MsgBox "Hello, World"
End Sub

A VB.NET example:
**************************

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click,
Button5.Click, Button6.Click, Button7.Click,
MessageBox.Show("Hello, World")
End Sub
 
M

Michael C

Master Programmer said:
Which do you prefer?

Classic VB example:
*************************
Private Sub Command1_Click()
MsgBox "Hello, World"
End Sub

A VB.NET example:
**************************
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MessageBox.Show("Hello, World")
End Sub

I prefer the c# version :)
 
M

Michael C

Blake said:
Classic VB example:
*************************

Private Sub Command1_Click()
MsgBox "Hello, World"
End Sub

Private Sub Command2_Click()
MsgBox "Hello, World"
End Sub

Private Sub Command3_Click()
MsgBox "Hello, World"
End Sub

Private Sub Command4_Click()
MsgBox "Hello, World"
End Sub

Private Sub Command5_Click()
MsgBox "Hello, World"
End Sub

Private Sub Command6_Click()
MsgBox "Hello, World"
End Sub

Private Sub Command7_Click()
MsgBox "Hello, World"
End Sub

Never heard of control arrays?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click,
Button5.Click, Button6.Click, Button7.Click,
MessageBox.Show("Hello, World")
End Sub

This isn't that good either as it would be better to use a for each
statement.

Michael
 
C

Cor Ligthert [MVP]

Strange: although I use both languages do I find especially the handling of
handlers very weak in C#.

Cor
 
B

Blake

Handlers are not weak in C#. It's just that, in typical vb style, the
plumbing is connected automatically for VB with the Handles keyword. In
C# you have to do the plumbing yourself with the equivelant of the
AddHandler command. You can do it youself in VB too, sometimes this is
an advantage. ie:

private button1 as new button

AddHandler button1.Click , AddressOf Click

' add the button to a form...

....

Private Sub Click(sender as Object, e as EventArgs)

MessageBox("Hello World!")

End Sub

Esentially the Handles keyword is wiring the event delegates for you.
That is all.
 
C

Cor Ligthert [MVP]

Blake,

You can use the C# style in VB.Net in the same way, however you get
something extra in VB.Net, which is in my opinion in fact nicer as
documentation. (Although I use often the C# way in VB.Net).

Cor
 
M

Michael C

Cor Ligthert said:
Blake,

You can use the C# style in VB.Net in the same way, however you get
something extra in VB.Net, which is in my opinion in fact nicer as
documentation. (Although I use often the C# way in VB.Net).

That is true but you also get inconsistency which can lead to problems for
maintenance programmers.

Michael
 
T

Tim Patrick

Any maintenance programmer worth hiring is not going to have a problem using
either syntax.
 
B

Blake

Yes. Thats what I was pointing out :)

I too prefer to manage handlers myself. Even in VB.

I guess I just like knowing as exactly as possible what is going on.
 
M

Michael C

Tim Patrick said:
Any maintenance programmer worth hiring is not going to have a problem
using either syntax.

That's not the point. Of course they can use either syntax but if 50 events
use one syntax and 1 event uses the other then I'd be suprised if they
didn't miss it.

Michael
 
M

Master Programmer

Harder to read

The Grand Master
"When you have climbed to the top of the mountain you can look down at
everyone."
 
T

Tom Leylan

Hi Blake:

I also prefer the AddHandler syntax and for the same reason you mention. I
find it more readable, more flexible and less ambiguous. One should never
mix the styles and I'd have the "Handles" code reworked if somebody
submitted them to me.
 
R

RobinS

You mean, "Harder for MasterProgrammer to read."


Robin S.
---------------------------------
 
M

Master Programmer

Good programming is about leaving breadcrumbs for the next person. Not
trying to show off by writting code that is not immediatly obvious. If
it needs any comments to describe it - then you are a useless
programmer.

The Grand Master
 
D

dbahooker

I mean seriously here

'mybutton_click' in vb6?

it all used to be automagic.

I shouldn't ever need to change these.. mybutton_click should HANDLE
the CLICK event of mybutton

any other LOAD OF CRAP that you shove down my throat is going to be
responded to as 'VB.NET IS NOT TOO VERBOSE'
 
M

Michael C

Tom Leylan said:
Hi Blake:

I also prefer the AddHandler syntax and for the same reason you mention.
I find it more readable, more flexible and less ambiguous. One should
never mix the styles and I'd have the "Handles" code reworked if somebody
submitted them to me.

I'm not sure that would be a good idea. The handles keyword supports the
designer where I presume the AddHandler does not.

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top