CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009
    Posts
    7

    [RESOLVED] Subtractinghexidecimal Numbers and keeping leading 0's (vb2005)

    Well this is what I have so far:
    Code:
    Dim code_address
            Dim code_offset
            Dim addition_code
            Dim convert_code
            Dim i As Integer
    
            code_address = Convert.ToInt32(txt_code_address.Text, 16)
            code_offset = Convert.ToInt32(txt_offset.Text, 16)
            addition_code = code_address + code_offset
            convert_code = Convert.ToString(addition_code, 16)
            txt_answer.Text = convert_code
            txt_answer.Text = (i.ToString.PadLeft(8, "0"c))
            txt_answer.Text = (i.ToString.PadRight(8, "0"c))
    What im trying to make is an offset calculator and I need the leading zeros to stay, before I tried to find a fix for it it worked just fine, just no zero's.

    Any case as of now all it gives me is 8 zero's
    Last edited by Zero1UP; February 16th, 2009 at 12:12 AM.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Subtractinghexidecimal Numbers and keeping leading 0's (vb2005)

    Declare things:
    Code:
    Dim code_address  As Int32 = Convert.ToInt32(txt_code_address.Text, 16)
    Dim code_offset  As Int32 = Convert.ToInt32(txt_offset.Text, 16)
    Dim addition_code = code_address + code_offset
    Dim convert_code = Convert.ToString(addition_code, 16)
    Dim i as String = convert_code 
    ' modify this part below
    txt_answer.Text = convert_code
    txt_answer.Text = (i.ToString.PadLeft(8, "0"c))
    txt_answer.Text = (i.ToString.PadRight(8, "0"c))
    I didn't test things, but that should fix the i reference

    EDIT: You need to use HEX() to subtract (not add like you have)
    Last edited by dglienna; February 15th, 2009 at 09:54 PM.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Feb 2009
    Posts
    7

    Re: Subtractinghexidecimal Numbers and keeping leading 0's (vb2005)

    Quote Originally Posted by dglienna View Post
    Declare things:
    Code:
    Dim code_address  As Int32 = Convert.ToInt32(txt_code_address.Text, 16)
    Dim code_offset  As Int32 = Convert.ToInt32(txt_offset.Text, 16)
    Dim addition_code = code_address + code_offset
    Dim convert_code = Convert.ToString(addition_code, 16)
    Dim i as String = convert_code 
    ' modify this part below
    txt_answer.Text = convert_code
    txt_answer.Text = (i.ToString.PadLeft(8, "0"c))
    txt_answer.Text = (i.ToString.PadRight(8, "0"c))
    I didn't test things, but that should fix the i reference

    EDIT: You need to use HEX() to subtract (not add like you have)
    Yea I know, it was a mistype in the title , either way I still had the same issue for both add and sub, but I'll give this a go

    EDIT:
    Thanks a ton worked like a charm, the only thing that I didn't need in there was:
    txt_answer.Text = (i.ToString.PadRight(8, "0"c))
    Last edited by Zero1UP; February 15th, 2009 at 10:54 PM.

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

Featured