473,909 Members | 5,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Random Access Files

In VB6 I could use random access and fixed record lengths to read specific
records from a test file. Eg the following code would save a LogEntry to a
file at the location specified by RecordNumber.

Private Type LogEntry
Date As String * 20
Number As String * 20
Source As String * 100
Description As String * 100
CRLF As String * 2
End Type
Public Sub RecordError(Num As Long, Source As String, Desc As String)
Dim FF As Integer
Dim CurrentRecord As LogEntry
'set the record values
With CurrentRecord
.Date = Trim(Format$(No w, "DD/MM/YYYY HH:MM:SS"))
.Number = Num
.Source = Trim(Source)
.Description = Trim(Desc)
.CRLF = vbCrLf
End With
'save the record
FF = FreeFile
Open "file.txt" For Random As FF Len = 242
Put FF, RecordNumber, CurrentRecord
Close #FF
End Sub

How do I do this sort of thing in Csharp? I can't seem to find a way to
read/write fixed sized records.

Thanks

Alan
Dec 20 '05 #1
1 2356
Alan,

There really isn't a simple way to do this.

The best way to do this would be to declare the LogEntry class with the
properties that you specify. Then, I would have a method which would
perform the serialization of the items into a byte array which is 242 bytes
long.

Then, you would have a method which would open the file, move the file
pointer to the appropriate location, write the record, and then close it.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Alan Roberts" <al**@statistix l.co.uk> wrote in message
news:Oh******** ******@tk2msftn gp13.phx.gbl...
In VB6 I could use random access and fixed record lengths to read specific
records from a test file. Eg the following code would save a LogEntry to
a file at the location specified by RecordNumber.

Private Type LogEntry
Date As String * 20
Number As String * 20
Source As String * 100
Description As String * 100
CRLF As String * 2
End Type
Public Sub RecordError(Num As Long, Source As String, Desc As String)
Dim FF As Integer
Dim CurrentRecord As LogEntry
'set the record values
With CurrentRecord
.Date = Trim(Format$(No w, "DD/MM/YYYY HH:MM:SS"))
.Number = Num
.Source = Trim(Source)
.Description = Trim(Desc)
.CRLF = vbCrLf
End With
'save the record
FF = FreeFile
Open "file.txt" For Random As FF Len = 242
Put FF, RecordNumber, CurrentRecord
Close #FF
End Sub

How do I do this sort of thing in Csharp? I can't seem to find a way to
read/write fixed sized records.

Thanks

Alan

Dec 24 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
7020
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
3864
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 memory leaks too. How can i track these down ?
3
10228
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#. Is it possible to map directly a buffer (read from a stream) to a Structure in memory ? If yes, how to do this ? If no, any hint to read/access/write random access files ?
1
2393
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 to expose the problem: This post deals with type (2) files.
5
2958
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 I try to start to run/debug a project (through Visual Studio) Server Error in '/Intranet' Application. -------------------------------------------------------------------------------- Compilation Error Description: An error occurred during...
3
3836
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 nutshell when testing my ASP.NET (localhost) apps images randomly don't load on the page. Examining the IIS logfile shows the missing images give 401 or 403 errors. Here's an example - 10:15:47 127.0.0.1 GET...
13
2585
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 get the FileStream class to work with Random Access Files, but it requires the data Structures to be in a byte array. How do I convert them? S.
16
7198
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 unchanged). How can I do that in Python? Claudio Grondi
39
2493
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 MyClass from module2. module2 does not import random. module1 sets a seed like this::
5
2425
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 binary values. If there are no corresponding Types I will manually convert the VB6 binary values (e.g. BinaryFormatter...). Where can I find the
0
10037
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9879
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10921
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11052
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10540
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8099
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7249
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3359
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.