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 undefined
Last Comment

8/22/2022 - Mon
Mike Tomlinson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

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
Mike Tomlinson

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 code...you should see a difference.

Thank You

i forgot to change the first one

you points are on there way :)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck

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