Link to home
Start Free TrialLog in
Avatar of ace5342

asked on

Write Record To txt File

i have got the data so it is saved into a txt file but can any one explain how to get it out and display the first record into a label3

here is my code

Private Sub Command1_Click()

With stock
    .ProductCode = product(0).Text
    .ProductName = product(1).Text
    .ProductType = product(2).Text
    .TQuantityCase = product(3).Text
    .TQuantitySingle = product(4).Text
    .ShopPrice = product(5).Text
    .WS1 = product(6).Text
    .WS2 = product(7).Text
    .WS3 = product(8).Text
    .WS4 = product(9).Text
    .WS5 = product(10).Text
    .WS6 = product(11).Text
    .WS7 = product(12).Text
    .WS8 = product(13).Text
    .WS9 = product(14).Text
End With

pathtofile = App.Path & "\stock.txt"
FileNumber = FreeFile
RecordLength = Len(stock)
Open pathtofile For Random As FileNumber Len = RecordLength
CurrentRecord = RecordLength + Val(1)
Put #FileNumber, CurrentRecord, stock
Close (FileNumber)
End Sub

Private Sub Command2_Click()
Get The First Record and display in the label box
End Sub

and the Module

Public Type tStock
    ProductCode As Variant
    ProductName As Variant
    ProductType As Variant
    Size As Variant
    TQuantityCase As Variant
    TQuantitySingle As Variant
    ShopPrice As Variant
    WS1 As Variant
    WS2 As Variant
    WS3 As Variant
    WS4 As Variant
    WS5 As Variant
    WS6 As Variant
    WS7 As Variant
    WS8 As Variant
    WS9 As Variant
End Type

Global CurrentRecord As Long
Global stock As tStock
Global pathtofile As String
Global FileNumber As Integer
Global RecordLength As Integer

any help would be great thanks

Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ace5342


i can't see any information would this have anything to do with the txt file im saving to as there are aolt of blank lines and spaces in there
In my instructions I said...

Change this line:

    CurrentRecord = RecordLength + Val(1)


    CurrentRecord = CurrentRecord + 1

Your old code was making CurrentRecorrd bigger than it was supposed to be causing the many blank lines.  

Delete the old text file and run it with the new should see a difference.
Avatar of ace5342


Thank You

i forgot to change the first one

you points are on there way :)
Avatar of ace5342


still a small problem

when i add another record it will not show me the first record only the second and if i add a 3rd it will not show the 1st or 2nd record and so on