Results 1 to 19 of 19

Thread: [RESOLVED] Simple Image Gallery in VB 2010

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2014
    Posts
    10

    Resolved [RESOLVED] Simple Image Gallery in VB 2010

    Hi,

    First off, I am pretty useless at programming as I am quite new to it but have to do a computing project for college. Although it won't get me any extra marks, I'm wanting to add an image gallery so that he user can upload an image so that multiple images can be seen on one page.

    After searching the internet, I found this link which is pretty much the perfect thing that I want. http://www.authorcode.com/image-gallery-in-vb-net/

    I have tried to follow these instructions but many errors have come up which I don't know how to fix. I have included the screenshots of the errors below.

    Name:  Gallery Errors.jpg
Views: 2962
Size:  34.4 KB

    If anyone has any ideas how to fix these errors or any alternate methods, I would be very grateful if you could give me some advice.

    Thanks in advance

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Simple Image Gallery in VB 2010

    Post your code + details of errors + which line the error refers to

  3. #3
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Simple Image Gallery in VB 2010

    Screenshot is too small, cant read anything
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Simple Image Gallery in VB 2010

    When posting code use [Code]'your code here[/Code] tags, + it'll format like this:

    Code:
    'your code here

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2014
    Posts
    10

    Re: Simple Image Gallery in VB 2010

    Not sure if this will look right but here goes. I have tried to underline where all the errors have appeared.
    This is the code for Form 1 ............

    Code:
    'Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim dlg As New FolderBrowserDialog
            If dlg.ShowDialog = DialogResult.OK Then
                AuthorCodeImageGalleryVB1.Directorypath = dlg.SelectedPath
                TextBox1.Text = dlg.SelectedPath
            End If
        End Sub
    End Class


    This is the code for the User Control

    Code:
    'Public Class AuthorCodeImageGalleryVB
        Dim CtrlWidth As Integer
        Dim CtrlHeight As Integer
        Dim PicWidth As Integer
        Dim PicHeight As Integer
        Dim XLocation As Integer
        Dim YLocation As Integer
    
        Private Sub AuthorCodeImageGalleryVB_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
            CtrlHeight = Me.Height
            CtrlWidth = Me.Width
        End Sub
        Private _Directory_Path As String
        Public Property Directorypath() As String
            Get
                Return _Directory_Path
            End Get
            Set(ByVal value As String)
    
                _Directory_Path = value
                XLocation = 25
                YLocation = 25
                PicWidth = 117
                PicHeight = 109
                CreateGallery()
            End Set
        End Property
        Dim i As Integer = 0
    
        Private Sub DrawPictureBox(ByVal _filename As String, ByVal _displayname As String)
            Dim Pic1 As New PictureBox
            Pic1.Location = New System.Drawing.Point(XLocation, YLocation)
            XLocation = XLocation + PicWidth + 20
            If XLocation + PicWidth >= CtrlWidth Then
                XLocation = 25
                YLocation = YLocation + PicHeight + 20
            End If
            Pic1.Name = "PictureBox" & i
            i += 1
            Pic1.Size = New System.Drawing.Size(PicWidth, PicHeight)
            Pic1.TabIndex = 0
            Pic1.TabStop = False
            Pic1.BorderStyle = BorderStyle.Fixed3D
            Me.ToolTip1.SetToolTip(Pic1, _displayname)
            AddHandler Pic1.MouseEnter, AddressOf Pic1_MouseEnter
            AddHandler Pic1.MouseLeave, AddressOf Pic1_MouseLeave
            Me.Controls.Add(Pic1)
            Pic1.Image = Image.FromFile(_filename)
            Pic1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        End Sub
    
        Private Sub CreateGallery()
            i = 0
            RemoveControls()
            If Directorypath IsNot Nothing Then
                Dim di As New IO.DirectoryInfo(Directorypath)
                Dim diar1 As IO.FileInfo() = di.GetFiles("*.jpg").Concat(di.GetFiles("*.bmp")).Concat(di.GetFiles("*.png")).Concat(di.GetFiles("*.gif")).ToArray
                Dim dra As IO.FileInfo
                For Each dra In diar1
                    DrawPictureBox(dra.FullName, dra.Name)
                Next
            End If
        End Sub
    
        Private Sub Pic1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim Pic As PictureBox
            Pic = sender
            Pic.BorderStyle = BorderStyle.FixedSingle
        End Sub
    
        Private Sub Pic1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim Pic As PictureBox
            Pic = sender
            Pic.BorderStyle = BorderStyle.Fixed3D
        End Sub
    
        Private Sub RemoveControls()
    Again:  For Each ctrl As Control In Me.Controls
                If TypeOf (ctrl) Is PictureBox Then
                    Me.Controls.Remove(ctrl)
                End If
            Next
            If Me.Controls.Count > 0 Then
                GoTo Again
            End If
        End Sub
    End Class


    These are the errors that have appeared (sorry they will be really hard to understand as I'm copy and pasting them)

    Error 1 'AuthorCodeImageGalleryVB1' is not declared. It may be inaccessible due to its protection level. Form1.vb 5 13 WindowsApplication1

    Error 2 'gt' is not declared. It may be inaccessible due to its protection level. UserControl1.vb 33 34 WindowsApplication1

    Error 3 Character is not valid. UserControl1.vb 33 36 WindowsApplication1

    Error 4 'amp' is not declared. It may be inaccessible due to its protection level. UserControl1.vb 37 35 WindowsApplication1

    Error 5 Character is not valid. UserControl1.vb 37 38 WindowsApplication1

    Error 6 'ToolTip1' is not a member of 'WindowsApplication1.AuthorCodeImageGalleryVB'. UserControl1.vb 43 9 WindowsApplication1

    Error 7 'gt' is not declared. It may be inaccessible due to its protection level. UserControl1.vb 79 31 WindowsApplication1

    Error 8 Character is not valid. UserControl1.vb 79 33 WindowsApplication1

  6. #6
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Simple Image Gallery in VB 2010

    The first error is clear, there is no 'AuthorCodeImageGalleryVB1' , what is it that you want to reference by that name?
    line 33 of your User Control is strange, shet does >= mean? apparently gt has not been declared and it is mixed with other characters that have no place there.
    Same in 37... & I what does that mean?
    It does not appear to by a typo, you have that 3 times, line 79 again > ????
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Simple Image Gallery in VB 2010

    1/ AuthorCodeImageGalleryVB1 is the name of the usercontrol instance on the form
    2/ change this:

    Code:
    If XLocation + PicWidth >= CtrlWidth Then
    to this:

    Code:
    If XLocation + PicWidth >= CtrlWidth Then
    3/ change this:

    Code:
    Pic1.Name = "PictureBox" & i
    to this:

    Code:
    Pic1.Name = "PictureBox" & i.tostring
    4/ see #3

    5/ see #3

    6/ add a ToolTip component to your usercontrol (from the toolbox)

    7/ change this:

    Code:
    If Me.Controls.Count > 0 Then
    to this:

    Code:
    If Me.Controls.Count > 0 Then
    8/ see #7

  8. #8
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Simple Image Gallery in VB 2010

    Why is that .paul.? what does > mean?
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  9. #9

    Thread Starter
    New Member
    Join Date
    Feb 2014
    Posts
    10

    Re: Simple Image Gallery in VB 2010

    Kaliman, like I said, I'm rubbish at all this programming so the code I sent is all copy and pasted from the link that I sent in the first post.

    I would have thought that 'AuthorCodeImageGallery1' should be 'AuthorCodeImageGalleryVB' (without the 1) as this is the name of the User Control. However when I change this to this 'AuthorCodeImageGalleryVB.Directorypath', the whole thing is underlined in blue with this error appearing.....

    'Error 1 Reference to a non-shared member requires an object reference. Form1.vb 5 13 WindowsApplication1'


    Also, I would agree that 'gt;' and amp; seem strange but I presumed there was a purpose to this even though I too don't understand what it means. If you take a look at the link I sent, it might explain what I'm doing wrong better than a useless programmer like me.

    Thanks

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Simple Image Gallery in VB 2010

    Quote Originally Posted by kaliman79912 View Post
    Why is that .paul.? what does > mean?
    it's html markup for >

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Simple Image Gallery in VB 2010

    AuthorCodeImageGalleryVB1 is the name of an instance of AuthorCodeImageGalleryVB (a Type) on your form

  12. #12

    Thread Starter
    New Member
    Join Date
    Feb 2014
    Posts
    10

    Re: Simple Image Gallery in VB 2010

    .Paul.

    Thanks so much, that has really helped, I've done everything you said and the only error that still appears is the one to do with 'AuthorCodeImageGalleryVB1'. Am I meant to change this to something else? I've tried changing it to 'AuthorCodeImageGalleryVB' but a different error occurs when I drop the '1' saying......

    'Error 1 Reference to a non-shared member requires an object reference. Form1.vb 5 13 WindowsApplication1'

  13. #13
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Simple Image Gallery in VB 2010

    comment that line out + start, then stop your project. remove the comment, goto form view, then at the top of your toolbox, you'll find the AuthorCodeImageGalleryVB control. add one to your form + rebuild (run) your project

  14. #14
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    774

    Re: Simple Image Gallery in VB 2010

    Quote Originally Posted by LittleCasino View Post
    .Paul.

    Thanks so much, that has really helped, I've done everything you said and the only error that still appears is the one to do with 'AuthorCodeImageGalleryVB1'. Am I meant to change this to something else? I've tried changing it to 'AuthorCodeImageGalleryVB' but a different error occurs when I drop the '1' saying......

    'Error 1 Reference to a non-shared member requires an object reference. Form1.vb 5 13 WindowsApplication1'
    Just add an instance of the control on Form 1. Try this:

    Code:
    Public Class Form1
    
    Dim AuthorCodeImageGalleryVB1 as new AuthorCodeImageGalleryVB
    
    ' Rest of Form1 code starts here ...

  15. #15

    Thread Starter
    New Member
    Join Date
    Feb 2014
    Posts
    10

    Re: Simple Image Gallery in VB 2010

    Oooooh, I see what you mean, I didn't realise you had to drag it into your form. Are you meant to only put one in or are you meant to drag multiple user controls in to have more than one image?

    At the moment, I can add an image but when I add another image, it just replaces the previous one.

  16. #16
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Simple Image Gallery in VB 2010

    I haven't tried it, but by the look of the code, it should display all of the images in the folder you select.

  17. #17

    Thread Starter
    New Member
    Join Date
    Feb 2014
    Posts
    10

    Re: Simple Image Gallery in VB 2010

    .Paul.

    Aha, I made the user control a bit bigger and it has included all the images.

    Thanks so much for the help Paul, I've been trying to do this for weeks!!! I really appreciate it!!!! Thank you! Thank you! Thank you!!!!!!!

  18. #18
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Simple Image Gallery in VB 2010

    no problem. glad I could help...

  19. #19
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: [RESOLVED] Simple Image Gallery in VB 2010

    Do you not agree handing in course work you can't understand, did not write will actually look worse on you?
    My Github - 1d3nt

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width