Things I haven't noticed in VB until now
Just want to share a couple of discoveries I've just made (for myself) about visual basic.
1. Did you know that you don't need to specify that boring
Code:
sender As System.Object, e As System.EventArgs
in the event handlers any more if you don't need the sender part.
I just wrote
vb Code:
Private Sub Form1_Load() Handles Me.Load
MessageBox.Show("test")
End Sub
and it was compiled without. Imagine that!
2. What I missed the most is the true conditional operator (like the one in my signature). IIf was a poor substitution since it is really a function, not a ternary operator and it evaluated all its arguments which defeated the initial purpose of this language construction. To my amazement, I only just discovered the If operator which happens to be just that - a ternary operator. So, you can simply do this:
vb Code:
TextBox1.Text = If(IsDbNull(value), "", value.ToString())
Perhaps I didn't tell anything new to someone, but I'm sure, there are people who might find this information useful.
Re: Things I haven't noticed in VB until now
Cool, I didn't know about number 1. How does that even work? Is it a new feature in VS 2010 or something? I'm pretty sure it used to error on that in the past... (incompatible event signature)
Re: Things I haven't noticed in VB until now
Somehow, I think that two delegates are invoked on each such event. One is with the usual (sender As Object, e As EventArgs) and the second one is without it.
Re: Things I haven't noticed in VB until now
The If operator certainly is useful in various cases but I should point out that this:
vb.net Code:
TextBox1.Text = If(IsDbNull(value), "", value.ToString())
is redundant because DBNull.ToString returns an empty string anyway.
Re: Things I haven't noticed in VB until now
Quote:
Originally Posted by
jmcilhinney
The If operator certainly is useful in various cases but I should point out that this:
vb.net Code:
TextBox1.Text = If(IsDbNull(value), "", value.ToString())
is redundant because DBNull.ToString returns an empty string anyway.
A poor example, perhaps...