Can this be shortened? 
Author Message
 Can this be shortened?

Is there a way to shorten this line of code?

If Me.ActiveControl.Name = "dgPaid" Or  Me.ActiveControl.Name = "dgHours"
Then

'blah blah

End If

To something like If Me.ActiveControl.Name = "dgPaid, or "dgHours" then ...



Tue, 20 Sep 2005 05:56:57 GMT  
 Can this be shortened?
No.

If you're worried about typing, you could use the With statement.

Erik Porter
Microsoft .NET MVP
http://www.windowsforms.net


Quote:
> Is there a way to shorten this line of code?

> If Me.ActiveControl.Name = "dgPaid" Or  Me.ActiveControl.Name = "dgHours"
> Then

> 'blah blah

> End If

> To something like If Me.ActiveControl.Name = "dgPaid, or "dgHours" then
...



Tue, 20 Sep 2005 06:12:33 GMT  
 Can this be shortened?
Hello Woody,


Quote:
> Is there a way to shorten this line of code?

> If Me.ActiveControl.Name = "dgPaid" Or  Me.ActiveControl.Name =
"dgHours"
> Then

Code written from scratch (untested):

\\\
Select Case Me.ActiveControl.Name
    Case "dgPaid", "dgHours"
        Bla()
    Case "..."
        ...
    Case Else
        ...
End Select
///

-- or --

\\\
If IsStringInSet(Me.ActiveControl.Name, "dgMain", "dgSelect") Then
    ...
End If
.
.
.
Private Function IsStringInSet( _
    ByVal str As String, _
    ByVal ParamArray astrSet() As String _
) As Boolean
    Dim i As Integer
    For i = 0 To astrSet.GetUpperBound(0)
        If astrSet(i) <> str Then
            Return False
        End If
    Next i
    Return True
End Function
///

Regards,
Herfried K. Wagner



Tue, 20 Sep 2005 06:15:24 GMT  
 Can this be shortened?

Quote:
> Private Function IsStringInSet( _
>     ByVal str As String, _
>     ByVal ParamArray astrSet() As String _
> ) As Boolean
>     Dim i As Integer
>     For i = 0 To astrSet.GetUpperBound(0)
>         If astrSet(i) <> str Then
>             Return False
>         End If
>     Next i
>     Return True
> End Function
> ///

Sorry for correction:  ;)

Private Function IsStringInSet( _
    ByVal str As String, _
    ByVal ParamArray astrSet() As String _
) As Boolean
    Dim i As Integer
    For i = 0 To astrSet.GetUpperBound(0)
        If astrSet(i) = str Then
            Return True
        End If
    Next i
End Function

Or:
   Private Function IsStringInSet( _
     ByVal str As String, _
     ByVal ParamArray astrSet() As String _
     ) As Boolean
      Return Array.IndexOf(astrSet, str) > -1
   End Function

--
Armin



Tue, 20 Sep 2005 06:38:28 GMT  
 Can this be shortened?
Hello Armin,


Quote:
> Sorry for correction:  ;)

Thanks for correction. It's late in Austria.

;-)

Regards,
Herfried K. Wagner



Tue, 20 Sep 2005 06:47:44 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. How do I create a canned form?

2. Canned AcctReceivable Module needed!

3. Canned pages....

4. Cans access2.0 engine access btrieve files?

5. Crystal Reports Canned Code

6. Canned objects and/or images

7. Switching from inhouse software to canned package.

8. line graph in vb (canned routine)

9. 'Canned' data in VB program

10. Looking 4 Canned Control

11. Shorten Subject Text for Journal Entry

12. How to shorten the LogOn() execution time?

 

 
Powered by phpBB® Forum Software