read back in Binaryreader
Messages   Related Types
This message was discovered on microsoft.public.dotnet.general.

Post a new message to this list...

Supra
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()

Reply to this message...
 
    
Morten Wennevik
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]
Reply to this message...
 
    
Supra
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:

[Original message clipped]

Reply to this message...
 
    
Morten Wennevik
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]
Reply to this message...
 
    
Morten Wennevik
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]
Reply to this message...
 
 
System.Byte
System.IO.BinaryReader
System.IO.File
System.IO.FileAccess
System.IO.FileMode




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com