Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Visual basic recognising numbers in a textfile??

    Hello,

    I'm trying to build a ordering system for a company and have already built the system to add and remove stock items.

    However, I am having trouble with the lowering of the amount of stock as I have no idea how to do such a thing.

    The system reads all the stock and values in a textfile as the program opens, after which you have the ability to add and remove stock items and also lower the amount of stock for one category as you sell more of the item (the bit i am having trouble with).

    any help would be greatly appreciated,

    below is my code so far...

    Code:
    ' Open IO namespace library to access commands StreamReader and Streamwriter
    Imports System.IO
    
    Public Class frmStockChart
    
        ' declare variables to hold values for Amount and name
        Dim Amount As String
        Dim Entry As String
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
            ' declares variable to read Stockfile.txt
            Dim StockFile As StreamReader = File.OpenText("Stockfile.txt")
            ' peek to the next line and only stop when there are no lines left
            Do While StockFile.Peek <> -1
                lstStock.Items.Add(StockFile.ReadLine())
    
            Loop
            ' after the file has been viewed, close the program
            StockFile.Close()
        End Sub
    
        Private Sub vsbAmount_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles vsbAmount.Scroll
            ' adds the right ammount of zeros to arrange the sort order of the Amount correctly
            Select Case vsbAmount.Value
                Case Is < 10 : Amount = "000" + CStr(vsbAmount.Value)
                Case 10 To 99 : Amount = "00" + CStr(vsbAmount.Value)
                Case 100 To 999 : Amount = "0" + CStr(vsbAmount.Value)
                Case Else : Amount = vsbAmount.Value
            End Select
            lblAmount.Text = Amount
        End Sub
    
        Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
            ' removes item from hi Amounts file
            lstStock.Items.Remove(lstStock.Text)
        End Sub
    
        Private Sub lblAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblAdd.Click
            ' entry area to add text to the Stock file
            Entry = "Amount: " + Amount + " " + "Stock Item Name: " + txtItemName.Text + " " + "Location Of Stock: " + txtLocat.Text
            ' adds the information to the form
            lstStock.Items.Add(Entry)
        End Sub
    
        Private Sub lblAmount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblAmount.Click
    
        End Sub
    
        Private Sub txtName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtItemName.TextChanged
    
        End Sub
    
    
        Private Sub txtLocat_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLocat.TextChanged
    
        End Sub
    
        Private Sub Quitbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Quitbtn.Click
            ' declare variable of Stockfile2
            Dim StockFile2 As StreamWriter = File.CreateText("Stockfile.txt")
            ' Add info to Stock file and save
            For Each Name As Object In lstStock.Items
                StockFile2.WriteLine(Name)
            Next
            ' close stock file
            StockFile2.Close()
            End
        End Sub
    End Class
    Thanks.

  • #2
    New to the CF scene
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    bumping for urgency

  • #3
    Regular Coder bobleny's Avatar
    Join Date
    May 2007
    Posts
    258
    Thanks
    3
    Thanked 11 Times in 11 Posts
    As far as I know, the only way to change the information in a text file like that is to rebuild the file from the first line to the last line.

    You will need to create a new file, copy every line from the old file to the new file, except of course when you get to the line that needs updating where you need to change that line. Then replace the old file with the new file, or relocate the old file to a different directory as a backup.

    When I do text files, I use serialized objects and structures. It make the whole process a lot simpler.
    --www.firemelt.net--
    * No good deed goes unpunished.
    * Cheer up, the worst has yet to come...


  •  

    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
    •