Okay I have a new assignment. I think I actually get the whole random access files ( I hope) but I have no clue as to how to set up my form(s). Does anyone have advice on how to set up the forms?

Here is the assignment.

Objectives: This assignment is intended to provide you with experience using random access files, the common dialog control, Dir function, printing reports, and creating menus.

Problem: Phrank & Schtein were extremely pleased with your work on the 800-WIZARDS ordering system and have threatened to turn me into a toad if I don't require you to develop another application that they need. They are hoping that you will be able to write a program to help them maintain their product inventory file that contains critical information about each of the products that they stock.

Program: Your application should perform the following tasks:

1) Using the common dialog control, allow the user to enter the file paths and names to be used. Make sure you handle the cancel button correctly. You can verify that the file exists using the Dir function.

2) Store the Product Ids and the record numbers from the index file in a list (use the itemdata property to store the record number). Allow the user of the program to select a product ID from the list and then use the associated record number to read the correct record from the random access file

a) The index information is contained in the file P&SPRDCT.NDX which contains up to 30 records, each of which contains the product ID (string * 6) and a record location (integer).

b) The random file P&SNVNTR.RND contains the following fields:

Field
Type
Manufacturer String * 15
Manufacturer phone String * 10
Qty in stock (units) Integer
Lots on order Integer
Qty per Lot Integer
Lot price Currency
Expected Shipment Date String * 10 (MM/DD/YYYY)


c) Provide the user with the ability to change any of the values contained in the inventory file. The update inventory information screen is to be a separate form from the one in which the user enters the product ID.

d) Allow the user to print a copy of the inventory information form.

3) Allow the user to print a copy of the current information stored in the inventory file along with the product ID (use the index and print the records in the order that they are listed in the index). The information should be printed under appropriate column headings and spaced into columns using Tab().

Turn In: TOE chart.
Files P&SPRDCT.NDX and P&SNVNTR.RND (after updates).

Test Data:
Product ID
Changes
PQ3250 Delete the shipping date. *Print*
HU1260 Order 50 lots, expected shipping date 5/17/96.
WB1234 Change Lot Price to 27.00
HB3140 Change Qty per Lot to 20 & Lot Price to 105.00 *Print*
NL8120 Change Qty per Lot to 150 & Lot price to 100.00

Ok, thanks for the run down, but as the guidelines for posting here at Techtalk, is that you show some attempt at your assignment, and we can give guidance when you get stuck.

Now after saying that;

And for staters are you doing this in Visual Basic or Visual Basic.Net??

From what I have read, quickly mind you, it would seem that you do not need multiple forms - therefore not MDI, but SDI. So the one form could have a listbox filled with the product ID's that can allow for selection. And have an open and save button which would load respective CommonDialog Boxes to handle opening and saving files respectively. The same code would be reusable for the menu class for the same Dialog boxes.

Hope this helps. Get back to us if you have any logic or coding type difficulties.

Take care

first I am taking Visual basic 6.0. My instructor has said that he wants two forms. One with a list box to hold the IDs and an open button and a second with textboxes to make changes to the files.

I have the Ids going into the list with the following code but how do I use the itemdata property to store the record number

Private Sub Form_Load()
Dim strProductID As String
Dim intRecordNumber As Integer
intRecord = FreeFile
Open "A:/P_SPRDCT.NDX" For Input As #intRecord
Do While Not EOF(intRecord)
Input #intRecord, strProductID, intRecordNumber
lstProduct.AddItem strProductID

Loop
Close #intRecord
End Sub

I added this is it correct?

Open "A:/P_SPRDCT.NDX" For Input As #intRecord
Do While Not EOF(intRecord)
Input #intRecord, strProductID, intRecordNumber
lstProduct.AddItem strProductID
lstProduct.ItemData(lstProduct.NewIndex) = intRecordNumber
Loop
Close #intRecord

Looks good so far. Good work!

okay now I have two forms made up. The first has the listbox filled from the code above as well as a dialog control to open a file for random access. The professor said the 2nd form is to have textboxes so when the file is opened it should fill into the textboxes. I am working on that. What I don't understand is how to link the two forms. Like when the open button is pushed the 2nd form is acitvated and filled in. Any ideas?

Kat

I have worked all weekend and have come up with the following code but it is not working correctly Instead of filling out the textboxes with each bit of info it puts the same info (the entire file) into each textbox.

