473,407 Members | 2,312 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,407 software developers and data experts.

Read Hex value from Specific address

I am trying to use Filestream to read a file ( .DAT) that contains values in HEX that I want to convert to text. I know the
different offset addresses for each portion of the data I am trying to retrieve. But, I am having problems actually reading the
data for the number of Bytes that I need to get from each address.
Here is some of the code I am currently working with:
Dim fsread As FileStream = File.Open(OpenFileDialog1.FileName, FileMode.Open)

Dim add As String

add = fsread.Seek(&HD0, SeekOrigin.Begin)

RichTextBox1.Text = add

Catch ex As Exception

'display error messages if they appear

MessageBox.Show(ex.Message)

End Try

End If

Using the above code, I get the Dec value for D0 ( 208) , instead of reading the contents of the data at that particular
address.

Any ideas on what I am doing wrong?

james


Nov 21 '05 #1
8 7230
I am confused by your post

Are you having problems actiually reading a specific set block size of data?

Also, your RichTextBox only holds one piece of data & isn't appended to it.

RichTextBox.Text = add

Don't you mean:

RichTextBox.Text += add ' Keep appending, but you need to use a loop to do
it this way.

You also state 'SeekOrigin.Begin'. What about 'SeekOrigin.Current'?

How big is the data you want to read? How big is the blocksize you want to
read?

Please just clarify

"james" wrote:
I am trying to use Filestream to read a file ( .DAT) that contains values in HEX that I want to convert to text. I know the
different offset addresses for each portion of the data I am trying to retrieve. But, I am having problems actually reading the
data for the number of Bytes that I need to get from each address.
Here is some of the code I am currently working with:
Dim fsread As FileStream = File.Open(OpenFileDialog1.FileName, FileMode.Open)

Dim add As String

add = fsread.Seek(&HD0, SeekOrigin.Begin)

RichTextBox1.Text = add

Catch ex As Exception

'display error messages if they appear

MessageBox.Show(ex.Message)

End Try

End If

Using the above code, I get the Dec value for D0 ( 208) , instead of reading the contents of the data at that particular
address.

Any ideas on what I am doing wrong?

james


Nov 21 '05 #2
Sorry about the confusion. Eventually, I will need to go thru the entire file. But, first I need to retreive different values at
different addresses in the header of the file(s) that will give me other information that I am looking for.
Well, to be clearer, I am working on reading an old Dataflex database .DAT file(s) (63 Tables in 63 seperate files, all
different sizes and number of fields). At location H08 is the number of rows in the file, and at H59 the number of fields.
Also, there are addresses that contain the field type for each field and the field size for each field. Also, there is an
address that contains the size of the record After that comes a null record. Then the actual field data.
The field names are in a seperate, Text file.
I can open the .TAG file that contains the field names and I have the names for the fields in each table. (seperate .TAG file
for each table) Then, I need to open the .DAT file and extract the information to build the rest of the table and save it to an
Access database.
The reason I am not looping thru the file or just reading to the end, is I wanted to be able to actually go to a specific
address and read the value at that address correctly. Once I can accurately do that, I feel that I can then proccess the rest of
the file with little to no problems. As for using SeekOrigin.Begin or SeekOrigin.Current, that was just one of the options that
Intellisense offered that I have tried using to read the value(s) I needed. Nothing carved in stone as to using that specific
function.
As I said in my original post, I am open to suggestions on how to this. I am not stuck on using FileStream or anything else.
james

"Crouchie1998" <Cr**********@discussions.microsoft.com> wrote in message
news:F4**********************************@microsof t.com...
I am confused by your post

Are you having problems actiually reading a specific set block size of data?

Also, your RichTextBox only holds one piece of data & isn't appended to it.

RichTextBox.Text = add

Don't you mean:

RichTextBox.Text += add ' Keep appending, but you need to use a loop to do
it this way.

You also state 'SeekOrigin.Begin'. What about 'SeekOrigin.Current'?

How big is the data you want to read? How big is the blocksize you want to
read?

Please just clarify

"james" wrote:
I am trying to use Filestream to read a file ( .DAT) that contains values in HEX that I want to convert to text. I know the
different offset addresses for each portion of the data I am trying to retrieve. But, I am having problems actually reading
the
data for the number of Bytes that I need to get from each address.
Here is some of the code I am currently working with:
Dim fsread As FileStream = File.Open(OpenFileDialog1.FileName, FileMode.Open)

Dim add As String

add = fsread.Seek(&HD0, SeekOrigin.Begin)

RichTextBox1.Text = add

Catch ex As Exception

'display error messages if they appear

MessageBox.Show(ex.Message)

End Try

End If

