what's the difference 
Author Message
 what's the difference

  hi.
In one of the examples made by Microsoft about arrays, I found this:

Dim opt As RadioButton = CType(sender, RadioButton)
Me.grpCompareField.Enabled = Not (opt.Name = "optStrings")

I replaced it by this:

Me.grpCompareField.Enabled = Not optStrings.Checked

and it works fine.Why use the dim sentence ?



Sun, 01 May 2005 05:38:10 GMT  
 what's the difference
It is because the same piece of code can be used to handle more than one
event and from more than one control. The 'sender' parameter then becomes
key to the code within as a means of identifying which control is firing the
event.


Quote:
>   hi.
> In one of the examples made by Microsoft about arrays, I found this:

> Dim opt As RadioButton = CType(sender, RadioButton)
> Me.grpCompareField.Enabled = Not (opt.Name = "optStrings")

> I replaced it by this:

> Me.grpCompareField.Enabled = Not optStrings.Checked

> and it works fine.Why use the dim sentence ?



Mon, 02 May 2005 16:54:54 GMT  
 what's the difference
Thanks a lot


Quote:
> It is because the same piece of code can be used to handle more than one
> event and from more than one control. The 'sender' parameter then becomes
> key to the code within as a means of identifying which control is firing
the
> event.



> >   hi.
> > In one of the examples made by Microsoft about arrays, I found this:

> > Dim opt As RadioButton = CType(sender, RadioButton)
> > Me.grpCompareField.Enabled = Not (opt.Name = "optStrings")

> > I replaced it by this:

> > Me.grpCompareField.Enabled = Not optStrings.Checked

> > and it works fine.Why use the dim sentence ?



Mon, 02 May 2005 07:51:43 GMT  
 what's the difference
After seeing the code again, and based upon your explanation, I understand
this:
Private Sub CompareKeyCheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles optId.CheckedChanged, optName.CheckedChanged

Dim opt As RadioButton = CType(sender, RadioButton)

.....

because it really handles 2 events

But what about this:

.

Private Sub txtLength_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtLength.Validating

Dim txt As TextBox = CType(sender, TextBox)

here we should simply use the properties of txtLength ..Am I right ?

