PDA

View Full Version : picturebox & vb timer


hiddenbox
08-31-2010, 12:53 AM
I am trying to get the image in picturebox1 to change at certain times. I'm using vb 2010.

I have been working on this for 8 hours and just tried to debug it and it doesn't work. :mad:

Here is a part of my code. The code goes on for 2000 lines. I will show what I have for month 1 (january).


If season.Month = 1 Then
If season.Hour >= 0 Then
If season.Minute >= 0 Then
PictureBox1.Image = My.Resources.time_1_
End If
End If
If season.Hour >= 3 Then
If season.Minute >= 10 Then
PictureBox1.Image = My.Resources.time_2_
End If
End If
If season.Hour >= 6 Then
If season.Minute >= 20 Then
PictureBox1.Image = My.Resources.time_3_
End If
End If
If season.Hour >= 7 Then
If season.Minute >= 12 Then
PictureBox1.Image = My.Resources.time_5_
End If
End If
If season.Hour >= 7 Then
If season.Minute >= 41 Then
PictureBox1.Image = My.Resources.time_7_
End If
End If
If season.Hour >= 8 Then
If season.Minute >= 29 Then
PictureBox1.Image = My.Resources.time_8_
End If
End If
If season.Hour >= 10 Then
If season.Minute >= 30 Then
PictureBox1.Image = My.Resources.time_9_
End If
End If
If season.Hour >= 12 Then
If season.Minute >= 0 Then
PictureBox1.Image = My.Resources.time_15_
End If
End If
If season.Hour >= 12 Then
If season.Minute >= 29 Then
PictureBox1.Image = My.Resources.time_10_
End If
End If
If season.Hour >= 13 Then
If season.Minute >= 9 Then
PictureBox1.Image = My.Resources.time_11_
End If
End If
If season.Hour >= 16 Then
If season.Minute >= 1 Then
PictureBox1.Image = My.Resources.time_12_
End If
End If
If season.Hour >= 17 Then
If season.Minute >= 49 Then
PictureBox1.Image = My.Resources.time_13_
End If
End If
If season.Hour >= 18 Then
If season.Minute >= 0 Then
PictureBox1.Image = My.Resources.time_14_
End If
End If
If season.Hour >= 18 Then
If season.Minute >= 4 Then
PictureBox1.Image = My.Resources.time_16_
End If
End If
If season.Hour >= 18 Then
If season.Minute >= 9 Then
PictureBox1.Image = My.Resources.time_17_
End If
End If
If season.Hour >= 18 Then
If season.Minute >= 15 Then
PictureBox1.Image = My.Resources.time_18_
End If
End If
If season.Hour >= 18 Then
If season.Minute >= 29 Then
PictureBox1.Image = My.Resources.time_19_
End If
End If
End If

I put this in a timer_tick sub so it would update every 1 second. When I run the program I do not get any images to show. I don't get any errors.

Spookster
08-31-2010, 01:22 AM
Have you first tried just displaying an image without tying to any timer logic? Have you run this through the debugger to determine at what line of code something is failing to do what was expected?

Also your conditional logic looks like it would not be very helpful because you have seperate if statements instead of if/else if / else. A large value would make it run through each of these conditionals because if season.Hour was == to say 30 of course it would be > 0 and > 18 so it is going to go through and execute the code in each if statement.

Also an if conditional may not be the best fit for this type of logic. A select/case statement might be more appropriate for this.

And actually since you are just repeatedly incrementing the numbers in each conditional you would be better off just simplifying the code to a few lines instead of 2000 by taking advantage of patterns you have in incrementing the numbers.

Or if that is not feasible you could just create a text file containing the associations between the particular times and the images and just write a few lines of code to parse the file for the needed image name. Lots of easier ways of doing this instead of manually writing out 2000+ lines of code.