Results 1 to 10 of 10

Thread: [RESOLVED] Binary Writer (complete string)

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2011
    Posts
    50

    Question [RESOLVED] Binary Writer (complete string)

    I want to write a string into a binary file.

    The length of the string is 22
    position 1036

    Write name in that chain, the length of the name varies but is always between a length of 22.

    As I can fill the remaining length of the string with blank spaces?

    The empty spaces in hex is "00"

    Thanks in advance.
    Last edited by sevito; Dec 2nd, 2011 at 07:51 AM.

  2. #2
    Member
    Join Date
    Nov 2009
    Posts
    62

    Re: Binary Writer (complete string)

    No absolutely sure about this, but I think you'll find that '00' is effectively a nul or chr$(0) and VB will treat that as end of string - I may be wrong

    Pad out with spaces chr$(32) is my best advice

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2011
    Posts
    50

    Re: Binary Writer (complete string)

    I do not think I explained well

    Dim s as string

    TextBox1.MaxLength = 22
    Textbox1.text = "ANTONIO" 'length 7

    s = textbox1.text & "00000000000000"

    The problem is that the name may vary in size
    How to determine the number of "0" to add?

  4. #4
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Binary Writer (complete string)

    At a quick guess:

    Code:
    s = textbox1.Text & new String("0",  Math.Max(0, 22 - textbox1.Text.Length))

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Binary Writer (complete string)

    Code:
            'test data
            TextBox1.Text = "Dewayne"
    
            Dim s As String = TextBox1.Text.PadRight(22, "0"c)
    
            Debug.WriteLine(s)
            Debug.WriteLine(s.Length)
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2011
    Posts
    50

    Re: Binary Writer (complete string)

    Thank you friends.

  7. #7
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: [RESOLVED] Binary Writer (complete string)

    Oo good find db, I have not used that method myself.

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] Binary Writer (complete string)

    Ummmm.... I could be wrong about this but.... won't "0"c give you 0? Which isn't the same as the hex value of 0. "0"c will give you the CHARACTER "0" ... which is hex 2F...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [RESOLVED] Binary Writer (complete string)

    Quote Originally Posted by techgnome View Post
    Ummmm.... I could be wrong about this but.... won't "0"c give you 0? Which isn't the same as the hex value of 0. "0"c will give you the CHARACTER "0" ... which is hex 2F...

    -tg
    I wasn't sure what the fill character was supposed to be either.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] Binary Writer (complete string)

    Ok, I was jsut checking... thought maybe you knew something I didn't... according to the OP, "The empty spaces in hex is "00"" ... which means it's null padded... which is always a joy in VB... :P

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width