| | |
Forms in Random access files
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2004
Posts: 8
Reputation:
Solved Threads: 0
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
•
•
Join Date: Jan 2004
Posts: 8
Reputation:
Solved Threads: 0
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
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
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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
•
•
Join Date: Oct 2004
Posts: 1
Reputation:
Solved Threads: 0
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
cd
•
•
Join Date: Feb 2008
Posts: 1
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- Creating a Address Book using Random Access Files (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: VB6 how to get media from code base64 text
- Next Thread: Showing clock in capture video
Views: 17067 | Replies: 15
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