Private Sub cmdOpen_Click()
Dim GetFree As Integer, Textline As String, Manufacture As String, ManPhone As String, QtyStock As Integer, LotOrder As Integer, QtyLot As Integer, LotPrice As Currency, Shipping As String
GetFree = FreeFile
CommonDialog1.Filter = "Random Files(*.rnd)|*.rnd|All Files(*.*)|*.*"
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #GetFree
Do While Not EOF(GetFree) 'Loop until it reaches the end of the file

Line Input #GetFree, Textline 'Input 1 line into the variable Textline
frmUpdate.txtManufacture.Text = frmUpdate.txtManufacture.Text & Textline
frmUpdate.txtManPhone.Text = frmUpdate.txtManPhone.Text & ManPhone
frmUpdate.txtQtyStock.Text = frmUpdate.txtQtyStock.Text & Textline
Loop
Close #GetFree
frmUpdate.Show
End Sub

looking good so far KatB!

Hope things are still that way since you post. Sorry, work has been busy so getting back to post on here has been a challenge.

Any other catches?

im having troble with my project. i do not get it please counld someone put random access vb in plan simple english

Random-access file ( or random file) is a file whose data you can read or write in any order without having to read or write all other data in the file.

Ok, what does that mean, well look at it like this (analogy); Say you have guest book at a wedding or tourist site, you have people write their name and where they came from, and any comments they have. Now, anyone visiting can write in the book, at any time and in any order. Hence random right? But to continue with the above definition, every time a guest writes in the guest book, you are not expecting them to read and re-write all the previous entries before them, are you?

No, hence again, Random access. You enter/write data to a file in in any order, but you are not required to read the entire file into memory first, and then add your new data and then write all the data back to the file. Instead you are only going to write the new data to the file, regardless of the data currently in the file.

Hope that made sense?

If it didn't, or you need more than let me know....

thanks, for helping me, now 2nd question how do i put all my files into a list box, that when clicked on can show another form. also how do you add a loop so that when i click a button it sends my information i have entered to a word doc in notepad. i can only make it output one line of info and i wish for it to keep all the data i enter. thanks

this is my code whats wrong with it:

Private Type myrec
name As String * 10
numbr As Integer
End Type
Dim position As Integer
Private Sub add_Click()
Dim rec As myrec
rec.name = tname.Text
rec.numbr = tnumber.Text
Open "i:\records.dat" For Random As #1 Len = Len(rec)
Put #1, position + 1, rec
Close #1
position = position + 1
tname.Text = ""
tnumber.Text = ""
End Sub
Private Sub Command1_Click()
Dim rec As myrec
Dim recnumber As Integer
recnumber = txtfindrecno
If (recnumber > 0) And (recnumber <= position) Then
    Open "i:\records.dat" For Random As #1 Len = Len(rec)
    Get #1, recnumber, rec
    tname = rec.name
    tnumber = rec.numbr
    Close #1
Else
    MsgBox "invalid record number"
End If
End Sub
Private Sub Command2_Click()
Dim rec As myrec
Dim recname As String
Dim found As Boolean
Dim recordnumber As Integer
recordnumber = 0
found = False

 Open "i:\records.dat" For Random As #1 Len = Len(rec)
 Do While (Not EOF(1)) And (found = False)
    recordnumber = recordnumber + 1
      Get #1, recordnumber, rec
    If rec.name = txtfindrecname.Text Then
        found = True
            tnumber = rec.numbr
            tname = rec.name
    End If
Loop
    Close #1
If Not found Then
    MsgBox "name " & txtfindrecname & " is not in file"
End If

End Sub
Private Sub Form_Load()
Dim rec As myrec
Open "c:\fiona.dat" For Random As #1 Len = Len(rec)
position = LOF(1) / Len(rec)
Close #1
End Sub
Private Sub recame_Change()
End Sub
Private Sub retrieve_Click()
Dim rec As myrec
Dim found As Boolean
Dim datatodisplay As String
Dim index As Integer
Open "c:\fiona.dat" For Random As #1 Len = Len(rec)
For index = 1 To position
Get #1, , rec
tname.Text = rec.name
tnumber.Text = rec.numbr
datatodisplay = rec.name & " " & rec.numbr
List1.AddItem datatodisplay
Next index
Close #1
End Sub

