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........................

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."

Thank you SCBWV for helping....i hav modified my code as follows..

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.....

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...???

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

Thank you SCBWV. Hope this is right....could you please check it

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...??

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?

well....i want random access

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

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.