Forms in Random access files

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2004
Posts: 8
Reputation: c_barnett01 is an unknown quantity at this point 
Solved Threads: 0
c_barnett01 c_barnett01 is offline Offline
Newbie Poster

Re: Forms in Random access files

 
0
  #11
Feb 2nd, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2004
Posts: 8
Reputation: c_barnett01 is an unknown quantity at this point 
Solved Threads: 0
c_barnett01 c_barnett01 is offline Offline
Newbie Poster

Re: Forms in Random access files

 
0
  #12
Feb 6th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Forms in Random access files

 
0
  #13
Feb 7th, 2004
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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ption Explicit
  2.  
  3. Private Type myrec ' USER DATA TYPE
  4. strName As String * 10
  5. intNumbr As Integer
  6. End Type
  7.  
  8. Private intPosition As Integer
  9.  
  10. Private Sub add_Click()
  11. Dim rec As myrec
  12. rec.strName = tname.Text ' Retrieves value from Textbox
  13. rec.intNumbr = tnumber.Text
  14. Open "c:\records.dat" For Random As #1 Len = Len(rec)
  15. MsgBox intPosition
  16. Put #1, intPosition + 1, rec
  17. Close #1
  18. intPosition = intPosition + 1
  19. tname.Text = ""
  20. tnumber.Text = ""
  21. End Sub
  22. Private Sub Command1_Click()
  23. Dim rec As myrec
  24. Dim recnumber As Integer
  25. recnumber = txtfindrecno
  26. If (recnumber > 0) And (recnumber <= intPosition) Then
  27. Open "c:\records.dat" For Random As #1 Len = Len(rec)
  28. Get #1, recnumber, rec
  29. tname = rec.strName
  30. tnumber = rec.intNumbr
  31. Close #1
  32. Else
  33. MsgBox "invalid record number"
  34. End If
  35. End Sub
  36. Private Sub Command2_Click()
  37. Dim rec As myrec
  38. Dim strRecname As String ' This is for what?
  39. Dim fFound As Boolean
  40. Dim intRecordnumber As Integer
  41. intRecordnumber = 0
  42. fFound = False
  43. MsgBox txtfindrecname.Text
  44. Open "c:\records.dat" For Random As #1 Len = Len(rec)
  45. Do While (Not EOF(1)) And (fFound = False)
  46. intRecordnumber = intRecordnumber + 1
  47. Get #1, intRecordnumber, rec
  48. If CStr(rec.strName) = CStr(txtfindrecname.Text) Then
  49. fFound = True
  50. tnumber = rec.intNumbr
  51. tname = rec.strName
  52. End If
  53. Loop
  54. Close #1
  55. If Not found Then
  56. MsgBox "name " & txtfindrecname & " is not in file"
  57. End If
  58.  
  59. End Sub
  60. Private Sub Form_Load()
  61. Dim rec As myrec
  62. Open "c:\fiona.dat" For Random As #1 Len = Len(rec)
  63. intPosition = LOF(1) / Len(rec)
  64. Close #1
  65. End Sub
  66. Private Sub recame_Change()
  67. End Sub
  68. Private Sub retrieve_Click()
  69. Dim rec As myrec
  70. Dim fFound As Boolean ' What is this for?
  71. Dim strDatatodisplay As String
  72. Dim intIndex As Integer
  73. Open "c:\fiona.dat" For Random As #1 Len = Len(rec)
  74. For intIndex = 1 To intPosition
  75. Get #1, , rec
  76. tname.Text = rec.strName
  77. tnumber.Text = rec.intNumbr
  78. strDatatodisplay = rec.name & " " & rec.intNumbr
  79. List1.AddItem strDatatodisplay
  80. Next intIndex
  81. Close #1
  82. End Sub
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 1
Reputation: chexwebson is an unknown quantity at this point 
Solved Threads: 0
chexwebson chexwebson is offline Offline
Newbie Poster

Re: Forms in Random access files

 
0
  #14
Oct 19th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 1
Reputation: nisha is an unknown quantity at this point 
Solved Threads: 0
nisha nisha is offline Offline
Newbie Poster

Re: Forms in Random access files

 
0
  #15
Jan 19th, 2005
hello
i want a simple demo to understand how to create random file access in vb.
pls help me.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1
Reputation: jesan is an unknown quantity at this point 
Solved Threads: 0
jesan jesan is offline Offline
Newbie Poster

Re: Forms in Random access files

 
0
  #16
May 27th, 2008
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum


Views: 17067 | Replies: 15
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC