CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2013
    Posts
    2

    need some help on my code please

    Hello to all im trying to create a simple code thats not soo simple to me but i just wanted to know if someone would be so kind as to help me figure out why certain things are not going as planned. Please have in mind i am a beginner (be gentle ). My code is the following (I put what i need help with in the code. its in green):

    Code:
    Imports System.IO
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim pInventory As IO.StreamWriter = IO.File.AppendText("product.txt")
            If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
                MsgBox("Please fill in required fields", MsgBoxStyle.Exclamation, "Error")
            Else
                pInventory.WriteLine(TextBox1.Text & ", $" & TextBox2.Text & ", " & TextBox3.Text)
                TextBox1.Clear()
                TextBox2.Clear()
                TextBox3.Clear()
                Dim num As Integer
                For num = 0 To ListBox1.Items.Count - 1
                    pInventory.WriteLine(ListBox1.Items(num))
                Next
                pInventory.Close()
            End If
        End Sub
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim name As String
            Dim num As Integer
            Dim max As Integer
            name = InputBox("What item would you like to search for :", "Product Search")
            num = 0
            max = ListBox1.Items.Count - 1
    
            'Here im having trouble searching for a product that is entered/saved in the data entry
            'it tells me that the exception was unhandled. it says its an invalid argument
    
            Do While (name <> (ListBox1.Items.Item(num))) And (num < max)
                num = num + 1
    
                ListBox1.Items.Add(num)
            Loop
            If (name = ListBox1.Items.Item(num)) Then
                MsgBox(name & " Was found", , "Search")
            Else
                MsgBox(name & " Was not found", , "Search")
            End If
        End Sub
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            If ListBox1.SelectedIndex <> -1 Then
                ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
            Else
                MsgBox("Please make a selection")
            End If
        End Sub
        Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    
           'Here, when you click on the "view data" button i just want the archive to show everything entered in data entry
            'but i just cant seem how to do it to where it just displays the data instead of asking you to enter archive name
            'i think im just worn out with this project!
    
            Dim item As String
            Dim product As StreamReader
            item = InputBox("Please enter archive name", "Product List")
            item = item & ".txt"
            If File.Exists(item) Then
                product = File.OpenText(item)
                ListBox1.Items.Clear()
                Do While product.Peek <> -1
                    ListBox1.Items.Add(product.ReadLine)
                Loop
                product.Close()
            Else
                MsgBox("Archive does not exist!", MsgBoxStyle.Critical, "Error")
            End If
        End Sub
    End Class

  2. #2
    Join Date
    Dec 2013
    Posts
    2

    Re: need some help on my code please

    in the first button i want to store the data. in the second button i want to search for stored data using keywords but for some reason its not working. in the third button i want to be able to click on any item that shows in the listbox and delete it and in the fourth button i want to be able to show all of the data that is stored in the archive in the listbox without having to type in the archive name. so far i got down the first and third buttons but im having problems with the second and fourth buttons.

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

Featured