Jump to content
Sign in to follow this  

Input control doesn't show data after one try

Recommended Posts


I made a reversed hexadecimal to integer converter. The problem is that the radio button for Reversed Hex to Int converts the data once and it won't convert new data. I made a temporary fix by adding a restart function but it can get annoying if we were to do that every time we want to convert. I've even tried to "clean out" a variable by setting $revH2int = "" but it only messes up the calculations.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <String.au3>
#include <Misc.au3>
$Form1_1 = GUICreate("Hex Converter", 380, 221, 356, 240, -1, 0)
$Tab1 = GUICtrlCreateTab(1, 2, 377, 217)
$ConvSheet = GUICtrlCreateTabItem("Converter")
$ConTypeGroup = GUICtrlCreateGroup("Convert Types", 5, 27, 305, 73)
$Int2RevH = GUICtrlCreateRadio("Int to Reversed Hex", 189, 51, 113, 14)
$RevH2Int = GUICtrlCreateRadio("Reversed Hex to Int", 189, 75, 113, 14)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$ConvGroup = GUICtrlCreateGroup("Conversion", 8, 104, 353, 105)
$inputLabel = GUICtrlCreateLabel("Your Input", 24, 128, 53, 17)
$userInput = GUICtrlCreateInput("", 88, 128, 257, 21)
$convLabel = GUICtrlCreateLabel("Converted", 24, 160, 53, 17)
$convOutput = GUICtrlCreateInput("", 88, 160, 257, 21)
$lblConvdesc = GUICtrlCreateLabel("Converted data is copied.", 88, 184, 125, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$lblF5 = GUICtrlCreateLabel("F5 - Refresh", 312, 32, 62, 17)
HotKeySet("{F5}", "_SelfRestart") ;Restarts the whole program.
While 1
   ;$convOutput = ""
$nMsg = GUIGetMsg()
Switch $nMsg

Case $Int2RevH

$userInput2 = GUICtrlRead($userInput)
      $hexID = "0x" & hex($userInput2)
    Hex(BitAND($hexID, 0x000000ff), 2) ;Reverses 1st and last
    Hex(BitShift(BitAND($hexID, 0x0000ff00), 8), 2) ;Reverses 2nd
    Hex(BitShift(BitAND($hexID, 0x00ff0000), 16), 2) ;Reverses last and third
    Hex(BitShift($hexID, 24), 2) ;Reverses the 4th hex.
    $revHex = Hex(BitAND($hexID, 0x000000ff), 2) & " " & Hex(BitShift(BitAND($hexID, 0x0000ff00), 8), 2) & " " & _
    Hex(BitShift(BitAND($hexID, 0x00ff0000), 16), 2) & " " & Hex(BitShift($hexID, 24), 2)
      _GUICtrlEdit_SetSel($convOutput, 0, -1) ;Selects all text in the output box.
_GUICtrlEdit_ReplaceSel($convOutput, $revHex)
   ;$revHex = ""
Case $RevH2Int
   ;$revH2int = ""
  $userInput2 = GUICtrlRead($userInput)
      $userInput2Dec = StringStripWS($userInput2,8)
     $strlen = StringLen($userInput2Dec)
   $revH2int = Dec(StringTrimLeft($userInput2Dec,$strlen-2) & _
      StringTrimRight(StringTrimLeft($userInput2Dec,$strlen-4),2) & _
      StringTrimRight(StringTrimLeft($userInput2Dec,$strlen-6),4) & _
          _GUICtrlEdit_SetSel($convOutput, 0, -1) ;Selects all text in the output box.
   _GUICtrlEdit_ReplaceSel($convOutput, $revH2int)
;$revH2int = ""

Func _SelfRestart() ; restart the app
    ;Local $iMsgBoxAnswer = MsgBox(308, "Restarting...", "Are you sure you want to restart?")
    ;If $iMsgBoxAnswer <> 6 Then Return ; Not Yes so return
    If @Compiled Then
        Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath))
EndFunc   ;==>_SelfRestart

Is there any way to fix this?

Thank you in advance.

Share this post

Link to post
Share on other sites

Put a button control on the GUI and use that to execute the conversion functions instead of reading the state of the radio buttons. Because that will only work the first time it's clicked, until the other radio button is clicked. Use the radio buttons to determine which function is run when the new button is clicked.

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

Share this post

Link to post
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
Sign in to follow this