473,386 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Random Access Files

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
1 5213
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Oin Zea | last post by:
Is it possible for to program to access a random file at the same time and perform actions like create a new record?
9
by: greeningster | last post by:
I have written an application in Visual C++ for a customer but it seems to crash randomly. Could anyone give me any help on how I could track this down ? Also, there appears there might be...
3
by: Cybertof | last post by:
Hello, Is there a simple way to read a random access file that has been created with VB6 using direct writing to disk of Type....End Type structures ? I have not found this possibility in C#. ...
1
by: Patrick | last post by:
Hi, This post is the 'sequel' ;) of the "Data Oriented vs Object Oriented Design" post, but it can be read and treated apart from that one. I will just quote the beginning of my previous message...
5
by: Raterus | last post by:
I'm just throwing this error out for my sanity, I've seen posts about this, but never solutions. I'm using VS.NET 2003, Framework 1.1, and I'm getting a random error about every 1 out of 10 times...
3
by: Simon | last post by:
This problem has been driving me mad for months.... Seen a few posts on forums about it but no answers... No mention on MSDN etc. XP Pro SP1, VS.NET (c#) .Net framework 1.1, IIS 5.1. In a...
13
by: Stuart | last post by:
I have converted a VB6 app to VB.NET. It's function is to generate reports from a Random Access file but the .NET version is pathetically slow compared to the VB6 version. I think I need to to...
16
by: Claudio Grondi | last post by:
I have a 250 Gbyte file (occupies the whole hard drive space) and want to change only eight bytes in this file at a given offset of appr. 200 Gbyte (all other data in that file should remain...
39
by: Alan Isaac | last post by:
This may seem very strange, but it is true. If I delete a .pyc file, my program executes with a different state! In a single directory I have module1 and module2. module1 imports random and...
5
by: Peter | last post by:
Hi I will use a Random Access File in dotnet/csharp. The file is created with Visual Basic 6 (VB6). My Problem is to find out the corresponding Types I had to use in dotnet - reading the VB6...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.