random access file help please

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

Join Date: Dec 2007
Posts: 7
Reputation: dee2020 is an unknown quantity at this point 
Solved Threads: 0
dee2020 dee2020 is offline Offline
Newbie Poster

random access file help please

 
0
  #1
Jan 8th, 2008
hi friendz..,

im working on "feedback form analysis" project
the first main aim of my project is to store data submitted by the user from the feedback form in a text file which can be accessed randomly. For that.... i wrote the following code:

CODE:


Private Type feedbackdata

Laboratory(0 To 4) As Integer
Library(0 To 4) As Integer
Teaching(0 To 4) As Integer
OptLaboratory As Boolean
OptLibrary As Boolean
OptTeaching As Boolean
End Type


Dim Index As Integer
Dim recordnum As Integer



Private Sub cmdSubmit_click()

Dim feedback As feedbackdata

Open "C:\student.txt" For Random As #1 Len = Len(feedback)
For Index = 0 To 4
If optLaboratory(Index).Value = True Then
feedback.Laboratory(Index) = 1
Else: feedback.Laboratory(Index) = 0
Put #1, 1, feedback
Next Index
Exit For
End If


For Index = 0 To 4
If optLibrary(Index).Value = True Then
feedback.Library(Index) = 1
Else: feedback.Library(Index) = 0
Put #1, 1, feedback
Next Index
Exit For
End If


For Index = 0 To 4
If optTeaching(Index).Value = True Then
feedback.Teaching(Index) = 1
Else: feedback.Teaching(Index) = 0
Put #1, 1, feedback
Next Index
Exit For
End If


recordnum = recordnum + 1

Close #1



End Sub


Private Sub cmdReset_click()
Dim Index As Integer
For index = 0 to 4
optLaboratory(index).value = False
Next
For index = 0 to 4
optLibrary(index).value = False
Next
For index = 0 to 4
optTeaching(index).value = False
Next


End Sub

================


when i execute the above code....the compiler is giving the following error:

after for next expected



i dont know whats wrong...Could u please help..?

thank u in advance........................
Attached Thumbnails
Picture1.png  
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 106
Reputation: SCBWV is an unknown quantity at this point 
Solved Threads: 16
SCBWV SCBWV is offline Offline
Junior Poster

Re: random access file help please

 
0
  #2
Jan 8th, 2008
You have Exit For outside every For-Next loop in cmdSubmit_click. Exit For is used to conditionally end the For-Next loop early... such as "If condition = true then Exit For."
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 7
Reputation: dee2020 is an unknown quantity at this point 
Solved Threads: 0
dee2020 dee2020 is offline Offline
Newbie Poster

Re: random access file help please

 
0
  #3
Jan 8th, 2008
Thank you SCBWV for helping....i hav modified my code as follows..

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Type feedbackdata
  2.  
  3. Laboratory(0 To 4) As Integer
  4. Library(0 To 4) As Integer
  5. Teaching(0 To 4) As Integer
  6. optLaboratory As Boolean
  7. optLibrary As Boolean
  8. optTeaching As Boolean
  9. End Type
  10.  
  11.  
  12. Dim Index As Integer
  13. Dim recordNum As Integer
  14.  
  15.  
  16. Private Sub cmdSubmit_click()
  17.  
  18. Dim feedback As feedbackdata
  19.  
  20. Open "C:\student.txt" For Random As #1 Len = Len(feedback)
  21.  
  22. recordnum = 0
  23.  
  24. For Index = 0 To 4
  25. If optLaboratory(Index).Value = True Then
  26. feedback.Laboratory(Index) = 1
  27. Else: feedback.Laboratory(Index) = 0
  28. Put #1, recordNum, feedback
  29. Exit For
  30. End If
  31. Next Index
  32.  
  33.  
  34.  
  35. For Index = 0 To 4
  36. If optLibrary(Index).Value = True Then
  37. feedback.Library(Index) = 1
  38. Else: feedback.Library(Index) = 0
  39. Put #1, recordNum, feedback
  40. Exit For
  41. End If
  42. Next Index
  43.  
  44. For Index = 0 To 4
  45. If optTeaching(Index).Value = True Then
  46. feedback.Teaching(Index) = 1
  47. Else: feedback.Teaching(Index) = 0
  48. Put #1, recordNum, feedback
  49. Exit For
  50. End If
  51. Next Index
  52.  
  53.  
  54. recordNum = recordNum + 1
  55.  
  56. Close #1
  57.  
  58.  
  59.  
  60. End Sub
  61.  
  62.  
  63. Private Sub cmdReset_click()
  64. Dim Index As Integer
  65. For Index = 0 To 4
  66. optLaboratory(Index).Value = False
  67. Next
  68. For Index = 0 To 4
  69. optLibrary(Index).Value = False
  70. Next
  71. For Index = 0 To 4
  72. optTeaching(Index).Value = False
  73. Next
  74.  
  75.  
  76. End Sub

