Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 15th, 2007, 01:45 PM
Authorized User
 
Join Date: Feb 2007
Location: Binghamton, NY, USA.
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to toddw607 Send a message via Yahoo to toddw607
Default Getting a set number of bytes from a file

Hi everyone,
    I have a seemingly simple problem which has been driving me crazy. I have a file consisting of a number of bytes and I want to take out eight bytes at a time, combine all eight bytes into a string, convert the new string to decimal and output the decimal to a text file. Here is my code that I've been working with:

Code:
                  Dim index As Integer = 8
                  For i = 0 To s1.Length() - 1 
                      bytes(i) = s1.ReadByte
                      If (i < index) Then
                          s2.WriteByte(bytes(i))
                      End If
                      index = index + 8
                  Next
      Here s1 is my filestream reader and s2 is my filestream writer. So far this prints out to the writer file the same thing as the reader file. I am not familiar with working with bytes and this has been driving me crazy. Can someone please help me out. Thanks!

Reply With Quote
  #2 (permalink)  
Old August 15th, 2007, 02:07 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,190
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there... homework????

anyway.. what are s1 and s2?? files??? opened like what???

you are writing one byte at a time, the same one you just readed ;)

look at this:

Code:
    Dim index As Integer = 8
    For i = 0 To s1.Length() - 1 
        'you read from somewhere a byte, and you store it inside a position of an array
        bytes(i) = s1.ReadByte
        If (i < index) Then
            'you get the same byte you read before, and put in into another file
            s2.WriteByte(bytes(i))
        End If
        index = index + 8
    Next
I think your logic is somehow wrong.. you have to read 8 bytes from the source, combine them (what's the diference between file 1 and 2??) and then you have to save it to destination...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
Reply With Quote
  #3 (permalink)  
Old August 15th, 2007, 02:17 PM
Authorized User
 
Join Date: Feb 2007
Location: Binghamton, NY, USA.
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to toddw607 Send a message via Yahoo to toddw607
Default

    This isn't homework, here's an explanation of what I'm trying to do: I'm trying to get coordinates of text out of a CGM file, convert the hex values into decimal and place the decimal coordinates into a transparent layer to fit over the CGM in order for the CGM to be clickable in certain spots.
    s1 (file 1) is defined as: s1 = New FileStream((FILE_NAME_IMAGE & fileName), FileMode.Open, FileAccess.Read). s2 (file 2) is defined as: s2 = New System.IO.FileStream(newName1, FileMode.Create, FileAccess.Write). All I am attempting to accomplish right now is reading in from s1, placing the hex values into a string (without any spaces between hex values) and place the string values into a text file. I know how to convert to a decimal after I get the string of 8 hex values into the file but all I am trying to do is get the string for every series of 8 hex values within the file. Sorry, I should have explained this before.

Reply With Quote
  #4 (permalink)  
Old August 15th, 2007, 03:22 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,190
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

I understand what are you trying to do, but I don't understand the way you are trying to achieve it..

Code:
    ' the next for is not necessary, search a better method to know when you reach eof
    For i = 0 To s1.Length() - 1 
        for j as int16 = 0 to 7
            'the next line could throw and error if reach the oef.
            bytes(j) = s1.ReadByte
        next j
        'better replace last for with something like:
        's1.read(bytes,0,8) that does the same and return the number of
        ' bytes readed...
        'convert your byte array to what you need, don't know how.
        s2.WriteByte(yournewbyte)
    'the next line surely will be replaced if you change the way you read the file
    Next


HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
convert 4 bytes to bit array Vinny_68 Pro Visual Basic 2005 1 March 21st, 2007 06:40 PM
Script to delete files after a set number jkutey Beginning VB 6 2 October 29th, 2005 10:45 AM
How to set a user-defined Serial Number ? justin_min VS.NET 2002/2003 1 February 17th, 2005 07:48 AM
[?]how to set page number when printing? jodgen VB How-To 0 April 14th, 2004 03:30 AM
Bytes doa-wnloaded vincentvdm Classic ASP Professional 0 August 17th, 2003 02:52 PM



All times are GMT -4. The time now is 10:24 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.