For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > April 2005 > vb6









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author vb6
tomS

2005-04-26, 8:55 pm

I have prbably a silly question but I recently wrote code to loop through 8
bitmaps and display them in an image box.the code is

Private Sub Image2_Click()
Dim index As Integer

Show Image2
For i = 0 To 8
'index = index + 1
Print i
'Show; Image2.Picture
'index = index + 1
'Image2.Visible = True
For a = 1 To 1000000
Image2 = Image1(i)
Next a
'index = index + 1
'index = index
Next i
End Sub
I made a matrix of 8 bitmaps on form and one empty image box.but for some
reason it only loops through 5 or 6 and then jumps to 8 .What am I doing
wrong.
Ken Halter

2005-04-26, 8:55 pm

"tomS" <tomS@discussions.microsoft.com> wrote in message
news:27C95C72-CB79-486C-B964-569EBB683320@microsoft.com...
>I have prbably a silly question but I recently wrote code to loop through 8
> bitmaps and display them in an image box.the code is
>
> Private Sub Image2_Click()
> Dim index As Integer
>
> Show Image2
> For i = 0 To 8
> 'index = index + 1
> Print i
> 'Show; Image2.Picture
> 'index = index + 1
> 'Image2.Visible = True
> For a = 1 To 1000000


The For loop above.... are you doing this for some kind of time delay? If
so, note that your "1000000" will take different amounts of time depending
on the CPU/RAM/etc the end user has. Also, you're assigning that image
1000000 times... no flicker? It's probably happening too fast to flicker.

> Image2 = Image1(i)
> Next a
> 'index = index + 1
> 'index = index
> Next i
> End Sub


> I made a matrix of 8 bitmaps on form and one empty image box.but for some
> reason it only loops through 5 or 6 and then jumps to 8 .What am I doing
> wrong.


If you start a new Project, drop a timer on the form (Timer1), drop an array
of 8 image controls (Image1(0-7)), another Image control (Image2) and 2
command buttons, called cmdGo and cmdStop, you should be able to see
"another way" of doing what you're trying to do.
'=============
Option Explicit

Private Sub cmdGo_Click()
Timer1.Tag = "" 'clear the "Flag"
Timer1.Enabled = True
DoEvents
cmdGo.Enabled = False
cmdStop.Enabled = True
End Sub

Private Sub cmdStop_Click()
Timer1.Tag = "STOP" 'set the "Flag"
End Sub

Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 500 '1/2 sec between pics - change this at will
Timer1.Tag = "STOP"
cmdStop.Enabled = False
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = vbFormControlMenu Then
If Timer1.Tag <> "STOP" Then
MsgBox "Click Stop first!"
Cancel = True
End If
End If
End Sub

Private Sub Timer1_Timer()
Static iElement As Integer

If Timer1.Tag = "STOP" Then
Timer1.Enabled = False
cmdGo.Enabled = True
cmdStop.Enabled = False
Else
Debug.Print "Showing image #" & iElement
Image2.Picture = Image1(iElement).Picture
iElement = iElement + 1
If iElement > Image1.UBound Then
iElement = 0
End If
End If

End Sub
'=============


--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Sign up now to help keep VB support alive - http://classicvb.org/petition
Please keep all discussions in the groups..


tomS

2005-04-27, 3:55 am



"Ken Halter" wrote:

> "tomS" <tomS@discussions.microsoft.com> wrote in message
> news:27C95C72-CB79-486C-B964-569EBB683320@microsoft.com...
>
> The For loop above.... are you doing this for some kind of time delay? If
> so, note that your "1000000" will take different amounts of time depending
> on the CPU/RAM/etc the end user has. Also, you're assigning that image
> 1000000 times... no flicker? It's probably happening too fast to flicker.
>
>
>
> If you start a new Project, drop a timer on the form (Timer1), drop an array
> of 8 image controls (Image1(0-7)), another Image control (Image2) and 2
> command buttons, called cmdGo and cmdStop, you should be able to see
> "another way" of doing what you're trying to do.
> '=============
> Option Explicit
>
> Private Sub cmdGo_Click()
> Timer1.Tag = "" 'clear the "Flag"
> Timer1.Enabled = True
> DoEvents
> cmdGo.Enabled = False
> cmdStop.Enabled = True
> End Sub
>
> Private Sub cmdStop_Click()
> Timer1.Tag = "STOP" 'set the "Flag"
> End Sub
>
> Private Sub Form_Load()
> Timer1.Enabled = False
> Timer1.Interval = 500 '1/2 sec between pics - change this at will
> Timer1.Tag = "STOP"
> cmdStop.Enabled = False
> End Sub
>
> Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
> If UnloadMode = vbFormControlMenu Then
> If Timer1.Tag <> "STOP" Then
> MsgBox "Click Stop first!"
> Cancel = True
> End If
> End If
> End Sub
>
> Private Sub Timer1_Timer()
> Static iElement As Integer
>
> If Timer1.Tag = "STOP" Then
> Timer1.Enabled = False
> cmdGo.Enabled = True
> cmdStop.Enabled = False
> Else
> Debug.Print "Showing image #" & iElement
> Image2.Picture = Image1(iElement).Picture
> iElement = iElement + 1
> If iElement > Image1.UBound Then
> iElement = 0
> End If
> End If
>
> End Sub
> '=============
>
>
> --
> Ken Halter - MS-MVP-VB - http://www.vbsight.com
> Sign up now to help keep VB support alive - http://classicvb.org/petition
> Please keep all discussions in the groups..
>
>
> Thanks that works good. There is one more thing I m tring to do and thats to be able to index each picture in the array once each time I click the image2 box,meaning click box once ,first pic,click again second pic etc.

Ken Halter

2005-04-27, 3:55 pm

"tomS" <tomS@discussions.microsoft.com> wrote in message
news:50FB33A6-24EA-4AC5-96AE-CAF23641BA46@microsoft.com...
>
> Thanks that works good. There is one more thing I m tring to do and thats
> to be able to index each picture in the array
> once each time I click the image2 box,meaning click box once ,first
> pic,click again second pic etc.


Very similar code.

> Private Sub Image1_Click(Index As Integer) 'untested air code
> Dim iElement As Integer
> iElement = Index + 1
> If iElement > Image1.UBound Then
> iElement = 0
> End If
> Debug.Print "Showing image #" & iElement
> Image2.Picture = Image1(iElement).Picture
> End If



--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Sign up now to help keep VB support alive - http://classicvb.org/petition
Please keep all discussions in the groups..


tomS

2005-04-28, 3:56 am



"Ken Halter" wrote:

> "tomS" <tomS@discussions.microsoft.com> wrote in message
> news:50FB33A6-24EA-4AC5-96AE-CAF23641BA46@microsoft.com...
>
> Very similar code.
>
>
>
> --
> Ken Halter - MS-MVP-VB - http://www.vbsight.com
> Sign up now to help keep VB support alive - http://classicvb.org/petition
> Please keep all discussions in the groups..
>
>
> I tryed code but doesn t work it only shows last pic in array

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com