Results 1 to 7 of 7

Thread: Small desktop application. I need an experienced VB user to help me on a few points.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2012
    Location
    Newcastle
    Posts
    12

    Small desktop application. I need an experienced VB user to help me on a few points.

    VB Project
    Hi everyone,

    I am a beginner in programming but have learned the basics over the past few weeks. I want to make a small desktop application for personal use in which I will be using a text-file database. I have been told this is as basic as it gets.

    Overview
    So the basic idea of this project is to create a digital version of my record collection (music vinyl). I aim to have a form in which I can essentially 'Add New Record' which has the following details:

    - Title
    - Artist
    - Type
    - Year
    - Image

    Once the details have been uploaded and the image retrieved from My Documents, I will click 'Add New' and this will save the details in the database. I also want this 'Add New' button to store the image in a variety of different forms depending on what 'Type' was selected. For example:

    There are 4 types:

    - 12" LP/EP
    - 10" LP/EP
    - 7" Single
    - 12" Single

    Each of the above will have its own section in the application where each record will be stored. In this section will be the image used when filling in the details in the 'Add New Record' page.

    Then, I will be able to click on the picture of a record and will lead me to the final screen which shows me all the details of that particular record and the enlarged image.

    The whole idea is to get all my record collection on, I have a lot of records and forget what I have. By having this application I will be able to see the front covers of each record and view the details of that record.

    It would be a huge help if someone gave me guidance with this project. I don't think it is too challenging for someone who has experience with VB.

    I already have the layout created on VB, just need help with the coding.

    Thanks in advance for anyone who shows an interest.

    Cheers!

    Conor.

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Small desktop application. I need an experienced VB user to help me on a few poin

    I don't think it is too challenging for someone who has experience with VB.
    Indeed it isn't. But you're not going to become one of those people if we simply do everything for you. If you want to use a database try one of the hundreds of perfectly adequate tutorials online and also use the extensive (though admittedly sometimes baffling!) help that comes with VB via MSDN. If you have code that doesn't seem to work for any reason then we'll only be too happy to guide you but you do the work, we only comment and correct where necessary.

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Small desktop application. I need an experienced VB user to help me on a few poin

    I don't think it is too challenging for someone who has experience with VB.
    Indeed it isn't. But you're not going to become one of those people if we simply do everything for you. If you want to use a database try one of the hundreds of perfectly adequate tutorials online and also use the extensive (though admittedly sometimes baffling!) help that comes with VB via MSDN. If you have code that doesn't seem to work for any reason then we'll only be too happy to guide you but you do the work, we only comment and correct where necessary.

  4. #4
    Fanatic Member
    Join Date
    Dec 2007
    Location
    West Yorkshire, UK
    Posts
    791

    Re: Small desktop application. I need an experienced VB user to help me on a few poin

    this may help. It's not a text file but a SQL Server Database. A text file may not be the easiest way.

  5. #5
    Hyperactive Member mbutler755's Avatar
    Join Date
    May 2008
    Location
    Peoria, AZ
    Posts
    417

    Re: Small desktop application. I need an experienced VB user to help me on a few poin

    Text files (flat files) are not the way to go (if you can avoid it). If you can use a local db, then do it. To me, you assignment sounds like a class assignment. Can you use a local db or sql db? Are you limited to a flat file? If you are, you may want to go with a structured flat file (e.g. xml).
    Regards,

    Matt Butler, MBA, BSIT/SE, MCBP
    Owner, Intense IT, LLC
    Find us on Facebook
    Follow us on Twitter
    Link up on LinkedIn
    mb (at) i2t.us

    CODE BANK SUBMISSIONS: Converting Images to Base64 and Back Again

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Small desktop application. I need an experienced VB user to help me on a few poin

    i'd use a class (call it record), with public properties for:

    - Title
    - Artist
    - Type
    - Year
    - Image

    vb.net Code:
    1. <System.Serializable()> Public Class record
    2.  
    3.     Private _Title As String
    4.     Private _Artist As String
    5.     Private _Type As String
    6.     Private _Year As Integer
    7.     Private _Image As Image
    8.  
    9.     Public Property Title() As String
    10.         Get
    11.             Return _Title
    12.         End Get
    13.         Set(ByVal value As String)
    14.             _Title = value
    15.         End Set
    16.     End Property
    17.  
    18.     Public Property Artist() As String
    19.         Get
    20.             Return _Artist
    21.         End Get
    22.         Set(ByVal value As String)
    23.             _Artist = value
    24.         End Set
    25.     End Property
    26.  
    27.     Public Property Type() As String
    28.         Get
    29.             Return _Type
    30.         End Get
    31.         Set(ByVal value As String)
    32.             _Type = value
    33.         End Set
    34.     End Property
    35.  
    36.     Public Property Year() As Integer
    37.         Get
    38.             Return _Year
    39.         End Get
    40.         Set(ByVal value As Integer)
    41.             _Year = value
    42.         End Set
    43.     End Property
    44.  
    45.     Public Property Image() As Image
    46.         Get
    47.             Return _Image
    48.         End Get
    49.         Set(ByVal value As Image)
    50.             _Image = value
    51.         End Set
    52.     End Property
    53.  
    54. End Class

    you need to create a dialog for adding new records, with 3 textboxes, a numericupdown, a picturebox + 3 buttons (see image).

    Name:  01-09-2012 17.51.07.jpg
