Sign in to follow this  
Followers 0
amarcruz

AutoIt is not reliable

11 posts in this topic

Run this code:

#include-once
AutoItSetOption("MustDeclareVars", 1)
Func _DebugOut($s)
    ConsoleWrite($s & @CRLF)
EndFunc

Local $b = Binary("0x2000200A")
_DebugOut("BinaryToInt1: "& BinaryToInt1($b, 20,4))
_DebugOut("BinaryToInt2: "& BinaryToInt($b, 20,4))

Func BinaryToInt1(Const ByRef $byteStr, $start = 1, $size = 4)
   $start -= 1
   Local $ax = StringToASCIIArray(BinaryToString($byteStr,1), $start, $start+$size, 1)
   If Not IsArray($ax) Then
      _DebugOut("***BinaryToInt1 : start="&$start&", end="&($start+$size)&", Type $ax: "& VarGetType($ax))
      Return 0
   EndIf
   Local $ix, $nx = $ax[0]
   For $ix = 1 To UBound($ax)-1
      $nx = BitShift($nx, -8) + $ax[$ix]
   Next
   Return $nx
EndFunc

Func BinaryToInt2(Const ByRef $byteStr, $start = 1, $count = 4)
   Return Number(String(BinaryMid($byteStr, $start, $count)))
EndFunc

In BinaryToInt1(), StringToASCIIArray() with 20,4 should return ""

For these things I left VBScript 5 years ago.

Back to VFP.

Share this post


Link to post
Share on other sites



If you have bug to report then report it. You will get some dev's opinion and resolution. It's simple matter.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Your code doesn't even run properly lol


I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Share this post


Link to post
Share on other sites

Sorry, too much work.

after resting a fewhourseverything looks different, every language has oddities.

and yes, I forgot the "2" of BinaryToInt2() :-(

tnx

Share this post


Link to post
Share on other sites

Then what about negating the title of your post?


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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites

err... right.

AutoIt is great. No dependencies, little learning curve, fast coding, easy GUI programming... and many more.

A very very hard work free for us.

but, the StringToASCIIArray return value is not reliable.

From the specifications in help:

"Return Value

Success: An array where each element is the UNICODE code of the character at the corresponding position.

Failure: Returns an empty string."

In the code above, StringToASCIIArray second parameter (start) is out of bounds, and must fail returning "".

I'm wrong?

Share this post


Link to post
Share on other sites

...continued from previous post.

Should I report this as bug?

...and yes, the title of my post is incorrect, I'm sorry and I appreciate your work.

Thank you again.

(and sorry for my English, my language is Spanish).

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I didn't try to run the broken code. I don't know what you want it to do but I got it doing something.

AutoItSetOption("MustDeclareVars", 1)
Func DebugOut($s) ; Conflict => _DebugOut already exists as a UDF function
    ConsoleWrite($s & @CRLF)
EndFunc

Local $b = Binary("0x2000200A")
DebugOut("BinaryToInt1: "& BinaryToInt1($b, 20,4))
DebugOut("BinaryToInt2: "& BinaryToInt2($b, 20,4))

Func BinaryToInt1(Const ByRef $byteStr, $start = 1, $size = 4)
   $start -= 1
   Local $ax = StringToASCIIArray(BinaryToString($byteStr,1), $start, $start+$size, 1)
   If Not IsArray($ax) Then
      DebugOut("***BinaryToInt1 : start="&$start&", end="&($start+$size)&", Type $ax: "& VarGetType($ax))
      Return 0
   EndIf
   Local $ix, $nx = $ax[0]
   For $ix = 1 To UBound($ax)-1
      $nx = BitShift($nx, -8) + $ax[$ix]
   Next
   Return $nx
EndFunc

Edit

After playing around with this, I see what you are saying. If some of the parameters are out of bounds, it appears that the function reverts to default parameters. Whether this is intentional or not, I don't know.

Edited by czardas

Share this post


Link to post
Share on other sites

No problem with your english, mine is French!

Yes there are a couple of issues with this function. First as you point out it forces the first parameter to 0 (default) when it's out of bounds or greater to the end point.

Then its definition of the end bound is a bit strange (but that's way too late to fix since that would break code) and doesn't work as one would expect. Since this is supposed to be the index of the character before which it should stop, StringToASCIIArray("abc", 1, 1) should bark but it behaves as it was (correctly) invoked as StringToASCIIArray("abc", 1, 2)

File a bug report but please only use something like

#include <Array.au3>

Local $a = StringToASCIIArray("012345", 1, 1)

_ArrayDisplay($a)

to describe it!


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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites

I will. Thank you.

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  
Followers 0