good syntax with if statements
Question posted by: WindAndWaves
(Guest)
on
November 13th, 2005 01:00 AM
Hi Gurus
What is the best way to write the following code:
If REC = -1 Then
For I = 0 To Ctl.ListCount - 1
Ctl.Selected(I) = bNew
Next I
Else
For I = 0 To Ctl.ListCount - 1
If Ctl.ItemData(I) = REC Then
Ctl.Selected(I) = bNew
End If
Next I
End If
as you can see, there is some repetition in the code. How do I prevent
typing the same code twice???
1
Answer Posted
WindAndWaves wrote:
[color=blue]
> Hi Gurus
>
> What is the best way to write the following code:
>
> If REC = -1 Then
> For I = 0 To Ctl.ListCount - 1
> Ctl.Selected(I) = bNew
> Next I
> Else
> For I = 0 To Ctl.ListCount - 1
> If Ctl.ItemData(I) = REC Then
> Ctl.Selected(I) = bNew
> End If
> Next I
> End If
>
> as you can see, there is some repetition in the code. How do I prevent
> typing the same code twice???
>
>[/color]
For I = 0 To Ctl.ListCount - 1
If Ctl.ItemData(I) = REC or REC = -1 Then
Ctl.Selected(I) = bNew
End If
Next I
--
Error reading sig - A)bort R)etry I)nfluence with large hammer
|
|
|
What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 196,909 network members.
Top Community Contributors
|