By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

Random Access Files

P: n/a
Hi Guys

How do I check whether or not a specific record number in
an initialised random access file is empty or not ?

What I need to do is when DisplayButton.Click event is
triggered the procedure should check if the record number
(seat number) is valid(this works fine), then if the
record number(seat number) is vaild but not been assigned
to anyone the app should throw up a messagebox "seat X is
vacant"

would it be as simple as:
intSeat = val(me.SeatTextBox.Text)

if udtParticipant.strParticipant.trimstart andalso
udtParticipant.strCompany.trimstart = "" then

messagebox.show "Blah blah" & intSeat & "blah"

end if
any guidance is appreciated as always...
\\\
Private Sub DisplayButton_Click(ByVal sender As Object,
ByVal e As System.EventArgs) _
Handles DisplayButton.Click
'declare variables
Dim intSeat As Integer
Dim udtParticipant As ParticipantStruc

'aasign seat number to a variable
intSeat = Val(Me.SeatTextBox.Text)

'verify that the seat number is valid
If intSeat > 0 AndAlso intSeat < 21 Then
'open the file
FileOpen(1, "Participant.Data",
OpenMode.Random, OpenAccess.ReadWrite, _
OpenShare.Shared, Len(udtParticipant))
'read the record
FileGet(1, udtParticipant, intSeat)
'assign field values to textboxes
Me.ParticipantTextBox.Text =
udtParticipant.strParticipant.TrimEnd
Me.CompanyTextBox.Text =
udtParticipant.strCompany.TrimEnd
'close the file
FileClose(1)
Else
MessageBox.Show("Please select seat number 1 -
20", "Seminar Information", _
MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
///

Regards Steve
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Here's the code in it's entirety just in case you need
it...

\\\
'declare form-level record structure
Structure ParticipantStruc
<VBFixedString(20)> Public strParticipant As
String
<VBFixedString(20)> Public strCompany As String
End Structure

Private Sub ExitButton_Click(ByVal sender As Object,
ByVal e As System.EventArgs) _
Handles ExitButton.Click
Me.Close()
End Sub

Private Sub SelectText(ByVal sender As Object, ByVal
e As System.EventArgs) _
Handles SeatTextBox.Enter, ParticipantTextBox.Enter,
CompanyTextBox.Enter
Dim objTextBox As TextBox
objTextBox = sender
objTextBox.SelectAll()
End Sub

Private Sub SeatTextBox_TextChanged(ByVal sender As
Object, ByVal e As System.EventArgs) _
Handles SeatTextBox.TextChanged
Me.ParticipantTextBox.Text = ""
Me.CompanyTextBox.Text = ""
End Sub

Private Sub InitializeButton_Click(ByVal sender As
Object, ByVal e As System.EventArgs) _
Handles InitializeButton.Click
'declare variables
Dim intSeat, intButton As Integer
Dim udtParticipant As ParticipantStruc

'verify the user wants to initialise the file
intButton = MessageBox.Show("Initialise the
file ?", "Seminar Information", _
MessageBoxButtons.YesNo,
MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button2)
If intButton = DialogResult.No Then
MessageBox.Show("File was not
initialised", "Seminar Information", _
MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
'assign spaces to string field variables
udtParticipant.strParticipant = Space(20)
udtParticipant.strCompany = Space(20)
'open the file
FileOpen(1, "Participant.data",
OpenMode.Random, OpenAccess.ReadWrite, _
OpenShare.Shared, Len(udtParticipant))
'initialise the file then close the file
For intSeat = 1 To 20
FilePut(1, udtParticipant, intSeat)
Next intSeat
FileClose(1)
MessageBox.Show("File was
intialised", "Seminar Information", _
MessageBoxButtons.OK,
MessageBoxIcon.Information)

End If

End Sub

Private Sub AddButton_Click(ByVal sender As Object,
ByVal e As System.EventArgs) _
Handles AddButton.Click
'declare variables
Dim intSeat As Integer
Dim udtParticipant As ParticipantStruc
'verify participants name was entered
If Me.ParticipantTextBox.Text.TrimStart <> "" Then
'assign the seat number to a variable
intSeat = Val(Me.SeatTextBox.Text)
'verify that the seat number is valid
If intSeat > 0 AndAlso intSeat < 21 Then
'assign names on form to field variables
udtParticipant.strParticipant =
Me.ParticipantTextBox.Text
udtParticipant.strCompany =
Me.CompanyTextBox.Text
'open the file
FileOpen(1, "Participant.data",
OpenMode.Random, OpenAccess.ReadWrite, _
OpenShare.Shared, Len(udtParticipant))
'write the record and then close the file
FilePut(1, udtParticipant, intSeat)
FileClose(1)
Else
MessageBox.Show("Please select seat
number 1 - 20", "Seminar Information", _
MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
Else
MessageBox.Show("Please enter participants
name", "Seminar Information", _
MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
Me.SeatTextBox.Focus()
End Sub

Private Sub DisplayButton_Click(ByVal sender As
Object, ByVal e As System.EventArgs) _
Handles DisplayButton.Click
'declare variables
Dim intSeat As Integer
Dim strMessage As String = ("Seat" & intSeat
& "is vacant")
Dim udtParticipant As ParticipantStruc

'aasign seat number to a variable
intSeat = Val(Me.SeatTextBox.Text)

'verify that the seat number is valid
If intSeat > 0 AndAlso intSeat < 21 Then

'\\\ (This doesn't work, cast from boolean
to "" not vaild)
'If udtParticipant.strParticipant AndAlso
udtParticipant.strCompany = "" Then
'MessageBox.Show(strMessage, "Seminar
Information", MessageBoxButtons.OK,
MessageBoxIcon.Information)
'End If
'///

'open the file
FileOpen(1, "Participant.Data", OpenMode.Random,
OpenAccess.ReadWrite, _
OpenShare.Shared, Len(udtParticipant))
'read the record
FileGet(1, udtParticipant, intSeat)
'assign field values to textboxes
Me.ParticipantTextBox.Text =
udtParticipant.strParticipant.TrimEnd
Me.CompanyTextBox.Text =
udtParticipant.strCompany.TrimEnd
'close the file
FileClose(1)
Else
MessageBox.Show("Please select seat number 1 -
20", "Seminar Information", _
MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If

End Sub
End Class

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.