|
-
Aug 5th, 2000, 06:01 PM
#1
Thread Starter
Fanatic Member
Hi everyone.
Why does the following code work for the Timer and not for the Command button? The code that they contain is exactly the same! (except for the If statement to disable the Timer control.)
Code:
Option Explicit
Private Sub Command1_Click()
Static I As Integer
If ListView1.ListItems(1).Selected = True Then I = 1
I = I + 1
If I = ListView1.ListItems.count Then Command1.Enabled = False
ListView1.ListItems(I).Selected = True
End Sub
Private Sub Form_Load()
ListView1.ListItems.Add , , "one"
ListView1.ListItems.Add , , "two"
ListView1.ListItems.Add , , "three"
End Sub
Private Sub Timer1_Timer()
Static I As Integer
If ListView1.ListItems(1).Selected = True Then I = 1
I = I + 1
If I = ListView1.ListItems.count Then Timer1.Enabled = False
ListView1.ListItems(I).Selected = True
End Sub
Thx.
-
Aug 5th, 2000, 06:31 PM
#2
I don't know what your goal is so it's hard to interpret what you mean when you say that the Timer1 routine "works". That routine will be executed serveral times quite rapidly (depending on your Interval) setting, so it's "I" Static variable will very quickly reach 3 and the Timer will be shut off since "I" will be 3.
The Command1_Click routine will stay enabled for 3 clicks of the command button, unless the "Two" entry is clicked. If that happens "I" gets set back to one.
What is it that you want to have happen?
-
Aug 5th, 2000, 06:32 PM
#3
Hi,
I am not sure what you mean by the code works for timer and not for command button.
When i run your code it selects the list view item one after another.
If your are trying this with a command button then the code will be different as the value of I is not changing so ur code will only select the first item.
In the case of timer the code will be executed three times and thus it will select all there items one after another.
Hope this makes any sense.
Danial
-
Aug 5th, 2000, 09:52 PM
#4
Thread Starter
Fanatic Member
Thanks for the responses ...
But I see that I didn't explain myself clearly enough.
In order to understand my question. Run the code I provided with the Timer enabled and watch what happens. Then, run the code with the Timer disabled and use the Command button to cycle through the listview items.
You'll see that with the timer, the items are highlighted one after the other, when it fires. But when you click on the command button 3 times, which contains basically the same code as the Timer, the items are NOT highlighted. This is what I don't understand.
Anyone have any ideas why?
Thx.
-
Aug 5th, 2000, 10:20 PM
#5
Code:
Private Sub Command1_Click()
Static I As Integer
I = I + 1
'If ListView1.ListItems(1).Selected = True Then I = 1
If I = ListView1.ListItems.Count Then Command1.Enabled = False
ListView1.ListItems(I).Selected = True
ListView1.SetFocus
End Sub
The highlighting doesn't happen until the ListView has the focus. The reason that it works for the timer is that the ListView never loses focus, whereas when you click Command1, the ListView, of course, loses focus, so you have to set it back.
-
Aug 5th, 2000, 10:58 PM
#6
Thread Starter
Fanatic Member
Thx.
I should have known it was something simple. But sometimes you can't see something, even if it is staring you in the face!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|