BTW: another question (I'm experienced in other languages but newbie in VB):

How do we format an integer to pad it with zeroes on its left? (ex: 3 ---->
0003)

Thank you in advance.

.

Quote:
----- Original Message -----

Newsgroups: microsoft.public.dotnet.languages.vb
Sent: Thursday, November 14, 2002 3:54 AM
Subject: Re: what's the difference

> It is because the same piece of code can be used to handle more than one
> event and from more than one control. The 'sender' parameter then becomes
> key to the code within as a means of identifying which control is firing
the
> event.



> >   hi.
> > In one of the examples made by Microsoft about arrays, I found this:

> > Dim opt As RadioButton = CType(sender, RadioButton)
> > Me.grpCompareField.Enabled = Not (opt.Name = "optStrings")

> > I replaced it by this:

> > Me.grpCompareField.Enabled = Not optStrings.Checked

> > and it works fine.Why use the dim sentence ?



> It is because the same piece of code can be used to handle more than one
> event and from more than one control. The 'sender' parameter then becomes
> key to the code within as a means of identifying which control is firing
the
> event.



> >   hi.
> > In one of the examples made by Microsoft about arrays, I found this:

> > Dim opt As RadioButton = CType(sender, RadioButton)
> > Me.grpCompareField.Enabled = Not (opt.Name = "optStrings")

> > I replaced it by this:

> > Me.grpCompareField.Enabled = Not optStrings.Checked

> > and it works fine.Why use the dim sentence ?



Mon, 02 May 2005 08:31:16 GMT  
 what's the difference
You could use the txtLength control name in that case as you say, but if the
code was to be requiered to handle events from additional controls at a
later date, then the code would need to be changed. It would probably be
better form to use the DirectCast(sender, ***) format consistently.

To format a number into a string with leading zeros you could do the
following...

Dim intNum As Integer = 3

MessageBox.Show(intNum.ToString.Format("{0:0000}", intNum))

The 0: represents a field index (0 based) corresponding to the list of
values at the end of the method parameter list, the 0000 following it
represents the format. You could also do the following...

Dim intQty As Integer = 3
Dim dblCost As Double = 7.99

MessageBox.Show(intQty.ToString.Format("{0:00} item(s) were ordered at a
price of {1:c} each.", intQty, dblCost))


Quote:
> After seeing the code again, and based upon your explanation, I understand
> this:
> Private Sub CompareKeyCheckedChanged(ByVal sender As System.Object, ByVal
e
> As System.EventArgs) Handles optId.CheckedChanged, optName.CheckedChanged

> Dim opt As RadioButton = CType(sender, RadioButton)

> .....

> because it really handles 2 events

> But what about this:

> .

> Private Sub txtLength_Validating(ByVal sender As Object, ByVal e As
> System.ComponentModel.CancelEventArgs) Handles txtLength.Validating

> Dim txt As TextBox = CType(sender, TextBox)

> here we should simply use the properties of txtLength ..Am I right ?

> BTW: another question (I'm experienced in other languages but newbie in
VB):

> How do we format an integer to pad it with zeroes on its left? (ex:
3 ---->
> 0003)

> Thank you in advance.

> .

> ----- Original Message -----

> Newsgroups: microsoft.public.dotnet.languages.vb
> Sent: Thursday, November 14, 2002 3:54 AM
> Subject: Re: what's the difference

> > It is because the same piece of code can be used to handle more than one
> > event and from more than one control. The 'sender' parameter then
becomes
> > key to the code within as a means of identifying which control is firing
> the
> > event.



> > >   hi.
> > > In one of the examples made by Microsoft about arrays, I found this:

> > > Dim opt As RadioButton = CType(sender, RadioButton)
> > > Me.grpCompareField.Enabled = Not (opt.Name = "optStrings")

> > > I replaced it by this:

> > > Me.grpCompareField.Enabled = Not optStrings.Checked

> > > and it works fine.Why use the dim sentence ?



> > It is because the same piece of code can be used to handle more than one
> > event and from more than one control. The 'sender' parameter then
becomes
> > key to the code within as a means of identifying which control is firing
> the
> > event.



> > >   hi.
> > > In one of the examples made by Microsoft about arrays, I found this:

> > > Dim opt As RadioButton = CType(sender, RadioButton)
> > > Me.grpCompareField.Enabled = Not (opt.Name = "optStrings")

> > > I replaced it by this:

> > > Me.grpCompareField.Enabled = Not optStrings.Checked

> > > and it works fine.Why use the dim sentence ?



Tue, 03 May 2005 16:59:17 GMT  
 what's the difference
Thank you very much .Good explanation.


Quote:
> You could use the txtLength control name in that case as you say, but if
the
> code was to be requiered to handle events from additional controls at a
> later date, then the code would need to be changed. It would probably be
> better form to use the DirectCast(sender, ***) format consistently.

> To format a number into a string with leading zeros you could do the
> following...

> Dim intNum As Integer = 3

> MessageBox.Show(intNum.ToString.Format("{0:0000}", intNum))

> The 0: represents a field index (0 based) corresponding to the list of
> values at the end of the method parameter list, the 0000 following it
> represents the format. You could also do the following...

> Dim intQty As Integer = 3
> Dim dblCost As Double = 7.99

> MessageBox.Show(intQty.ToString.Format("{0:00} item(s) were ordered at a
> price of {1:c} each.", intQty, dblCost))



> > After seeing the code again, and based upon your explanation, I
understand
> > this:
> > Private Sub CompareKeyCheckedChanged(ByVal sender As System.Object,
ByVal
> e
> > As System.EventArgs) Handles optId.CheckedChanged,

optName.CheckedChanged

- Show quoted text -

Quote:

> > Dim opt As RadioButton = CType(sender, RadioButton)

> > .....

> > because it really handles 2 events

> > But what about this:

> > .

> > Private Sub txtLength_Validating(ByVal sender As Object, ByVal e As
> > System.ComponentModel.CancelEventArgs) Handles txtLength.Validating

> > Dim txt As TextBox = CType(sender, TextBox)

> > here we should simply use the properties of txtLength ..Am I right ?

> > BTW: another question (I'm experienced in other languages but newbie in
> VB):

> > How do we format an integer to pad it with zeroes on its left? (ex:
> 3 ---->
> > 0003)

> > Thank you in advance.

> > .

> > ----- Original Message -----

> > Newsgroups: microsoft.public.dotnet.languages.vb
> > Sent: Thursday, November 14, 2002 3:54 AM
> > Subject: Re: what's the difference

> > > It is because the same piece of code can be used to handle more than
one
> > > event and from more than one control. The 'sender' parameter then
> becomes
> > > key to the code within as a means of identifying which control is
firing
> > the
> > > event.



> > > >   hi.
> > > > In one of the examples made by Microsoft about arrays, I found this:

> > > > Dim opt As RadioButton = CType(sender, RadioButton)
> > > > Me.grpCompareField.Enabled = Not (opt.Name = "optStrings")

> > > > I replaced it by this:

> > > > Me.grpCompareField.Enabled = Not optStrings.Checked

> > > > and it works fine.Why use the dim sentence ?



> > > It is because the same piece of code can be used to handle more than
one
> > > event and from more than one control. The 'sender' parameter then
> becomes
> > > key to the code within as a means of identifying which control is
firing
> > the
> > > event.



> > > >   hi.
> > > > In one of the examples made by Microsoft about arrays, I found this:

> > > > Dim opt As RadioButton = CType(sender, RadioButton)
> > > > Me.grpCompareField.Enabled = Not (opt.Name = "optStrings")

> > > > I replaced it by this:

> > > > Me.grpCompareField.Enabled = Not optStrings.Checked

> > > > and it works fine.Why use the dim sentence ?



Tue, 03 May 2005 04:23:02 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. what's the difference...(chr(13)) and vbCr

2. What's the difference between ....

3. What's the difference between .Send and .Save

4. What's the difference

5. what's the difference

6. In this case, what's the difference between CSharp and VB.NET Exception Handling

7. Where's the difference

8. What's the difference?

9. What's the difference

10. OCX vs DLL: what's the difference ?

11. what's the difference?

12. Join and Where: What's the difference?

 

 
Powered by phpBB® Forum Software