Jump to content

Hex Addition


Queener
 Share

Recommended Posts

scratching my head since the past week of trying to get this to work...

Goal is :

Hex Addition:
$hex_test = 0x012C + (textbox1)
 
Here's what I tried so far and none of them works for me:
$hex_test = 0x12C + "0x" & guictrlread($input1)
(or)
$hex_test = 0x12C + 0X & guictrlread($input1)
(or)
 
$string = dec($input1)
$hex_test = 0x12C + hex($string, 8)

With the textbox, I don't wanted to have to type 0x in front... Any help is great appreciated.

 

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

$hex_test = Hex(0x12C + guictrlread($input1))

Hexadecimal isn't a magical thing, it's just a number in another base, treat it like a normal number.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I tried, but it gives me a wrong answer... Testing 12C + 1 where 1 is typed on the textbox and I get 27BC with the example:

 

$hex_test = 0x12C + ("0x" & guictrlread($input1) )

 

 

Below example gives me 000000

 

$hex_test = Hex(0x12C + guictrlread($input1))

 

 

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

Can you confirm that the following example provides the expected result  ?

#Include <GUIConstantsEx.au3>

$gui = GUICreate("gui")
$input1 = GUICtrlCreateInput("", 10, 10, 100)
$button = GUICtrlCreateButton("ok", 10, 50, 100)

GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $button Then
        $hex_test = 0x12C + ("0x" & guictrlread($input1) )
        MsgBox(0, "result", $hex_test, 0, $gui)
    EndIf
WEnd

 

Link to comment
Share on other sites

Yes, your works... But can you explain why would this make a differences?

 

$input1 = InputBox("test", "Number", "", "")

$hex_test = 0x12C + ("0x" & guictrlread($input1) )

MsgBox(0, "", $hex_test, 0)

 

 

Edited by Queener

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

This, adding the 0x before the number,  is not needed to do the addition. You get the exact same result without it.

("0x" & guictrlread($input1) )

I'm not sure why my example didn't work right, but the Hex function is screwing up the output for some reason I can't explain. The return is correct, but when converted to Hex using the function it gets set to something completely different. 

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

This, adding the 0x before the number,  is not needed to do the addition. You get the exact same result without it.

I'm not sure about what you mean...

0x12c + GUICtrlRead($input) can only work if the input contains numbers. If the input contains an hexadecimal number, the addition will fail and return x012c. Adding 0x before applies the hexadecimal format and the addition will work

$val = "a"
ConsoleWrite(0x12C + $val & @CRLF) ; 0x12c + a
ConsoleWrite(0x12C + ("0x" & $val) & @CRLF) ; 0x12c + "0xa"

 

Link to comment
Share on other sites

I'm not sure about what you mean...

0x12c + GUICtrlRead($input) can only work if the input contains numbers. If the input contains an hexadecimal number, the addition will fail and return x012c. Adding 0x before applies the hexadecimal format and the addition will work

$val = "a"
ConsoleWrite(0x12C + $val & @CRLF) ; 0x12c + a
ConsoleWrite(0x12C + ("0x" & $val) & @CRLF) ; 0x12c + "0xa"

 

"a" is not a hexadecimal number, it's a letter, if you wanted to input a hex number use hex notation. "0xa" would be a hex number.

It is impossible to make anything foolproof because fools are so ingenious.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...