2o2 Posted December 24, 2007 Posted December 24, 2007 Heres my almost perfect script. It almost works. how would i get it to work with more than like 10 characters and when you press enter, and why does "b" turn out as "`"?? Help Plz expandcollapse popup#include <GUIConstants.au3> #include <string.au3> guicreate("Binary Converter", 300, 300) $menu = guictrlcreatemenu("Menu") $open = guictrlcreatemenuitem("Open", $menu) $save = guictrlcreatemenuitem("Save", $menu) $copy = guictrlcreatemenuitem("Copy", $menu) $paste = Guictrlcreatemenuitem("Paste", $menu) $exit = Guictrlcreatemenuitem("Exit", $menu) $about = Guictrlcreatemenuitem("About", $menu) $display = Guictrlcreateedit("", 5, 60, 290, 215) $tobinary = Guictrlcreatebutton("Convert to Binary", 5, 5, 145, 50) $tostring = Guictrlcreatebutton("Convert to String", 150, 5, 145, 50) guisetstate(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case ($msg = -3) Exit Case ($msg = $copy) $readata = guictrlread($display) clipput($readata) Case ($msg = $paste) $put = clipget() guictrlsetdata($display, $put) Case ($msg = $exit) Exit Case ($msg = $about) msgbox(0, "About", "") Case ($msg = $open) $openfile = fileopendialog("Open", @desktopdir, "All Files (*.*)") $openfileread = fileopen($openfile, 0) $data2 = fileread($openfileread) guictrlsetdata($display, $data2) Case ($msg = $save) $readdata = guictrlread($display) $savedialog = filesavedialog("Save", @desktopdir, "Text Files (*.txt)") filewrite($savedialog, $readdata) Case ($msg = $tobinary) $input = guictrlread($display) $input = _StringToHex($input) $hexvalue = StringSplit($input,'') $Result = '' $bits = "0000|1001|0010|0011|0100|0101|0110|0111|1000|1001|10410|1011|1100|1101|1110|1111" $bits = stringsplit($bits,'|') for $n = 1 to $hexvalue[0] $result &= $bits[Dec($hexvalue[$n])+1] Next Guictrlsetdata($display, $result) ;$data = guictrlread($display) ;$char = string($data) ;$bin = stringtobinary($char) ;Guictrlsetdata($display, $bin) Case ($msg = $tostring) $binaryvalue = guictrlread($display) Local $test, $Result = '',$numbytes,$nb if $BinaryValue = '' Then SetError(-2) Return endif Local $bits = "0010|1001|0010|0011|0100|0101|0110|0111|1000|1001|1010|1011|1100|1101|1110|1111" $bits = stringsplit($bits,'|') #region check string is binary $test = stringreplace($BinaryValue,'1','') $test = stringreplace($test,'0','') if $test <> '' Then guictrlsetdata($display, "This is not a valid binary number") endif #endregion check string is binary #region make binary string an integral multiple of 4 characters While 1 $nb = Mod(StringLen($BinaryValue),4) if $nb = 0 then exitloop $BinaryValue = '0' & $BinaryValue WEnd #endregion make binary string an integral multiple of 4 characters $numbytes = Int(StringLen($BinaryValue)/4);the number of bytes Dim $bytes[$numbytes],$Deci[$numbytes] For $j = 0 to $numbytes - 1;for each byte ;extract the next byte $bytes[$j] = StringMid($BinaryValue,1+4*$j,4) ;find what the dec value of the byte is for $k = 0 to 15;for all the 16 possible hex values if $bytes[$j] = $bits[$k+1] Then $Deci[$j] = $k ExitLoop EndIf next Next ;now we have the decimal value for each byte, so stitch the string together again $Result = '' for $l = 0 to $numbytes - 1 $Result &= Hex($Deci[$l],1) Next $result1 = _HexToString($result) guictrlsetdata($display, $result1) ;$data1 = guictrlread($display) ;$bin1 = binary($data1) ;$string = binarytostring($data1) ;GUICtrlSetData($display, $string) EndSelect WEnd Rick rack ree, kick 'em in the knee.Rick rack rass, kick 'em in the other knee!
Paulie Posted December 24, 2007 Posted December 24, 2007 (edited) You have a few more problems than that. I Typed in the word "Hi" Pressed Convert to Binary, got "0110100001101001" I then pressed Convert to string, and got "Ha" And Line 65 has a return statement when its not in a function . EDIT: Upon further experimentation, All instances of the following letters result in errors b = ` i = a j = -1 r=p y=q z=-1 Edited December 24, 2007 by Paulie
Fossil Rock Posted December 24, 2007 Posted December 24, 2007 How many more threads are you going to start devoted to this one subject? Agreement is not necessary - thinking for one's self is!
martin Posted December 24, 2007 Posted December 24, 2007 You have a few more problems than that.I Typed in the word "Hi"Pressed Convert to Binary, got "0110100001101001"I then pressed Convert to string, and got "Ha"And Line 65 has a return statement when its not in a function .@202As Paulie says, you have a few more problems than that.Really you should not be posting the same thing in more than one thread. I answered the same question in example scripts. You have at least three threads that I have seen on this topic. Even worse, I posted a complete answer a long time before this thread was started. Maybe even worse again, the examples I gave in an earlier post were only half copied leading to the problems above. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now