how to keep changing the background image of mdi form? - vb6

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.

Related

Disable VB6 Timer during updates

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

vb6 listbox list timer

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.

Display pictures from a folder in the cente of full screen

I have two groups of pictures saved in two folders. I want the program to display theses pictures randomly in center of full screen form. I am trying to do this with visual basic.
Private Sub VScroll1_Change()
End Sub
Private Sub Command1_Click()
Form2.Show
Form1.Hide
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
End Sub
Private Sub Timer1_Timer()
If Interval > 0 Then
Timer1.Enabled = True
Else
Timer1.Enabled = False
Form2.Hide
End
End If
End Sub
If you are using Image control to display the picture and if your Image control name is "Image1", Then you can use the following to reposition your image in center every time you change the picture.
Image1.Left = (Me.ScaleWidth - Image1.Width) / 2
Image1.Top = (Me.ScaleHeight - Image1.Height) / 2
The following are added:
You have to place a FileListBox control in your form and name it f
Dim folder As String
Dim n As Integer
Private Sub Timer1_Timer()
n = Rnd() * f.ListCount
Image1.Picture = LoadPicture(folder & "\" & f.List(n))
Image1.Left = (Me.ScaleWidth - Image1.Width) / 2
Image1.Top = (Me.ScaleHeight - Image1.Height) / 2
End Sub
Private Sub Form_Load()
folder = "D:\VLTR"
f.Visible = False
f.Pattern = "*.jpg"
f.Path = folder
End Sub

Will I be able to make progress bar repeat every time in vb6?

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

vb6 check if multiple timers

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

Resources