473,387 Members | 3,684 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,387 software developers and data experts.

read back in Binaryreader

i saved file in binary. i saved 16 colours.. but how do i read back
values into listbox?

Dim st2 As Stream = File.Open _
("C:\Documents and Settings\My Documents\Visual Studio
Projects\VbNet\project\Write_Ini_File\bin\colours. dat", FileMode.Open,
FileAccess.Read)
Dim br2 As New BinaryReader(st2)
Do Until br2.PeekChar = -1
ListBox1.Items.Add(br2.ReadByte) ==>this is not what i wanted
...i wanted hex values (colour) into listbox
Loop
br2.Close()
st2.Close()

Nov 22 '05 #1
4 1858
Hi Supra,

How you read the colors back depends on how you wrote them in the first place.
If the colors are in in hex RGB format (3 bytes) you could do something like
(C# code)

byte[] rgb = br2.ReadBytes(3);
ListBox1.Items.Add(rgb[0].ToString("X") + rgb[1].ToString("X") + rgb[2].ToString("X"));

Of course, PeekChar wouldn't work since you read three bytes.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 22 '05 #2
i will explain to u. but i have done in vb6 b4.
in mirc chat when user clicked colour and click Okbutton to save file
in binary. but how do i read back values(limited 6 only) and also how
do i write back when saving? i had 16 colours in file.
regards

Morten Wennevik wrote:
Hi Supra,

How you read the colors back depends on how you wrote them in the
first place.
If the colors are in in hex RGB format (3 bytes) you could do
something like
(C# code)

byte[] rgb = br2.ReadBytes(3);
ListBox1.Items.Add(rgb[0].ToString("X") + rgb[1].ToString("X") +
rgb[2].ToString("X"));

Of course, PeekChar wouldn't work since you read three bytes.


Nov 22 '05 #3
I'm sorry Supra, but I'm not familiar with how mirc saves the file.
However if you have done it in VB6 you should be able to do it in VB.Net.

The BinaryReader.ReadByte reads a byte. It may be that this byte is all that is necessary to store color information for mirc but you need to convert the byte into some other value. Byte.ToString("X") will convert the byte to a hexadecimal string value. So

ListBox1.Items.Add(br2.ReadByte().ToString("X"))

should give you the hex value of a single byte. However I believe you need all three bytes to get the full color.

If you give us the VB6 code for the color reading it would be easier for us to help you.

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 22 '05 #4
Hi Supra,

How you read the colors back depends on how you wrote them in the first place.
If the colors are in in hex RGB format (3 bytes) you could do something like
(C# code)

byte[] rgb = br2.ReadBytes(3);
ListBox1.Items.Add(rgb[0].ToString("X") + rgb[1].ToString("X") + rgb[2].ToString("X"));

Of course, PeekChar wouldn't work since you read three bytes.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 22 '05 #5

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

Similar topics

4
by: Supra | last post by:
i saved file in binary. i saved 16 colours.. but how do i read back values into listbox? Dim st2 As Stream = File.Open _ ("C:\Documents and Settings\My Documents\Visual Studio...
8
by: Patrik Malmström | last post by:
How do I read, write a file binary? I want to open, say, file.exe read it in to the program, then write it out to file2.exe. Like file copy, anyone have a code sample?
14
by: Laszlo Szijarto | last post by:
Can BinaryReader be forced to read a stream, say a TCP/IP stream or memory stream or even file stream in big endian order or do I have to write something custom to reverse the byte order? So, for...
2
by: Matt | last post by:
I just wanted to know if I am converting to/from streams the easiest and correct way. I am performing the following statements to convert byte arrays to and from streams during different...
2
by: Bob Rock | last post by:
I already found an alternative way to accomplish this (using ReadBytes), still I'd like to understand why I'm getting and error reading a text file using the following method. The exception is...
2
by: I_AM_DON_AND_YOU? | last post by:
Can BinaryReader Object read the Word file?
10
by: Tibby | last post by:
I need to read/write not only text files, but binary as well. It seems like on binary files, it doesn't right the last 10% of the file. -- Thanks --- Outgoing mail is certified Virus...
8
by: S Shulman | last post by:
Hi All I need to read a file to an array of bytes (any type of file) I tried using FileStream and BinaryReader but it doesn't seem to work Thank you, Shmuel
5
by: Just Me | last post by:
Using streams how do I write and then read a set of variables? For example, suppose I want to write into a text file: string1,string2,string3 Then read them later. Suppose I want to write...
6
by: =?Utf-8?B?VGhvbWFzWg==?= | last post by:
Hi, Is it possible to read a file in reverse and only get the last 100 bytes in the file without reading the whole file from the begining? I have to get info from files that are in the last 100...
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: 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
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.