sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
WindAndWaves's Avatar

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
Trevor Best's Avatar
Guest - n/a Posts
#2: Re: good syntax with if statements

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
 
Not the answer you were looking for? Post your question . . .
196,909 members ready to help you find a solution.
Join Bytes.com

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.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors