Results 1 to 3 of 3

Thread: Using &H with a variable

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    38

    Using &H with a variable

    Hello, I am building a program to edit stuff at the binary level. I found that by using &HAA, for example, it would write AA in hex. My problem is I have variables that I want to write from text boxes. And I can not do &H & text1.text!
    And even if i convert them to hex, and do put #1, &H27110, var, it writes it into the file as asc

    Any help is greatly appreciated!

  2. #2
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Using &H with a variable

    You should distingush between Hex notation and Hex string of a number.
    &HAA and 170 are two ways to denote the same decimal number 170.
    We say: The Hex string of 170 is "AA".
    Try this in Immediate window, it will help you to understand:
    Code:
    ? &HAA
     170 
    ? Hex$(&HAA)
    AA
    ? Hex$(170)
    AA
    ? CLng("&H" & "AA")
     170 
    ? Hex$(CLng("&H" & "AA"))
    AA
    ? Hex$("&H" & "AA")
    AA
    If you want to write Hex String of a number to output file with Put, you have to convert the number to Hex String first:

    Code:
    Put #1, Hex$("&H" & Text1.Text)
    Put #1, Hex$(&H27110) ' = "27110"
    Put #1, Hex$(170) ' = "AA"
    Put #1, "&H" & Hex$(170) ' = "&HAA"

  3. #3
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Using &H with a variable

    if you entered "&Hff" in a textbox1.text, this would give you the value:
    msgbox val(textbox1.text)
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

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