| | |
random access file help please
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Dec 2007
Posts: 7
Reputation:
Solved Threads: 0
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........................
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........................
•
•
Join Date: Dec 2007
Posts: 7
Reputation:
Solved Threads: 0
Thank you SCBWV for helping....i hav modified my code as follows..
but i stuck again.....
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...???
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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) recordnum = 0 For Index = 0 To 4 If optLaboratory(Index).Value = True Then feedback.Laboratory(Index) = 1 Else: feedback.Laboratory(Index) = 0 Put #1, recordNum, feedback Exit For End If Next Index For Index = 0 To 4 If optLibrary(Index).Value = True Then feedback.Library(Index) = 1 Else: feedback.Library(Index) = 0 Put #1, recordNum, feedback Exit For End If Next Index For Index = 0 To 4 If optTeaching(Index).Value = True Then feedback.Teaching(Index) = 1 Else: feedback.Teaching(Index) = 0 Put #1, recordNum, feedback Exit For End If Next Index 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
but i stuck again.....
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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...???
•
•
Join Date: Apr 2007
Posts: 106
Reputation:
Solved Threads: 16
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
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
•
•
Join Date: Dec 2007
Posts: 7
Reputation:
Solved Threads: 0
Thank you SCBWV. Hope this is right....could you please check it
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...??
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Option Explicit Private Type feedbackdata Laboratory(0 To 4) As byte Library(0 To 4) As byte Teaching(0 To 4) As byte End Type Dim recordnum As Long Private Sub cmdSubmit_click() Dim feedback As feedbackdata, Index As Integer Open "C:\student.txt" For Random As #1 Len = Len(feedback) With feedback For Index = 0 To 4 .Laboratory(Index) = Abs(OptLaboratory(Index).Value) .Library(Index) = Abs(OptLibrary(Index).Value) .Teaching(Index) = Abs(OptTeaching(Index).Value) Next Index End With recordnum = recordnum + 1 Put #1, recordnum, feedback Close #1 cmdReset_click End Sub Private Sub cmdReset_click() Dim Index As Integer For Index = 0 To 4 OptLaboratory(Index).Value = False OptLibrary(Index).Value = False OptTeaching(Index).Value = False Next 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.
•
•
Join Date: Apr 2007
Posts: 106
Reputation:
Solved Threads: 16
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?
![]() |
Similar Threads
- Forms in Random access files (Visual Basic 4 / 5 / 6)
- VB 6.0. Creating a file for random access (Visual Basic 4 / 5 / 6)
- random access file and creating an index file (C)
- Deleting from Random Access File? (VB.NET)
- Random Access Files Help!! (Visual Basic 4 / 5 / 6)
- Random access read write (Visual Basic 4 / 5 / 6)
- Help!..."File Processing" *questions inside* (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: how to create graphs and flowcharts using VB
- Next Thread: Problem in identifying the database name
Views: 1611 | Replies: 7
| 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 table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