but i stuck again.....



Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Open "C:\student.txt" For Random As #1 Len = Len(feedback)


From the above line of code....the compiler created a text file called "student" in C drive but it does not have any 1's or 0's as i wrote in the code. In short.... the file is empty. There seems to be a piece of information which is invisible in the student text file . I can say that it is invisible as the size of the text file is 36 bytes instead of 0 bytes.

could u please help me...???
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 106
Reputation: SCBWV is an unknown quantity at this point 
Solved Threads: 16
SCBWV SCBWV is offline Offline
Junior Poster

Re: random access file help please

 
0
  #4
Jan 8th, 2008
Random Access files use records, much like a database, but you define the record in a user defined type. You should create a user defined type much like you create the fields for a record in a database. be that as it may, you're not incrementing the recordNum variable properl and your If/Then is inccorect. You should increment it inside each loop. For instance:
For Index = 0 To 4
If optLaboratory(Index).Value = True Then
feedback.Laboratory(Index) = 1
Else: feedback.Laboratory(Index) = 0
recordNum = recordNum + 1 'increment for each value
End If ' should be here
Put #1, recordNum, feedback
'Exit For 'this shouldn't even be here
End If 'woing place
Next Index
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 7
Reputation: dee2020 is an unknown quantity at this point 
Solved Threads: 0
dee2020 dee2020 is offline Offline
Newbie Poster

Re: random access file help please

 
0
  #5
Jan 15th, 2008
Thank you SCBWV. Hope this is right....could you please check it

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2.  
  3. Private Type feedbackdata
  4. Laboratory(0 To 4) As byte
  5. Library(0 To 4) As byte
  6. Teaching(0 To 4) As byte
  7.  
  8. End Type
  9.  
  10. Dim recordnum As Long
  11.  
  12. Private Sub cmdSubmit_click()
  13. Dim feedback As feedbackdata, Index As Integer
  14.  
  15. Open "C:\student.txt" For Random As #1 Len = Len(feedback)
  16.  
  17. With feedback
  18. For Index = 0 To 4
  19. .Laboratory(Index) = Abs(OptLaboratory(Index).Value)
  20. .Library(Index) = Abs(OptLibrary(Index).Value)
  21. .Teaching(Index) = Abs(OptTeaching(Index).Value)
  22. Next Index
  23. End With
  24. recordnum = recordnum + 1
  25. Put #1, recordnum, feedback
  26. Close #1
  27. cmdReset_click
  28. End Sub
  29.  
  30. Private Sub cmdReset_click()
  31. Dim Index As Integer
  32. For Index = 0 To 4
  33. OptLaboratory(Index).Value = False
  34. OptLibrary(Index).Value = False
  35. OptTeaching(Index).Value = False
  36. Next
  37. End Sub

But the recordnum is not incrementing properly....i.e., after the user answers the three questions, it should start from a new line. could u plz help me...??
Last edited by dee2020; Jan 15th, 2008 at 7:11 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 106
Reputation: SCBWV is an unknown quantity at this point 
Solved Threads: 16
SCBWV SCBWV is offline Offline
Junior Poster

Re: random access file help please

 
0
  #6
Jan 16th, 2008
New line? Random access files do not have lines, they have records. In this case, each record is the length of the feedback. So every Len(feedback) is a new record. If you want one record per line, then you want a text file. However, you can't randomly read a text file, so there's no way to read the 15th record without reading 1-14 first. Do you want random access or lines?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 7
Reputation: dee2020 is an unknown quantity at this point 
Solved Threads: 0
dee2020 dee2020 is offline Offline
Newbie Poster

Re: random access file help please

 
0
  #7
Jan 17th, 2008
well....i want random access
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 7
Reputation: dee2020 is an unknown quantity at this point 
Solved Threads: 0
dee2020 dee2020 is offline Offline
Newbie Poster

Re: random access file help please

 
0
  #8
Jan 24th, 2008
Hi friendz....,,,,

Does anyone have any idea on "how to draw pie diagrams by retrieving data from a random access file by a single button click" using VB6??
Any help would be appreciated

dee
Reply With Quote Quick reply to this message  
Reply

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




Views: 1611 | Replies: 7
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