i want to iterate listbox list item with Timer1 .
for example, if listbox list item have 'A','B','C'
then i want to make run 'A' then run timer1
and after finish 'B' then run timer1 and so on
maybe this is easy for someone but it not easy for me because Timer1 is continue looping
and it make me some confused.
sorry my bad english and anyone could enlight me i really much appreate!
Private Sub Command1_Click()
For xx = 0 To List3.listcount - 1
Timer1.Enabled = True
Next xx
End Sub
Public Sub Timer1_Timer()
some code....
.
.
End Sub
The Timer1_Timer() event fires every interval of the timer - so your code needs to go in there.
Something like this (untested code):
Private Sub Command1_Click()
Timer1.Enabled = True ' Start the timer
End Sub
Public Sub Timer1_Timer()
Static currentIndex = 0
' Do what you want with List1.List(currentIndex)
currentIndex = currentIndex + 1
If (currentIndex = List1.ListCount) Then
Timer1.Enabled = False ' Stop the timer
End if
End Sub
The Interval property of Timer1 controls how often Timer1_Timer() is called.
Related
How do I execute my timer1.enabled=true after TreeView FOR statement has reached the last item. My timer starts counting while the treeview is working still.
This is the code I have so far.
Private Sub Command17_Click()
Dim objRootNode As Node
Dim objChildNode As Node
Dim iRootCounter As Integer
Dim iChildCounter As Integer
Dim countt As Integer
Dim ii As Integer
For iRootCounter = 1 To TreeView2.Nodes.Count
ii = TreeView2.Nodes(iRootCounter).Index
Set objRootNode = TreeView2.Nodes(iRootCounter)
If objRootNode.Image = 4 Then
Set objChildNode = objRootNode.Child ' Gets first child
For iChildCounter = 1 To objRootNode.Children
If objChildNode.Image = 3 Then
objRootNode.Image = 9
End If
Set objChildNode = objChildNode.Next ' Get next node
Next
End If
If TreeView2.Nodes(iRootCounter).Index = TreeView2.Nodes.Count - 0 Then
If startt = True Then
Timer1.Enabled = True
Exit For
End If
End If
Next
End Sub
When I run this code, the treeview items remain in processing mode, meaning it's still doing its job changing image index for each item after I run another code, then this button gets triggered.
Just add Timer1.Enabled = False at the beginning of the TreeView update. Then, set it back to True before exiting.
Better yet, stop the timer in the Timer1_Timer event handler:
Private Sub Timer1_Timer()
' Stop timer until all code is execute
Timer1.Enabled = False
Command17_Click
' Restart timer
Timer1.Enabled = True
End Sub
I'm trying to make a voting system in visual basic 6.0 using Combo Box and Command Button.
The thing I would like to happen is when the user choose the name in the combobox and click the command button which renamed as "Submit" the number of votes will be counted and print into the Label.
So far, i only had this.
Private Sub Form_Load()
Combo1.AddItem "Jeff"
Combo1.AddItem "Gerwen"
End Sub
I guess it should be like this:
Public jeff_counter as Integer
Public gerwen_counter as Integer
Private Sub Form_Load()
Combo1.AddItem "Jeff"
Combo1.AddItem "Gerwen"
jeff_counter = 0
gerwen_counter = 0
End Sub
Private Sub Command3_Click()
if Combo1.text == "Jeff" then
jeff_counter = jeff_counter + 1
else
gerwen_counter = gerwen_counter + 1
end if
Label1.text = jeff_counter
Label2.text = gerwen_counter
End Sub
You can improve it, by using array of integer, It's been a long time since I used VB6, so maybe there is a typo..
Can I make a progress bar repeat it's loading process every time I load that page?
This is my code,
Private Sub Form_load()
Timer1.Interval = 50
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
On Error Resume Next
PBcolor ProgressBar1, vbBlue, vbGreen
ProgressBar1 = ProgressBar1 + 1
If ProgressBar1.Value = 50 Then
ProgressBar1.Value = ProgressBar1 + 50
If ProgressBar1.Value >= ProgressBar1.Max Then
Form7.Hide
form8.Show
End If
End If
ProgressBar1.Refresh
End Sub
When I run this code, the progress bar runs at first, but if I navigate to another form and come back (Without ending the program of course), it didn't run again. So could anyone suggest a solution please. Thank you.
In my VB6 apps I use UserForm_Initialize or UserForm_Initialize (Depending on versions).
Private Sub UserForm_Initialize()
ProgressBar1 = 0
'Start Progress Bar
End Sub
Your code depends on the progressbar value being less than the max value to do anything. The easiest thing you can do is just reset the value to the minimum when the form gets focus again. The Form_Activate event works well for this. Below I've formatted your original example and added the new event after your code.
Private Sub Form_load()
Timer1.Interval = 50
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
On Error Resume Next
PBcolor ProgressBar1, vbBlue, vbGreen
ProgressBar1 = ProgressBar1 + 1
If ProgressBar1.Value = 50 Then
ProgressBar1.Value = ProgressBar1 + 50
If ProgressBar1.Value >= ProgressBar1.Max Then
Form7.Hide
form8.Show
End If
End If
ProgressBar1.Refresh
End Sub
'Add this to the form with the progressbar
Private Sub Form_Activate()
ProgressBar1.Value = ProgressBar1.Min
End Sub
Use the Form_Activate() or the Form_GotFocus() event to reset your progressbar and restart loading
In my application I got few timers, timer1 too timer5. timer1 activates timer2 and so on setting the previous timer to false.
so I want to make another timer that follow these, like "timer6"
if timer1.enabled = true then 'then it should check if the timer2 now is enabled
if timer2.enabled = true then 'and so on to it reaches timer5..
Need any example to achieve this because I am at a stop point and basically just need this part to work.
my idea was just to do this in the timer6
if timer1.enabled = true then
if timer2.enabled = true then
if etc etc
else
timer6.enabled = true
timer6.enabled = false
end if
end if
end if
end sub
any ideas how to accomplish this?
So.. I am looking for a way to check all the timers are enabled in one condition and disable the last one.
I am not sure you can check al the timers at once but what you can do is to keep array of all the timers corresponding Boolean field.
array = collection[timerState{timer1,true},timerState{timer2,false}]
Then on each timer enabled/disabled event you keep this state array updated.
and lastly wherever you want you will have the state for all the timers.
have a look at the following test project
click the form to start the first timer, click the button to check which timer is active
'1 form with
' 1 timer : name=Timer1 Index=0
' 1 command button : name=Command1
Option Explicit
Private Sub Form_Load()
Dim intIndex As Integer
Timer1(0).Enabled = False
Timer1(0).Interval = 1000
For intIndex = 1 To 5
Load Timer1(intIndex)
Timer1(intIndex).Interval = intIndex * 1000
Next intIndex
End Sub
Private Sub Form_Click()
Timer1(0).Enabled = True
End Sub
Private Sub Timer1_Timer(Index As Integer)
Print CStr(Now)
Timer1(Index).Enabled = False
If Index < Timer1.Count - 1 Then
Timer1(Index + 1).Enabled = True
Else
Print "done"
End If
End Sub
Private Sub Command1_Click()
Dim intIndex As Integer
For intIndex = 0 To Timer1.Count - 1
If Timer1(intIndex).Enabled Then
Caption = "active timer : " & CStr(intIndex)
Exit For
End If
Next intIndex
End Sub
I am doing a project in vb6..i want to know how to keeping changing the background image of the MDI for as soon as it is loaded.
i tried to make an array of images and then set the timer
here is my code
Private Sub Timer1_Timer()
For i = 0 To 2
Picture1.Picture = LoadPicture(arr(i))
i = i + 1
If i = 3 Then
i = 0
End If
Next i
End Sub
Private Sub MDIForm_Load()
arr(0) = "images\Shop.jpg"
arr(1) = "images\Display1.jpg"
arr(2) = "images\Display2.jpg"
end sub
please help
thank you
Couple of issues with your code as written. First, you don't need to use a picturebox, the MDI form should have a Picture property you can set directly.
Second, as written you're cycling through all the images in your array each time the timer event fires. What you really want is one change per timer event and store/increment the array index at the end of each timer event, like so:
Private Sub Timer1_Timer()
MDIForm.Picture = LoadPicture(arr(arrIndex))
If arrIndex + 1 <= UBound(arr) Then
arrIndex = arrIndex + 1
Else
arrIndex = 0
End If
End Sub
Dim arrIndex as Integer
Private Sub MDIForm_Load()
arr(0) = "images\Shop.jpg"
arr(1) = "images\Display1.jpg"
arr(2) = "images\Display2.jpg"
arrIndex = 0
end sub
The Dim of arrIndex should be at the top of your MDIForm. This will change the background picture every time the timer event fires.