Views: 542
Size:  31.5 KB

    note: the cancel button's dialogresult property is Cancel + the save button's dialogresult property is OK.


    in the dialog form's sub new you'd load the controls from the instance of record passed in.
    it could either be a new record, or you've reopened an existing record:

    vb.net Code:
    1. Public Class frmRecord
    2.  
    3.     Private _currentRecord As New record
    4.     Public Property currentRecord() As record
    5.         Get
    6.             Return _currentRecord
    7.         End Get
    8.         Set(ByVal value As record)
    9.             _currentRecord = value
    10.         End Set
    11.     End Property
    12.  
    13.     Public Sub New(ByVal r As record)
    14.         InitializeComponent()
    15.  
    16.         TextBox1.Text = r.Title
    17.         TextBox2.Text = r.Artist
    18.         TextBox3.Text = r.Type
    19.         NumericUpDown1.Value = If(r.Year <> 0, r.Year, Now.Year)
    20.         PictureBox1.Image = r.Image
    21.  
    22.         currentRecord = r
    23.  
    24.     End Sub
    25.  
    26.     Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    27.         currentRecord.Title = TextBox1.Text
    28.     End Sub
    29.  
    30.     Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
    31.         currentRecord.Artist = TextBox2.Text
    32.     End Sub
    33.  
    34.     Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
    35.         currentRecord.Type = TextBox3.Text
    36.     End Sub
    37.  
    38.     Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
    39.         currentRecord.Year = CInt(NumericUpDown1.Value)
    40.     End Sub
    41.  
    42.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    43.         'declare new OpenFileDialog + set it's initial properties
    44.         Dim ofd As New OpenFileDialog With { _
    45.         .Title = "Select image file", _
    46.         .Filter = "BMP (*.bmp)|*.bmp|GIF (*.gif)|*.gif|JPG (*.jpg)|*.jpg|PNG (*.png)|*.png|All Files (*.*)|*.*", _
    47.         .FilterIndex = 0, _
    48.         .InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)}
    49.  
    50.         'show the dialog
    51.         If ofd.ShowDialog = DialogResult.OK Then
    52.             PictureBox1.Image = New Bitmap(ofd.FileName)
    53.             currentRecord.Image = PictureBox1.Image
    54.         End If
    55.  
    56.     End Sub
    57.  
    58. End Class

    then in your main form a list(of record) + an add new record button, an imageList, + a listview setup for large icon.

    Name:  01-09-2012 17.55.00.jpg
Views: 477
Size:  17.5 KB

    in the button_click event, create a new instance of record class + a new instance of your add dialog form + pass the record variable
    in the listview doubleclick, you'd open the selected item in the add new dialog.

    at form_closed you'd serialize the list(of record) as binary, then in form_load you'd check if the binary file exists + if so, deserialize it back in to your list(of record)

    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Dim records As New List(Of record)
    4.     Dim iml As New ImageList
    5.  
    6.     Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
    7.         Dim formatter As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
    8.         Dim myWriter As New IO.FileStream("test.bin", IO.FileMode.Create)
    9.         formatter.Serialize(myWriter, records)
    10.         myWriter.Close()
    11.     End Sub
    12.  
    13.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    14.         ListView1.LargeImageList = iml
    15.         iml.ImageSize = New Size(64, 64)
    16.  
    17.         If IO.File.Exists("test.bin") Then
    18.             Dim formatter As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
    19.             Dim fs As New IO.FileStream("test.bin", IO.FileMode.Open)
    20.             records = DirectCast(formatter.Deserialize(fs), Global.System.Collections.Generic.List(Of record))
    21.             fs.Close()
    22.  
    23.             For Each r In records
    24.                 iml.Images.Add("", New Bitmap(r.Image, 64, 64))
    25.                 Dim item As ListViewItem = ListView1.Items.Add(r.Artist & Environment.NewLine & r.Title, iml.Images.Count - 1)
    26.                 item.Tag = r
    27.             Next
    28.  
    29.         End If
    30.     End Sub
    31.  
    32.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    33.         Dim r As New record
    34.         Dim frm As New frmRecord(r)
    35.         If frm.ShowDialog = Windows.Forms.DialogResult.OK Then
    36.             records.Add(frm.currentRecord)
    37.             iml.Images.Add("", New Bitmap(frm.currentRecord.Image, 64, 64))
    38.             Dim item As ListViewItem = ListView1.Items.Add(frm.currentRecord.Artist & Environment.NewLine & frm.currentRecord.Title, iml.Images.Count - 1)
    39.             item.Tag = frm.currentRecord
    40.         End If
    41.     End Sub
    42.  
    43.     Private Sub ListView1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDoubleClick
    44.  
    45.         If ListView1.HitTest(e.Location).Item.Index > -1 Then
    46.             Dim item As ListViewItem = ListView1.HitTest(e.Location).Item
    47.             Dim frm As New frmRecord(DirectCast(item.Tag, record))
    48.             If frm.ShowDialog = Windows.Forms.DialogResult.OK Then
    49.                 records(ListView1.HitTest(e.Location).Item.Index) = frm.currentRecord
    50.                 iml.Images(ListView1.HitTest(e.Location).Item.Index) = New Bitmap(frm.currentRecord.Image, 64, 64)
    51.                 ListView1.HitTest(e.Location).Item.Text = frm.currentRecord.Artist & Environment.NewLine & frm.currentRecord.Title
    52.                 ListView1.HitTest(e.Location).Item.Tag = frm.currentRecord
    53.             End If
    54.         End If
    55.     End Sub
    56.  
    57. End Class

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2012
    Location
    Newcastle
    Posts
    12

    Re: Small desktop application. I need an experienced VB user to help me on a few poin

    Hi espanolito, mbutler755 and .paul.,

    I am hugely grateful for your replies. Been busy over the past month so I apologise for the late reply. This weekend I have some spare time and will attempt to look through the guides and code you have given me and try to understand them before implementing.

    Thanks for your interest and help I really appreciate it,

    Cheers,

    Conor.

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