473,836 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(OpenF ileDialog1.File Name, FileMode.Open)

Dim add As String

add = fsread.Seek(&HD 0, SeekOrigin.Begi n)

RichTextBox1.Te xt = 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 7272
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.Tex t = add

Don't you mean:

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

You also state 'SeekOrigin.Beg in'. What about 'SeekOrigin.Cur rent'?

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(OpenF ileDialog1.File Name, FileMode.Open)

Dim add As String

add = fsread.Seek(&HD 0, SeekOrigin.Begi n)

RichTextBox1.Te xt = 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.Begi n or SeekOrigin.Curr ent, 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

"Crouchie19 98" <Cr**********@d iscussions.micr osoft.com> wrote in message
news:F4******** *************** ***********@mic rosoft.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.Tex t = add

Don't you mean:

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

You also state 'SeekOrigin.Beg in'. What about 'SeekOrigin.Cur rent'?

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(OpenF ileDialog1.File Name, FileMode.Open)

Dim add As String

add = fsread.Seek(&HD 0, SeekOrigin.Begi n)

RichTextBox1.Te xt = 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(OpenF ileDialog1.File Name, FileMode.Open) Dim add As String add = fsread.Seek(&HD 0, SeekOrigin.Begi n)


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******** *************@z 14g2000cwz.goog legroups.com...
james wrote:
Dim fsread As FileStream = File.Open(OpenF ileDialog1.File Name,

FileMode.Open)
Dim add As String

add = fsread.Seek(&HD 0, SeekOrigin.Begi n)


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(file name, 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.Se ek(&H2D0, SeekOrigin.Curr ent)

r.BaseStream.Re ad(mybytearray, 0, 7)

ListBox1.Items. Add(myencoding. GetString(mybyt earray))

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.Re ad(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******** *************@z 14g2000cwz.goog legroups.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.goo glegroups.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
1571
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 **** Command 'content-transfer-encoding:' not recognized. >>>> >>>> something is fool
18
4899
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) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
5
45747
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 *air_address;
8
14013
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 stack. this contains the arguments this function was called with, address to return to after return from this function (the location in the previous stack frame), location of previous frame on stack (base or start of this frame) and local variables...
35
10809
by: hasho | last post by:
Why is "call by address" faster than "call by value"?
19
2107
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 pointer beasties. The following code is excerpted from digitemp, a program that reads 1-wire devices. Digitemp is the work of Brian C. Lane. As I walk through this code, I have a number of questions. I'm hoping someone with experience in...
1
4316
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 time after routine process A, the text file is named "mytext.dat" in following format with "#####" as separator. The maximum entries of them is 5. When reaching the fifth entry, it will delete the very first entry.
8
23912
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
6029
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 examples, I found its printing of cell's contents in a different manner. print sh.row(rx)
0
9825
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
10852
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10553
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
10596
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
10255
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...
0
9382
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7793
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
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3116
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.