Ok a couple of things. 1. There is some logic to the code I a not understanding, so maybe you could give me a explaination on what is suppose to be happening.
2. To make your code easier to follow and read, for yourself and others, you should use hungarian notation and name your buttons appropriately.

i.e. lstRecords (for a list box with Records), cmdAdd or btnAdd (for a button that adds to something), strName (for a string variable called "name"), intNumber (for an integer variable), etc.

Just a pointer. No harm done!

Saying that, what part of your program is not working? It finds the records, it adds records, and it retrieves records. I mean, I didn't test it in everyway... but give us more details other that "something is wrong", which tells us very little.

Later

ption Explicit

Private Type myrec  '   USER DATA TYPE
    strName As String * 10
    intNumbr As Integer
End Type

Private intPosition As Integer

Private Sub add_Click()
    Dim rec As myrec
    rec.strName = tname.Text   '   Retrieves value from Textbox
    rec.intNumbr = tnumber.Text
    Open "c:\records.dat" For Random As #1 Len = Len(rec)
    MsgBox intPosition
    Put #1, intPosition + 1, rec
    Close #1
    intPosition = intPosition + 1
    tname.Text = ""
    tnumber.Text = ""
End Sub
Private Sub Command1_Click()
    Dim rec As myrec
    Dim recnumber As Integer
    recnumber = txtfindrecno
    If (recnumber > 0) And (recnumber <= intPosition) Then
        Open "c:\records.dat" For Random As #1 Len = Len(rec)
        Get #1, recnumber, rec
        tname = rec.strName
        tnumber = rec.intNumbr
        Close #1
    Else
        MsgBox "invalid record number"
    End If
End Sub
Private Sub Command2_Click()
    Dim rec As myrec
    Dim strRecname As String    '   This is for what?
    Dim fFound As Boolean
    Dim intRecordnumber As Integer
    intRecordnumber = 0
    fFound = False
    MsgBox txtfindrecname.Text
    Open "c:\records.dat" For Random As #1 Len = Len(rec)
    Do While (Not EOF(1)) And (fFound = False)
        intRecordnumber = intRecordnumber + 1
        Get #1, intRecordnumber, rec
        If CStr(rec.strName) = CStr(txtfindrecname.Text) Then
            fFound = True
            tnumber = rec.intNumbr
            tname = rec.strName
        End If
    Loop
    Close #1
    If Not found Then
        MsgBox "name " & txtfindrecname & " is not in file"
    End If

End Sub
Private Sub Form_Load()
    Dim rec As myrec
    Open "c:\fiona.dat" For Random As #1 Len = Len(rec)
    intPosition = LOF(1) / Len(rec)
    Close #1
End Sub
Private Sub recame_Change()
End Sub
Private Sub retrieve_Click()
    Dim rec As myrec
    Dim fFound As Boolean   '   What is this for?
    Dim strDatatodisplay As String
    Dim intIndex As Integer
    Open "c:\fiona.dat" For Random As #1 Len = Len(rec)
    For intIndex = 1 To intPosition
        Get #1, , rec
        tname.Text = rec.strName
        tnumber.Text = rec.intNumbr
        strDatatodisplay = rec.name & " " & rec.intNumbr
        List1.AddItem strDatatodisplay
    Next intIndex
    Close #1
End Sub

This may need to be a new thread, and seems I am responding after quite some time, if needed, please move this where it needs to go. I am looking for even more info on the Random access files...your description was good, however, there are three different types, including binary, and then it is my understanding that you can assign block size and even encryption before placing into the Random access file? Could you possible describe more about how this is done, or point me in the direction for more information? I am using Visual Studio.Net 2003u sing vb.net for the programming language. Thanks in advance.

cd

hello
i want a simple demo to understand how to create random file access in vb.
pls help me.

Hi , i am a newbie as you can tell and i was wondering if anyone could answer this and maybe ( by luck) make a demo or something

But heres the question :

AS you know i am using a random Access File (RAF), and these files carry Students names,age and absences. So I thought that why not that everytime you open a RAF that the students will be in a list. Also suppose I click on a name in the list, i want that person's data to show.
Example: Suppose I open a RAF : Ms.Cooks Class. Then the program will list everyone in her class. Suppose there is a student name Jeson . And If i click on him all his data would come out.

By the way, i am very new to Visual Basic 6, i am doing a course on this and ya we are still noobs in my class. So far though i know the very basics of these things like Putting, Creating and Reading RAFs. Thanks for anyone willing to help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.