Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Creating sequential file using Visual Basic 6.0

Posted on 2003-03-18
Medium Priority
Last Modified: 2010-04-17
How to create a sequential file using Visual basic 6.0 that will load a user-defined type from the sequential file with an extra field for the pay. A command button will called findpay will use a for next loop to process the array. First you will display an input box for he number of hours worked, calculate the pay, and add to the totals.  Then you will display the labels for the next employee.  (Place the pay into the extra field in the array.  An exit button will print a report on the printer and terminate the project.  (Print the array) Hours over 40 recieve time and a half pay. accumulate the total num. hours worked, total num. hours overtime, and total amount of pay.
Question by:LakeshaJ

Author Comment

ID: 8162594
This question needs to be answer ASAP

Accepted Solution

Jacamar earned 1000 total points
ID: 8162953
Try this

dim stFilename as string
stFilename = app.path & "\Text.txt"
Open stFilename for output as #1

Print #1, "This is how to output to a text file."

Close #1


Expert Comment

ID: 8162967
Now, you can control the spacing in this with commands such as

Print #1, tab(10); "This will be 10 spaces from the left margin"


Print #1, spc(10); "This will be 10 spaces from the most recent text on this line"

adding a ";" after the text will keep the current printing spot on the same line


Print #1, "This line of code and the next";
Print #1, "will be on the same line in the file"

and last but not least, you can output variables the same way

Print #1, ststring

I hope this is what you wanted.
LVL 77

Assisted Solution

GrahamSkan earned 1000 total points
ID: 8165860
Picking up on 'User-defined' with extra field, place something like this in the decarations section of a module

Type UserDetails
    Firstname As String * 20
    Middlename As String * 20
    LastName As String * 20
    HoursWorked As Integer
    PayRate As Currency
End Type

Type UserPay
    ud As UserDetails
    Pay As Currency
End Type
Read a record from a sequential file into text boxes on a form

Sub GetRecord(InputFile As String, Recordnumber As Long)
    Dim f As Integer
    Dim ud As UserDetails
    f = FreeFile
    Open InputFile For Binary As #f
        Get #f, Recordnumber, ud
        txtFirstName.Text = ud.Firstname
        txtHoursWorked.Text = ud.HoursWorked
    Close #f
End Sub

Save the record with the extra field to another sequential file using this sort of code:

Sub SaveRecord(OutPutFile As String, Recordnumber As Long)
    Dim f As Integer
    Dim up As UserPay
    f = FreeFile
    Open OutPutFile For Binary As #f
        Put #f, Recordnumber, up
        up.UserDetails.Firstname = txtFirstName.Text
        up.Pay = Val(txtHoursWorked.Text) * Val(txtPayRate.Text)
    Close #f
End Sub

Expert Comment

ID: 9447019
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question