By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,916 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,916 IT Pros & Developers. It's quick & easy.

read back in Binaryreader

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.