VB.NET

Moderators: seancampbell
Number of threads: 4020
Number of posts: 10026

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
help on project Posted by wragen22 on 29 May 2008 at 2:50 PM
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’ll have to create this text file based on the information shown in the table above). When the user opens this application, a Windows form will display the existing books and their information (examples of the information are shown in the table above). Below is an example of the form interface.






Specific tasks in the Book Information form are:
1. When the form is loaded, the text file csvBooks.txt is read and the book titles and the book formats will be displayed in the list box (just the book titles and the formats, not other information).
2. When the user clicks on a book title in the list box, the information related to the selected book will be placed in the text boxes and check box on the right hand side of the form. Note: You’ll need to read the data from csvBooks.txt into an array (or an arrayList) of books. A book will be represented by a “structure” of variables. Then as the user clicks on the book title in the list box, transfer the data from the array (or arrayList) to other controls on the form.
3. The user can then make changes to the book information (in the text boxes and/or check box).
4. After the user makes the changes, he/she can click on the Modify/Save button to have the changes saved onto the text file csvBooks.txt and the Book Information form will be closed.
5. If the user doesn’t want to save the changes to the data (or makes no changes), he/she can simply click the “Exit” button to close the program.
6. Set up the list box such that the user can click on only one book title at a time.
7. Arrange the tab order to make it convenient to go through the controls on your form when the user only uses a keyboard.

Add New Books
The second application will allow users to add new books to a text file (this can be a different text file from the file used in the previous program). When the user starts this program, a Widows form will be displayed to allow the user to add new books to csvNewBooks.txt. Initially, the list box will be empty waiting for the user to enter new data through other controls on the form. After the user enters the data for a new book, the title of the book and the per-unit profit is displayed in the list box. Note: You will also use an array (or an arrayList) of books (represented by a “structure” of variables) to temporarily maintain the new data (e.g., title, price, cost, etc.) until they are saved onto csvNewBooks.txt.
After finishing entering data for a new book, the user can click the “Add To List” button to append the new information to the list box control. If the user clicks the “Save All And Exit” button, your program will check whether or not the user has entered any new data. If no new data was entered, the Windows form will be closed. If the user has entered new data, a message box will appear to confirm with the user whether the new data should be saved. If the user indicates that the new data should not be saved, the program terminates. If the user wants to save the new data, the data will be saved onto csvNewBooks.txt. The following web page contains information on how to use a MessageBox to ask the user a yes/no question and make a decision based on the response http://msdn2.microsoft.com/en-us/library/system.windows.forms.messagebox(VS.85).aspx . An example of the form interface is shown below.


Report
Re: help on project Posted by wragen22 on 29 May 2008 at 8:46 PM
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?


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

Report
Re: help on project Posted by seancampbell on 30 May 2008 at 7:28 AM
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
Report
Re: help on project Posted by wragen22 on 31 May 2008 at 1:41 PM
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?
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
Report
Re: help on project Posted by seancampbell on 2 Jun 2008 at 9:06 AM
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

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


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
View = Details
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
MultiSelect = False
Self explanitory
GridLines = True
This option gets set so when you select an Line Item it doesn't just
highlight a cell, but instead highlights the whole line
FullRowSelect = True

 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




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.