VB6 edit a record
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: VB6 edit a record

  1. #1
    Join Date
    Apr 2013
    Posts
    11

    VB6 edit a record

    Hi, I've created a program to be used in a school to monitor the stock of equipment. a student is able to loan stock out, which should as a result drop the ammount of stock by 1 and increase a tally of the total loans for that piece of stock by 1. The coding works to the point that the stock drops, however all of the information writes back to a .text files, yet it isnt updating within the file.

    I hope this makes sense,

    Cheers

    Code:
     Public Sub Loan()
    Dim recordnumber As Integer
    Dim found As Boolean
    Dim ProductID As String
    Dim product As OneProduct
    Dim totalloans As Integer
    
    
    ProductID = Form1.txtfindproduct.Text
    recordnumber = 0
    found = False
    Filename = Form1.txtfilename.Text
    Open Filename For Random As #1 Len = Len(product)
    Do While (Not EOF(1)) And (found = False)
    
        recordnumber = recordnumber + 1
        Get #1, recordnumber, product
        If product.ProductID = ProductID Then
        found = True
        Form1.lblproductID.Caption = ProductID
        Form1.lbldescription.Caption = product.Description
        Form1.lblprice.Caption = product.Price
        Form1.lblquantityinstock.Caption = product.QuantityInStock
        Form1.txttotalloans.Text = Form1.txttotalloans.Text + 1
        product.totalloans = Form1.txttotalloans.Text
        
        product.QuantityInStock = Form1.lblquantityinstock.Caption
        
        Put #1, recordnumber, product
       End If
    
       Loop
        Close #1
        If Not found Then
        MsgBox ("Product ID " & ProductID & " is not in the file")
        End If
        
        product.QuantityInStock = Form1.lblquantityinstock.Caption
        product.totalloans = Form1.txttotalloans.Text
        lstdisplayfile.Clear
        Open Filename For Random As #1 Len = Len(product)
    Put #1, recordnumber, product
    MsgBox (product.ProductID)
        
    MsgBox (product.totalloans)
    MsgBox (product.QuantityInStock)
    
    Close #1
        
    
    
        
    End Sub

  2. #2
    Join Date
    Apr 2013
    Posts
    11

    Re: VB6 edit a record

    Hey, I've also now added this piece of code to the bottom of the orginal code...

    Code:
     Open Filename For Random As #1 Len = Len(product)
        Get #1, 1, newquantity
        newquantity = Form1.lblquantityinstock.Caption
        Put #1, 1, newquantity
        Close #1

  3. #3
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,834

    Re: VB6 edit a record

    I do not see any issue with the piece of code that reads and writes the file.
    You say that all the info writes back to the file but it doesn't update the file. That would not seem possible and how would you know? If the file has not changed then there would be no difference after the write so how would you tell?

    I would say step through the code and see what is happening at runtime.

    One note about the code is that it would appear that you are only trying to update one item in which case you should exit the loop once it has been found rather than continue to cycle through the rest of the file

    Code:
    If product.ProductID = ProductID AND found=false Then

    As for the second piece of code that may very well cause an issue. You should use the Product class rather than a single var there.
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center