Tsukihime Posted May 27, 2011 Share Posted May 27, 2011 (edited) I am unsure what the issue is with this problem. I have a script that writes out bytes to a file. $outFile = FileOpen("test", 18) For $i = 120 to 140 FileWrite($outFile, chr($i)) Next Very simple test. Opening it in a hex editor, I get 78 79 7A 7B 7C 7D 7E 7F 80 81 82 83 84 85 86 87 88 89 8A 8B 8C as expected from my interval. However, I ran this on another computer and to my surprise, this was the result: 78 79 7A 7B 7C 7D 7E 7F 80 81 81 81 81 81 81 81 81 81 81 81 81 I don't understand why it keeps repeating 81. Or...why chr returns 81 when the number is too large. The first one was run on winXP 32-bit, second on win7 64-bit. I don't know if that makes a difference in how I write the code. Edited May 27, 2011 by Tsukihime Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 27, 2011 Share Posted May 27, 2011 Did you compile for x64 before running it on Win7 x64? Add this when you compile for that environment: #AutoIt3Wrapper_UseX64=Y Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Tsukihime Posted May 28, 2011 Author Share Posted May 28, 2011 (edited) Hmm I added that to the top and compiled the script and ran it, but it's still giving 81. Anyways I just tried compiling the script on another 32-bit vista laptop and it seems to be giving me 81 as well, so my analysis of the problem was probably wrong. Which is strange, cause it's the same script that worked on XP 32-bit. Edited May 28, 2011 by Tsukihime Link to comment Share on other sites More sharing options...
Malkey Posted May 28, 2011 Share Posted May 28, 2011 (edited) It appears the computer that returns Chr(130) to Chr(140) as the same character, has a default font that has the Chr(130) to Chr(140) characters the same. Look at the file as a text file and you should see the same ASCII character that is appearing as Chr(0x81). Edit: Disregard this answer. It is wrong. Even if the ASCII characters look the same their numeric values would be different. Edited May 28, 2011 by Malkey Link to comment Share on other sites More sharing options...
Developers Jos Posted May 28, 2011 Developers Share Posted May 28, 2011 Hmm I added that to the top and compiled the script and ran it, but it's still giving 81.Anyways I just tried compiling the script on another 32-bit vista laptop and it seems to be giving me 81 as well, so my analysis of the problem was probably wrong.Which is strange, cause it's the same script that worked on XP 32-bit.Did you install the full SciTE4AutoIt3 installer else that directive won't do much. SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
jchd Posted May 28, 2011 Share Posted May 28, 2011 FYI your script works as expected (same as on XP x86 SP3) on my Vista x86. BTW, how do you look at the file in hex? PsPad for instance can open a text file for edit but also has a Hex editor option. Is it possible that the tool you use to view it as hex doesn't work correctly? Just double check using another tool. Binary mode used for creating/writing the file will no doubt allow you to write any sequence of bytes on any OS. What I question is that some editors might transpose your file and only let you see an abridged hex view of it. Possible if you only use a hex view of a text editor which may choke at characters > 0x7F and even try to transcode them into more weirdness if you use a codepage with multi-byte representation (like many asian codepages). You can also simply check the hash of the output: test 28C6D232763D1D0A7267BFCCFDABF139 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Tsukihime Posted May 29, 2011 Author Share Posted May 29, 2011 (edited) Did you install the full SciTE4AutoIt3 installer else that directive won't do much.I only installed whatever was here http://www.autoitscript.com/site/autoit/downloads/I assumed it was enough.FYI your script works as expected (same as on XP x86 SP3) on my Vista x86.BTW, how do you look at the file in hex?I am using 010 editor and use the same procedure to view the "original" files that I am trying to write out myself. And it works for the originals.The only reason I"m using a hex editor to verify my results is because I write strings and read strings as well.When I wrote out the file and tried reading it, some letters were all wrong because it's printing 81 for anything after chr(130).This is odd. Edited May 29, 2011 by Tsukihime Link to comment Share on other sites More sharing options...
jchd Posted May 29, 2011 Share Posted May 29, 2011 Can you try this and post the result: $hFile = FileOpen("test", 18) For $i = 120 to 140 FileWrite($hFile, chr($i)) Next FileClose($hFile) $hFile = FileOpen("test", 16) $data = FileRead($hFile) FileClose($hFile) MsgBox(0, "Chr() write/read test", $data) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Tsukihime Posted May 29, 2011 Author Share Posted May 29, 2011 (edited) Instead of 81's, I get 3F 78 79 7A ... 80 3F 3F 3F 3F (without the spaces) Edited May 29, 2011 by Tsukihime Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 29, 2011 Share Posted May 29, 2011 (edited) I only installed whatever was here http://www.autoitscript.com/site/autoit/downloads/I assumed it was enough.And that means what? SciTE4AutoIt3 is linked from there (AutoIt Script Editor) so did you install it? You will find your experience with AutoIt highly improved with the tools therein (like AutoIt3Wrapper). Edited May 29, 2011 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
jchd Posted May 29, 2011 Share Posted May 29, 2011 Uh! That looks just like the binary mode isn't enforced and these chars are converted to their display representation '?' behind the scene. Which codepage or rather system locale are you using on XP, Vista and Seven? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Tsukihime Posted May 29, 2011 Author Share Posted May 29, 2011 (edited) And that means what? SciTE4AutoIt3 is linked from there (AutoIt Script Editor) so did you install it? You will find your experience with AutoIt highly improved with the tools therein (like AutoIt3Wrapper).I didn't specifically install the editor. It just came with the package.Uh! That looks just like the binary mode isn't enforced and these chars are converted to their display representation '?' behind the scene.Which codepage or rather system locale are you using on XP, Vista and Seven?Vista/Seven are in japanese localeXP was using english.I will try switching to english locale to see if it does anything.EDIT: after switching to english, it printed what is expected.PS: I was mistaken, it was not japanese this time, it was in chinese. But both did not work. Edited May 29, 2011 by Tsukihime Link to comment Share on other sites More sharing options...
ProgAndy Posted May 29, 2011 Share Posted May 29, 2011 What is the output if you run this? $hFile = FileOpen("test", 18) For $i = 120 to 140 FileWrite($hFile, StringToBinary(chr($i))) Next FileClose($hFile) $hFile = FileOpen("test", 16) $data = FileRead($hFile) FileClose($hFile) MsgBox(0, "Chr() write/read test", $data) At least the following should work even if there is a bug with the string to binary conversion: $hFile = FileOpen("test", 18) $s = "0x" For $i = 120 to 140 $s &= Hex($i, 2) Next FileWrite($hFile, Binary($s)) FileClose($hFile) *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
jchd Posted May 29, 2011 Share Posted May 29, 2011 OK, so ther is actually no bug there.Look, japanese and chinese (and most asian charsets) use what's called a double-byte representation.Chr() returns a character, but 0x82 and up alone are not valid Big5 (japanese/chinese/korean, ...) character codes by themselves. That's why they get interpreted as ? (0x3f) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Tsukihime Posted May 29, 2011 Author Share Posted May 29, 2011 Is there a way to force which charset it will use? Since users that will be using the small tool will probably have all sorts of locales. Link to comment Share on other sites More sharing options...
jchd Posted May 29, 2011 Share Posted May 29, 2011 (edited) Don't change the locale setting!Simply use what ProgAndy offered: StringToBinary(chr($i)) instead of Chr($i) Edit: what I wrote above was of course complete nonsense. The crux of the problem is, as I myself explained earlier, that 0x82 is simply not a valid character code in Big5, CJK and other asian double-byte codepages. Chr(0x82) means return the character whose code is 0x82, and in the case at hand, there is no such thing. Thus the library returns a question mark, meaning invalid char.The Hex version by ProgAndy work fine as the OP noted. Edited May 30, 2011 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Tsukihime Posted May 29, 2011 Author Share Posted May 29, 2011 (edited) The hex alternative worked =D Edited May 29, 2011 by Tsukihime Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 30, 2011 Share Posted May 30, 2011 I didn't specifically install the editor. It just came with the package.Either you just called the website "the package" or you refuses to uderstand what SciTE4AutoIt3 is. Both choices are strange. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
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