473,837 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:\Documen ts and Settings\My Documents\Visua l Studio
Projects\VbNet\ project\Write_I ni_File\bin\col ours.dat", FileMode.Open,
FileAccess.Read )
Dim br2 As New BinaryReader(st 2)
Do Until br2.PeekChar = -1
ListBox1.Items. Add(br2.ReadByt e) ==>this is not what i wanted
...i wanted hex values (colour) into listbox
Loop
br2.Close()
st2.Close()

Nov 22 '05 #1
4 1893
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.Re adByte 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.ReadByt e().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
341
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 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
8
31019
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
19072
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 example, I'd like a Windows client PC (native little endian) to be able to read a network stream coming in as big endian. I want to be able to read a short for example without worrying about flipping the bytes. Thank you, Laszlo
2
7380
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 processing in my application: Here is a sample where I convert from a stream to a byte array: strm = mqMsg.BodyStream; BinaryReader br = new BinaryReader(strm); byteArray= br.ReadBytes(Convert.ToInt32(strm.Length));
2
23626
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 returned on the ReadString call. public string BinaryRead(string fileName) { FileStream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
2
1819
by: I_AM_DON_AND_YOU? | last post by:
Can BinaryReader Object read the Word file?
10
2550
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 Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.538 / Virus Database: 333 - Release Date: 11/10/2003
8
37137
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
2264
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 and then read: string1, integer1, double1
6
5816
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 bytes of the file and some of these files are 600Mb -1 GB in size. I am getting "outofMemory.." exceptions on the largest files and the other files take "forever" to get the last 100 bytes. This is the code I have currently that works with...
0
9683
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10883
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
10578
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
10631
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
10276
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
9409
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
7813
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
5670
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3126
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.