Using the above code, I get the Dec value for D0 ( 208) , instead of reading the contents of the data at that particular
address.

Any ideas on what I am doing wrong?

james


Nov 21 '05 #3
james wrote:
Dim fsread As FileStream = File.Open(OpenFileDialog1.FileName, FileMode.Open) Dim add As String add = fsread.Seek(&HD0, SeekOrigin.Begin)


The seek method does not read data, it only positions the file pointer
to the location you want. You must call the read method to actually
read data.

Nov 21 '05 #4
Chris, thank you. I guess I did not understand the .Seek method correctly.
One other question. Can I use a Hex value ( like the &H0 in my code sample) to set the file pointer? Or do I need to convert
that to a decimal value first?
james

"Chris Dunaway" <du******@gmail.com> wrote in message news:11*********************@z14g2000cwz.googlegro ups.com...
james wrote:
Dim fsread As FileStream = File.Open(OpenFileDialog1.FileName,

FileMode.Open)
Dim add As String

add = fsread.Seek(&HD0, SeekOrigin.Begin)


The seek method does not read data, it only positions the file pointer
to the location you want. You must call the read method to actually
read data.

Nov 21 '05 #5
I think using a hex constant is fine.

Nov 21 '05 #6
Just tried it like this:

Dim filename As String = OpenFileDialog1.FileName

Dim fs As FileStream

fs = New FileStream(filename, FileMode.Open, FileAccess.Read)

Dim r As StreamReader = New StreamReader(fs)

Dim sz As Integer = fs.Length

Dim mybytearray() As Byte = New Byte(sz) {}

Dim myencoding As ASCIIEncoding = New ASCIIEncoding

r.BaseStream.Seek(&H2D0, SeekOrigin.Current)

r.BaseStream.Read(mybytearray, 0, 7)

ListBox1.Items.Add(myencoding.GetString(mybytearra y))

r.Close()

fs.Close()

(converted from some C# code I found using Google)

This works really good. But, now I have another question. ( of course you knew that didn't you :-) )

In this line:

r.BaseStream.Read(mybytearray,0,7)

I am reading 7 characters and adding that to my listbox. And it works just fine. But, what I really want to do is to read

all the characters starting at &H2D0 till I encounter a Chr(32) (Space) and then stop. That way I can read variable length

strings (and or numbers) without having to know the exact length of the string I am reading. Is there any way to read the
stream

until it encounters a Space ( chr(32) ) or any other character I might specify?

james

"Chris Dunaway" <du******@gmail.com> wrote in message news:11*********************@z14g2000cwz.googlegro ups.com...
I think using a hex constant is fine.

Nov 21 '05 #7
The only way I know would be to read byte by byte until you hit a
space. An alternative would be to read a whole line using the ReadLine
method and then use the Split method to break out the string into
individual words.

Nov 21 '05 #8
Thanks Chris. I will give that a try.
james

"Chris Dunaway" <du******@gmail.com> wrote in message news:11**********************@c13g2000cwb.googlegr oups.com...
The only way I know would be to read byte by byte until you hit a
space. An alternative would be to read a whole line using the ReadLine
method and then use the Split method to break out the string into
individual words.

Nov 21 '05 #9

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

Similar topics

0
by: Majordomo | last post by:
-- >>>> --36742377 **** Command '--36742377' not recognized. >>>> Content-Type: text/plain; charset=us-ascii **** Command 'content-type:' not recognized. >>>> Content-Transfer-Encoding: 7bit...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
5
by: Jeong-Gun Lee | last post by:
I'm writing a code of writing a value to a specific memory address. ================================================================= #include <stdio.h> int main() { long air; long...
8
by: Ravindranath Gummadidala | last post by:
Hi All: I am trying to understand the C function call mechanism. Please bear with me as I state what I know: "every invocation of a function causes a frame for that function to be pushed on...
35
by: hasho | last post by:
Why is "call by address" faster than "call by value"?
19
by: Mark Richards | last post by:
I've been programming for many years, but have only recently taken a deep "C" dive (bad pun, i know) and need a lot of explanation from an expert. My questions center around those mysterious...
1
by: Magix | last post by:
Hi, I have these string data: str_data1, str_data2, str_data3, which capture some value after a routine process A. Then I would like to write (append) these 3 string values into a text file each...
8
by: a | last post by:
I have a struct to write to a file struct _structA{ long x; int y; float z; } struct _structA A; //file open write(fd,A,sizeof(_structA)); //file close
12
by: kath | last post by:
How do I read an Excel file in Python? I have found a package to read excel file, which can be used on any platform. http://www.lexicon.net/sjmachin/xlrd.htm I installed and working on the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.