By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,644 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

good syntax with if statements

P: n/a
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???
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
WindAndWaves wrote:
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???

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
Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.