Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

help on project

wragen22wragen22 Posts: 3Member
Hello, is there anyone that could write this for me? I would be willing to pay a small fee in return. Thanks so much. I feel i can learn by looking at the specs and then looking at the solution.

Display/Modify Book Information
The first application is to allow users to read data from a comma-delimited text file called csvBooks.txt (you

Comments

  • wragen22wragen22 Posts: 3Member
    I've started to try it myself. For some reason the output for the book type is not aligned. Any idea? And any hints on what to do next?
    [img=http://i2.photobucket.com/albums/y13/wragen22/Picture2-4.png]

    [code]Public Class Form1
    Structure books
    Dim title As String
    Dim quant As Integer
    Dim type As String
    Dim price As Decimal
    Dim cost As Decimal
    End Structure
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim sr As IO.StreamReader = IO.File.OpenText("csvBooks.txt")
    Dim fmtstr As String = "{0,-40}{1,15}"
    ListBox1.Items.Add(String.Format(fmtstr, "Title", "Hard Cover?"))

    Dim books1(5) As books
    Dim i As Integer = 0
    Dim data() As String

    Do While sr.Peek <> -1
    data = sr.ReadLine().Split(",")
    ListBox1.Items.Add(String.Format(fmtstr, data(0), data(2)))
    books1(i).title = data(0)
    books1(i).type = data(2)


    i += 1

    Loop

    End Sub



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub


    End Class
    [/code]
  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    Hi wragen22! Welcome to the forum.

    Hey, I have noticed (over the last few years providing help on these forums) that most people ignore people who ask someone to write a program for them. Myself, I won't do that for you, but I have no quarels with helping you with something you have already written.

    When your working on a program, you should focus on one aspect at a time. My usual attack process works like this:
    1. Understand the problem
    2. Consider (or write down) what work needs to be done to make it functional
    3. Make it functional (Functional in the sense that it does its primary function, maybe not every little feature yet)
    4. Test unexpected cases
    5. Consider what work is needed to add features
    6. Add final features and revise the cosmetics (aligning in listboxes, make the input elements stand out, etc)

    Your project seems very simple. I broke its functionality down into a checksheet for you, maybe that will help:

    For Modifying:
    Form_Load:
    1.Load data from the CSV into objects in memory (form level arrays, or anything else your comfortable with)
    2.Populate the listbox with content (I would make this a seperate Sub so you can call it when doing Save/Modify)

    ListBox_SelectedIndexChanged:
    1.Populate the text boxes with the information for that line item. If you are corresponding an array to the listbox, make sure you remember that ListBox.SelectedIndex starts at 0 for the first line item.

    Modify/Save_Click:
    1.Change the object in memory corresponding with the ListBox.SelectedIndex
    2.Rewrite the Csv file

    Exit_Click:
    1. Prompt if user is sure (If a requirement)
    2. End

    For adding new:

    ~`Recycle code from previous form`~
    Add New:
    :tip: For this function you are going to need to add a new object to your Array. If you predefine how many you can have maximum (by making a memory object like Dim Arr(100) as Integer) then you should use If Statements to limit the user to the maximum number of entries

    :tip2: You will need some kind of counter to know how many objects there are. Conveniently, the ListBox tool has a count feature, I am not sure off the top of my head but it is either ListBox.Count or ListBox.Items.Count or Something similar (could be rowcount I am not exactly sure)

    1.Add new object
    2.Refresh the listbox

    SaveAllExit_Click:
    1.Recreate the CSV file
    2.End


    Hope this helps you, if you have questions on why certain code isn't working, or what a command you absolutely cannot find on google is then I would be happy to help you out. I am kinda spotty on this forum (I have been inactive the last several months, and just got back in the swing of things yesterday) but you can get my contact information from my website and email me directly with questions if you'd like.

    Happy coding,
    firesickle.com
  • wragen22wragen22 Posts: 3Member
    Ok..so when I select a book on the listbox it is showing the book after it in the textbox...and idea how to fix this?
    [code]Public Class Form1
    Structure books
    Dim title As String
    Dim quant As Integer
    Dim type As String
    Dim price As Decimal
    Dim cost As Decimal
    End Structure
    Dim bookinfo(5) As books

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim sr As IO.StreamReader = IO.File.OpenText("csvBooks.txt")
    Dim fmtstr As String = "{0,-30}{1,10}"
    ListBox1.Items.Add(String.Format(fmtstr, "Title", "Hard Cover?"))

    Dim book1(5) As books
    Dim i As Integer = 0
    Dim data() As String

    Do While sr.Peek <> -1
    data = sr.ReadLine().Split(",")
    ListBox1.Items.Add(String.Format(fmtstr, data(0), data(2)))
    bookinfo(i).title = data(0)
    bookinfo(i).type = data(2)
    i += 1

    Loop

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    TextBox1.Text = CStr((bookinfo(ListBox1.SelectedIndex).title))

    End Sub
    End Class
    [/code]
  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    Sure, When you are populating the ListBox, you add in the Title Captions as the first row, that meens that when ListBox1.SelectedIndex = 0 you have selected the titles of the data.

    So You would have to say

    [code]
    If Listbox1.SelectedIndex <= 0 then Exit Sub 'this keeps us from crashing
    textbox1 = bookinfo(ListBox1.SelectedIndex-1).title
    [/code]

    I suggest however using a ListView. It works a lot like the ListBox but it have have multiple columns. For the sake of you not having to go look for sample code on google, I will post some sample code on how to use one with your project:

    After you have added the object to your form,
    there are a few settings that need set.
    In the properties set the following:
    This option must be set to view data like the Listbox
    [b]View = Details[/b]
    This makes it so only one line item can be selected at a time
    Note: by default you can select multiple lines by holding ctrl and clicking
    [b]MultiSelect = False[/b]
    Self explanitory
    [b]GridLines = True[/b]
    This option gets set so when you select an Line Item it doesn't just
    highlight a cell, but instead highlights the whole line
    [b]FullRowSelect = True[/b]

    [code]
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim sr As IO.StreamReader = IO.File.OpenText("csvBooks.txt")
    Dim fmtstr As String = "{0,-30}{1,10}"

    'This is where we are creating Columns
    ListView1.Columns.Clear()
    ListView1.Add("Title", 75, HorizontalAlignment.Left) '75 px width
    ListView1.Add("Hard Cover?", 75, HorizontalAlignment.Left) '75 px

    'ListBox1.Items.Add(String.Format(fmtstr, "Title", "Hard Cover?"))

    Dim book1(5) As books
    Dim i As Integer = 0
    Dim data() As String

    Dim xItem as ListViewItem
    Do While sr.Peek <> -1
    data = sr.ReadLine().Split(",")
    'ListBox1.Items.Add(String.Format(fmtstr, data(0), data(2)))
    xItem = New ListViewItem(data(0))
    xItem.SubItems.Add(data(2))
    'To put data in for each column beyond the first,
    'you add subitems
    ListView1.Items.Add(xItem)
    'Once our temporary item object is finished it gets added
    'to the ListView.Items collection
    bookinfo(i).title = data(0)
    bookinfo(i).type = data(2)
    i += 1
    Loop

    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    'TextBox1.Text = CStr((bookinfo(ListBox1.SelectedIndex).title))
    TextBox1.Text = CStr(bookinfo(ListView1.SelectedIndices(0)).title)
    End Sub

    [/code]
Sign In or Register to comment.