|
-
Jun 30th, 2005, 02:47 AM
#1
Thread Starter
Member
Can Anyone help in this set of codes?
Hi there.
I have done up a set of codes to view photos/ pictures. The program is working well but, there are some errors. I suspect that it is the logic problem.
Can anyone help to solve it?
Here's some parts of the codes:
Public FileIndex As Integer
'Public FileIndexx As Integer
Public ImageFiles() As FileInfo
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim DirObj As New DirectoryInfo("C:\Documents and Settings\project\My Documents\My Pictures")
ImageFiles = DirObj.GetFiles("*.jpg")
'If ImageFiles.Length = 0 Then
'Me.Close()
'Else
If ImageFiles.Length = 1 Then
'Button1.Text = "Done"
'Else
btnNext.Text = "Next"
End If
FileIndex = 0
Dim MyImage As Image
Try
MyImage = Image.FromFile(ImageFiles(FileIndex).FullName, RichTextBoxStreamType.PlainText)
PicBox().Image = Image.FromFile(ImageFiles(FileIndex).FullName, RichTextBoxStreamType.PlainText)
Catch Ex As Exception
End Try
Me.Text = ImageFiles(FileIndex).FullName
'End If
End Sub
Private Sub open_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles open.Click
Dim open As OpenFileDialog = New OpenFileDialog
open.Title = "Select the image to open."
open.Filter = ("Supported Files|*.gif;*.jpg;*.bmp")
open.ShowDialog()
Dim theImage As New Bitmap(open.FileName)
PicBox.Image = theImage
End Sub
Private Sub rotate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rotate.Click
PicBox.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
PicBox.Refresh()
End Sub
Private Sub exitleft_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitleft.Click
Close()
End Sub
Private Sub btnPre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPre.Click
FileIndex = FileIndex - 1
If FileIndex = ImageFiles.Length Then
Me.Close()
Else
If FileIndex = (ImageFiles.Length + 1) Then
btnPre.Text = "Done"
End If
Dim MyImage As Image
Try
MyImage = Image.FromFile(ImageFiles(FileIndex).FullName, RichTextBoxStreamType.PlainText)
PicBox().Image = Image.FromFile(ImageFiles(FileIndex).FullName, RichTextBoxStreamType.PlainText)
Catch Ex As Exception
End Try
'Me.Text = ImageFiles(FileIndex).FullName
End If
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
FileIndex = FileIndex + 1
If FileIndex = ImageFiles.Length Then
Me.Close()
Else
If FileIndex = (ImageFiles.Length - 1) Then
'btnNext.Text = "Done"
btnNext.Text = "Next"
End If
Dim MyImage As Image
Try
MyImage = Image.FromFile(ImageFiles(FileIndex).FullName, RichTextBoxStreamType.PlainText)
PicBox().Image = Image.FromFile(ImageFiles(FileIndex).FullName, RichTextBoxStreamType.PlainText)
Catch Ex As Exception
End Try
'Me.Text = ImageFiles(FileIndex).FullName
End If
End Sub
Thanks so much!
Last edited by longdexin; Jul 12th, 2005 at 01:07 AM.
-
Jun 30th, 2005, 03:26 AM
#2
Re: Can Anyone help in this set of codes?
That's a fair bit of code. You can't expect us to just read it all and know what the issues are. I'd suggest you put it in [Highlight=VB] tags to make it more readable and then tell us what the issues are and where they occur.
-
Jun 30th, 2005, 04:14 AM
#3
Frenzied Member
Re: Can Anyone help in this set of codes?
Here you go
VB Code:
Public FileIndex As Integer
'Public FileIndexx As Integer
Public ImageFiles() As FileInfo
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim DirObj As New DirectoryInfo("C:\Documents and Settings\project\My Documents\My Pictures")
ImageFiles = DirObj.GetFiles("*.jpg")
'If ImageFiles.Length = 0 Then
'Me.Close()
'Else
If ImageFiles.Length = 1 Then
'Button1.Text = "Done"
'Else
btnNext.Text = "Next"
End If
FileIndex = 0
Dim MyImage As Image
Try
MyImage = Image.FromFile(ImageFiles(FileIndex).FullName, RichTextBoxStreamType.PlainText)
PicBox().Image = Image.FromFile(ImageFiles(FileIndex).FullName, RichTextBoxStreamType.PlainText)
Catch Ex As Exception
End Try
Me.Text = ImageFiles(FileIndex).FullName
'End If
End Sub
Private Sub open_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles open.Click
Dim open As OpenFileDialog = New OpenFileDialog
open.Title = "Select the image to open."
open.Filter = ("Supported Files|*.gif;*.jpg;*.bmp")
open.ShowDialog()
Dim theImage As New Bitmap(open.FileName)
PicBox.Image = theImage
End Sub
Private Sub rotate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rotate.Click
PicBox.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
PicBox.Refresh()
End Sub
Private Sub exitleft_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitleft.Click
Close()
End Sub
Private Sub btnPre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPre.Click
FileIndex = FileIndex - 1
If FileIndex = ImageFiles.Length Then
Me.Close()
Else
If FileIndex = (ImageFiles.Length + 1) Then
btnPre.Text = "Done"
End If
Dim MyImage As Image
Try
MyImage = Image.FromFile(ImageFiles(FileIndex).FullName, RichTextBoxStreamType.PlainText)
PicBox().Image = Image.FromFile(ImageFiles(FileIndex).FullName, RichTextBoxStreamType.PlainText)
Catch Ex As Exception
End Try
'Me.Text = ImageFiles(FileIndex).FullName
End If
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
FileIndex = FileIndex + 1
If FileIndex = ImageFiles.Length Then
Me.Close()
Else
If FileIndex = (ImageFiles.Length - 1) Then
'btnNext.Text = "Done"
btnNext.Text = "Next"
End If
Dim MyImage As Image
Try
MyImage = Image.FromFile(ImageFiles(FileIndex).FullName, RichTextBoxStreamType.PlainText)
PicBox().Image = Image.FromFile(ImageFiles(FileIndex).FullName, RichTextBoxStreamType.PlainText)
Catch Ex As Exception
End Try
'Me.Text = ImageFiles(FileIndex).FullName
End If
End Sub
-
Jun 30th, 2005, 04:18 AM
#4
Re: Can Anyone help in this set of codes?
-
Jun 30th, 2005, 08:54 PM
#5
Thread Starter
Member
Re: Can Anyone help in this set of codes?
Sorry for posting that junk of codes the other time. Anyway, juz to give you a little background of the project.
Basically, this project is to write a program that can be able to view pictures. This program will be constantly connected to the server and when server is sending information (which is the pictures), the program shld be able to show the pictures. There will be a 'Next' and 'Previous' Button and navigate the pictures.
The codes below is able to show next and previous pictures within the folder. However, there's some logic error. I'm not so sure of wad went wrong, so decided to post the set of codes to this forum to see if anyone could help.
Sorry for the trouble and thanks for helpin out. 
Here's the Next button codes:
VB Code:
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
FileIndex = FileIndex + 1
If FileIndex = ImageFiles.Length Then
Me.Close()
Else
If FileIndex = (ImageFiles.Length - 1) Then
'btnNext.Text = "Done"
btnNext.Text = "Next"
End If
Dim MyImage As Image
Try
MyImage = Image.FromFile(ImageFiles(FileIndex).FullName, RichTextBoxStreamType.PlainText)
PicBox().Image = Image.FromFile(ImageFiles(FileIndex).FullName, RichTextBoxStreamType.PlainText)
Catch Ex As Exception
End Try
Me.Text = ImageFiles(FileIndex).FullName
End If
End Sub
Here's the Previous button codes:
VB Code:
Private Sub btnPre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPre.Click
FileIndex = FileIndex - 1
If FileIndex = ImageFiles.Length Then
Me.Close()
Else
If FileIndex = (ImageFiles.Length + 1) Then
btnPre.Text = "Done"
End If
Dim MyImage As Image
Try
MyImage = Image.FromFile(ImageFiles(FileIndex).FullName, RichTextBoxStreamType.PlainText)
PicBox().Image = Image.FromFile(ImageFiles(FileIndex).FullName, RichTextBoxStreamType.PlainText)
Catch Ex As Exception
End Try
Me.Text = ImageFiles(FileIndex).FullName '<---- The error occur here
End If
End Sub
I would oso like to ask on how to implement a loop method. If there are 5 picture files, when i click on the next button till the 5th picture, it shld be able to continue to loop back to the 1st picture and so on.
-
Jun 30th, 2005, 09:05 PM
#6
Re: Can Anyone help in this set of codes?
As to the loop you mention, for the Next button use:
VB Code:
FileIndex += 1
If FileIndex = ImageFiles.Length Then
FileIndex = 0
End If
and for the Previous button use:
VB Code:
FileIndex -= 1
If FileIndex = -1 Then
FileIndex = ImageFile.Length - 1
End If
As for the error you are getting, I'd say it's because you are testing for "FileIndex = ImageFiles.Length" and "FileIndex = (ImageFiles.Length + 1)" when the Previous button is clicked instead of "FileIndex = -1" and "FileIndex = 0". You are decrementing the FileIndex variable to the lower bound of the array, remember.
-
Jun 30th, 2005, 11:39 PM
#7
Thread Starter
Member
Re: Can Anyone help in this set of codes?
jmcilhinney,
thanks alot man. i trying the code and it works but still editing some of the codes.
-
Jul 12th, 2005, 01:05 AM
#8
Thread Starter
Member
Re: Can Anyone help in this set of codes?
once again thanks alot to all u guys... the loop is working[resloved]
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
|