Harsh lessons in binaryDecode

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Harsh lessons in binaryDecode

Alex Tweedly

I was trying to use binaryDecode to get some data out of a string; the
format is simple
 - 4 digit number
 - a space
 - 4 digit number
 - a space
 - 12 digit number

However, the numbers may be completely blank (otherwise I'd just have
used word 1, word 2 and word 3 :-)
So get some sample data ready ...

  put "1234 5678 123456789012 and some more" into lV

Rather than
   put char 1 to 4 of V into tVal1
   put char 6 to 9 of V into tVal2
   put char 11 to 22 of V into tVal3
I decided to have a go at using binaryDecode (thanks to Jim Ault for
suggesting this), because it would be a single statement and potentially
faster (the real case has more variables and decoding to do)
 
  get binaryDecode("a4xa4xa12", lV, tVal1, tVal2, tVal3)

i.e. put 4 chars into the first variable, skip one char, 4 chars into
next var, skip, 12 chars into next var.

I heeded the warning about the fact that the variables must exist, so
added local declarations.

Unfortunately, executing this code makes Rev crash immediately - no
error, no warning, just "Boom" - gone.

It turns out (I think) that although the binaryDecode format of "x" is
described as

> The formatsList consists of one or more dataTypes, each followed
> optionally by an amount. A dataType is one of the following single
> letters:
>
> x: skip next amount bytes of data
> a: convert next amount bytes of data to characters

etc.
"skip" doesn't mean skip - it means skip and use up one variable from
the variable list !!

Therefore, there were too few variables in the variable list. A crash
out of Rev seems a bit harsh even for too few variables, but I can live
with that.

A quick scan in Bugzilla didn't show anything like this. So
 - should  I BZ it ?  (or this the way it's always been and should be
forever :-)
 - BZ the docs ? (i.e. skip doesn't mean skip), since a change would
risk backwards compatibility
 - BZ the crash separately ??


Here's the recipe - switch the commented out lines to see the problem ...

[ in the script of a button ]
local lV
on mouseUp
  put "1234 5678 123456789012 and some more" into lV
  doit
end mouseUp

on doit
  local tVal1, tVal2, tVal3
  local x1, x2
  --  get binaryDecode("a4xa4xa12", lV, tVal1, tVal2, tVal3)
  get binaryDecode("a4xa4xa12", lV, tVal1, x1, tVal2, x2, tVal3)
  put it && tVal1, tVal2, tVal3 & cr after msg
end doit


Moral of the day, for those who've made it this far ...
  I've spent more hours with this problem than I will ever save seconds
in run time from this efficiency :-)

--
Alex Tweedly       http://www.tweedly.net



--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.7.2/349 - Release Date: 26/05/2006

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Harsh lessons in binaryDecode

xtalkprogrammer
Hi Alex,

You are right about the crash, but you don't need additional  
variables to avoid it.

on mouseUp
   local lVal1, lVal2, lVal3
   put "1234 5678 123456789012 and some more" into myBin
   get binaryDecode("a4xa4xa12",myBin, lVal1,,lVal2,,lVal3)
   put it && lVal1, lVal2, lVal3
end mouseUp

This is good to know, if you are decoding large amounts of data.

Best,

Mark

--

Economy-x-Talk
Consultancy and Software Engineering
http://economy-x-talk.com
http://www.salery.biz

Salery is the easiest way to get your own web store on-line: http://
www.salery.biz/salery.html



Op 27-mei-2006, om 14:33 heeft Alex Tweedly het volgende geschreven:

> Here's the recipe - switch the commented out lines to see the  
> problem ...
>
> [ in the script of a button ]
> local lV
> on mouseUp
>  put "1234 5678 123456789012 and some more" into lV
>  doit
> end mouseUp
>
> on doit
>  local tVal1, tVal2, tVal3
>  local x1, x2
>  --  get binaryDecode("a4xa4xa12", lV, tVal1, tVal2, tVal3)
>  get binaryDecode("a4xa4xa12", lV, tVal1, x1, tVal2, x2, tVal3)
>  put it && tVal1, tVal2, tVal3 & cr after msg
> end doit
>
>
> Moral of the day, for those who've made it this far ...
>  I've spent more hours with this problem than I will ever save  
> seconds in run time from this efficiency :-)
>
> --
> Alex Tweedly

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Kind regards,

Drs. Mark Schonewille

Economy-x-Talk Consultancy and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
Facebook: http://facebook.com/LiveCode.Beginner
KvK: 50277553
Reply | Threaded
Open this post in threaded view
|

Re: Harsh lessons in binaryDecode

Jim Lyons-2
In reply to this post by Alex Tweedly
On May 27, 2006, at 8:33 AM, Alex Tweedly wrote:

> I was trying to use binaryDecode to get some data out of a string; the
> format is simple
> - 4 digit number
> - a space
> - 4 digit number
> - a space
> - 12 digit number
> ...
>
> I decided to have a go at using binaryDecode (thanks to Jim Ault for
> suggesting this), because it would be a single statement and
> potentially faster (the real case has more variables and decoding to
> do)
>  get binaryDecode("a4xa4xa12", lV, tVal1, tVal2, tVal3)
>
> i.e. put 4 chars into the first variable, skip one char, 4 chars into
> next var, skip, 12 chars into next var.

Alex,
Sorry about the crash ;^)  but shouldn't that be "a4x1a4x1a12" ? (Note
the ones after the x's)

Jim Lyons

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Harsh lessons in binaryDecode

Alex Tweedly
Jim Lyons wrote:

> On May 27, 2006, at 8:33 AM, Alex Tweedly wrote:
>
>> I decided to have a go at using binaryDecode (thanks to Jim Ault for
>> suggesting this), because it would be a single statement and
>> potentially faster (the real case has more variables and decoding to do)
>>  get binaryDecode("a4xa4xa12", lV, tVal1, tVal2, tVal3)
>>
>> i.e. put 4 chars into the first variable, skip one char, 4 chars into
>> next var, skip, 12 chars into next var.
>
>
> Alex,
> Sorry about the crash ;^)  but shouldn't that be "a4x1a4x1a12" ? (Note
> the ones after the x's)

Nope. The docs say

> Parameters:
> The formatsList consists of one or more dataTypes, each followed
> optionally by an amount. A dataType is one of the following single
> letters:
>
Note - "...followed *optionally* by an amount..."

But thanks for the sympathy :-)

--
Alex Tweedly       http://www.tweedly.net



--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.7.2/349 - Release Date: 26/05/2006

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Harsh lessons in binaryDecode

Jim Lyons-2
I previously wrote and alex replied:

>
>> Alex,
>> Sorry about the crash ;^)  but shouldn't that be "a4x1a4x1a12" ?
>> (Note the ones after the x's)
>
> Nope. The docs say
>
>> Parameters:
>> The formatsList consists of one or more dataTypes, each followed
>> optionally by an amount. A dataType is one of the following single
>> letters:
>>
> Note - "...followed *optionally* by an amount..."
>
> But thanks for the sympathy :-)

Whoops, I picked up on the "optionally" right after I hit Send. I'm
really much better at lurking than helping. :^/

I did verify that in Rev 2.6 and Rev 2.7.1 (Mac OS 10.3.9) that you get
a big time crash if the number of variables is less than the number of
format specs.

Jim Lyons

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Saving information in Revolution.

Alvaro Abril - Tecnologia
Dear Sirs:..

How i use :

On closecard

End closecard

To save information? I cant save information, because in Hypercard, save is
automatic...

How I can?

Best regards, Alvaro

-----Mensaje original-----
De: [hidden email]
[mailto:[hidden email]] En nombre de Jim Lyons
Enviado el: Sábado, 27 de Mayo de 2006 12:01 p.m.
Para: How to use Revolution
Asunto: Re: Harsh lessons in binaryDecode

I previously wrote and alex replied:

>
>> Alex,
>> Sorry about the crash ;^)  but shouldn't that be "a4x1a4x1a12" ?
>> (Note the ones after the x's)
>
> Nope. The docs say
>
>> Parameters:
>> The formatsList consists of one or more dataTypes, each followed
>> optionally by an amount. A dataType is one of the following single
>> letters:
>>
> Note - "...followed *optionally* by an amount..."
>
> But thanks for the sympathy :-)

Whoops, I picked up on the "optionally" right after I hit Send. I'm
really much better at lurking than helping. :^/

I did verify that in Rev 2.6 and Rev 2.7.1 (Mac OS 10.3.9) that you get
a big time crash if the number of variables is less than the number of
format specs.

Jim Lyons

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Saving information in Revolution.

xtalkprogrammer
Hi Alvaro,

on closeCard
   save this stack
end closeCard

or

on closeStackRequest
   save this stack
   pass closeStackRequest
end closeStackRequest

There is also a closeStack handler, but you might want to use the  
closeStackRequest handler because you could decide whether you really  
want to close the stack, in the closeStackRequest handler, which will  
be useful when your project grows more advanced.

Are you sure you want to save the information in the stack? If you  
are going to make standalones, you probably want to save the data in  
a text file or in a stack that is not part of the standalone.

Best regards,

Mark

P.S. It is not necessary to quote messages that have nothing to do  
with the subject.

--

Economy-x-Talk
Consultancy and Software Engineering
http://economy-x-talk.com
http://www.salery.biz

Salery is the easiest way to get your own web store on-line: http://
www.salery.biz/salery.html



Op 28-mei-2006, om 0:53 heeft Alvaro Abril - Tecnologia het volgende  
geschreven:

> Dear Sirs:..
>
> How i use :
>
> On closecard
>
> End closecard
>
> To save information? I cant save information, because in Hypercard,  
> save is
> automatic...
>
> How I can?
>
> Best regards, Alvaro

<snip>

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Kind regards,

Drs. Mark Schonewille

Economy-x-Talk Consultancy and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
Facebook: http://facebook.com/LiveCode.Beginner
KvK: 50277553
Reply | Threaded
Open this post in threaded view
|

RE: Saving information in Revolution.

Alvaro Abril - Tecnologia
Dear Mark.. And where I need to place the handler in the standalone?

on closeStackRequest
   save this stack
   pass closeStackRequest
end closeStackRequest


Thank you, Alvaro Abril

-----Mensaje original-----
De: [hidden email]
[mailto:[hidden email]] En nombre de Mark
Schonewille
Enviado el: Sábado, 27 de Mayo de 2006 04:06 p.m.
Para: How to use Revolution
Asunto: Re: Saving information in Revolution.

Hi Alvaro,

on closeCard
   save this stack
end closeCard

or

on closeStackRequest
   save this stack
   pass closeStackRequest
end closeStackRequest

There is also a closeStack handler, but you might want to use the  
closeStackRequest handler because you could decide whether you really  
want to close the stack, in the closeStackRequest handler, which will  
be useful when your project grows more advanced.

Are you sure you want to save the information in the stack? If you  
are going to make standalones, you probably want to save the data in  
a text file or in a stack that is not part of the standalone.

Best regards,

Mark

P.S. It is not necessary to quote messages that have nothing to do  
with the subject.

--

Economy-x-Talk
Consultancy and Software Engineering
http://economy-x-talk.com
http://www.salery.biz

Salery is the easiest way to get your own web store on-line: http://
www.salery.biz/salery.html



Op 28-mei-2006, om 0:53 heeft Alvaro Abril - Tecnologia het volgende  
geschreven:

> Dear Sirs:..
>
> How i use :
>
> On closecard
>
> End closecard
>
> To save information? I cant save information, because in Hypercard,  
> save is
> automatic...
>
> How I can?
>
> Best regards, Alvaro

<snip>

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

RE: Saving information in Revolution.

Alvaro Abril - Tecnologia
In reply to this post by xtalkprogrammer
Hello.. where I can to put this commands.. I cant save information using
Standalone :)

Alvaro

-----Mensaje original-----
De: [hidden email]
[mailto:[hidden email]] En nombre de Mark
Schonewille
Enviado el: Sábado, 27 de Mayo de 2006 04:06 p.m.
Para: How to use Revolution
Asunto: Re: Saving information in Revolution.

Hi Alvaro,

on closeCard
   save this stack
end closeCard

or

on closeStackRequest
   save this stack
   pass closeStackRequest
end closeStackRequest

There is also a closeStack handler, but you might want to use the  
closeStackRequest handler because you could decide whether you really  
want to close the stack, in the closeStackRequest handler, which will  
be useful when your project grows more advanced.

Are you sure you want to save the information in the stack? If you  
are going to make standalones, you probably want to save the data in  
a text file or in a stack that is not part of the standalone.

Best regards,

Mark

P.S. It is not necessary to quote messages that have nothing to do  
with the subject.

--

Economy-x-Talk
Consultancy and Software Engineering
http://economy-x-talk.com
http://www.salery.biz

Salery is the easiest way to get your own web store on-line: http://
www.salery.biz/salery.html



Op 28-mei-2006, om 0:53 heeft Alvaro Abril - Tecnologia het volgende  
geschreven:

> Dear Sirs:..
>
> How i use :
>
> On closecard
>
> End closecard
>
> To save information? I cant save information, because in Hypercard,  
> save is
> automatic...
>
> How I can?
>
> Best regards, Alvaro

<snip>

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Saving information in Revolution.

xtalkprogrammer
In reply to this post by Alvaro Abril - Tecnologia
Hi Alvaro,

You put the closeStackRequest into the script of the stack that is  
being closed. If this stack is a substack, you might also want to put  
it into the script of the mainstack, depending on what you try to  
achieve. Sometimes, you want to runi the script of a particular card  
is the current card, only. In those cases, you could put the script  
into the card script.

I could imagine that you want to find out more about the message  
hierarchy. If you have books about HyperCard, they will probably  
contain useful information about the message hierarchy. Just ignore  
the info about backgrounds, for now. You also probably want to have a  
look at Richard Gaskin's scripting conference stack about the message  
hierarchy at <http://downloads.runrev.com/section/ 
scriptingconferences.php>. On the same page, you will find a stack by  
Judy Perry, about Groups and Backgrounds, which is also very useful.  
Of course, other stacks on that page could also be very useful for you.

Best

Mark

--

Economy-x-Talk
Consultancy and Software Engineering
http://economy-x-talk.com
http://www.salery.biz

Salery is the easiest way to get your own web store on-line: http://
www.salery.biz/salery.html



Op 28-mei-2006, om 1:13 heeft Alvaro Abril - Tecnologia het volgende  
geschreven:

> Dear Mark.. And where I need to place the handler in the standalone?
>
> on closeStackRequest
>    save this stack
>    pass closeStackRequest
> end closeStackRequest

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Kind regards,

Drs. Mark Schonewille

Economy-x-Talk Consultancy and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
Facebook: http://facebook.com/LiveCode.Beginner
KvK: 50277553
Reply | Threaded
Open this post in threaded view
|

Re: Saving information in Revolution.

xtalkprogrammer
In reply to this post by Alvaro Abril - Tecnologia
Alvaro,

Do you mean you created a standalone but can't save data in it? That  
would be normal, since modifications in standalones cannot be saved.  
Instead, you would write the data in a field to a file, for example  
using syntax like

put fld "My Info" into url "file:~/Desktop/Test File.txt"

Note that the file path will be different if you are on Windows. Next  
time you open the standalone, read the data using the following syntax.

put url file:~/Desktop/Test File.txt" into fld "My Info".

I hope this helps you to get going. Don't forget to read the built-in  
docs.

Best,

Mark

--

Economy-x-Talk
Consultancy and Software Engineering
http://economy-x-talk.com
http://www.salery.biz

Salery is the easiest way to get your own web store on-line: http://
www.salery.biz/salery.html



Op 28-mei-2006, om 2:03 heeft Alvaro Abril - Tecnologia het volgende  
geschreven:

> Hello.. where I can to put this commands.. I cant save information  
> using
> Standalone :)
>
> Alvaro
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Kind regards,

Drs. Mark Schonewille

Economy-x-Talk Consultancy and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
Facebook: http://facebook.com/LiveCode.Beginner
KvK: 50277553
Reply | Threaded
Open this post in threaded view
|

Re: Saving information in Revolution.

Sarah Reichelt-2
In reply to this post by Alvaro Abril - Tecnologia
On 5/28/06, Alvaro Abril - Tecnologia <[hidden email]> wrote:
> Hello.. where I can to put this commands.. I cant save information using
> Standalone :)

You might find this article useful:
<http://www.revjournal.com/tutorials/saving_data_in_revolution.html>

Cheers,
Sarah
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Saving information in Revolution

Judy Perry
In reply to this post by xtalkprogrammer
Mark:

Kindest thanks for your reference!

Alvaro:

You may want to visit a scripting conferences stack by Ken Ray at
http://downloads.runrev.com/section/scriptingconferences.php

See also the "specialFolderPath" function via the Rev docs.

I have a PDF on this as well:
http://jperryl.ecs.fullerton.edu/FileIOHandout.pdf

As Mark says, Hypercard's ability to save itself (that is, be
self-modifying) is not supported in modern executables.  But you can save
settings to a text file on the stack's close and then read them back in
upon a stack (that is, a file's) opening to set custom settings as far as
I understand things.

Everyone else:

Should you still be reading, if you find anything gargantuanly stupid at
http://jperryl.ecs.fullerton.edu/FileIOHandout.pdf , please do let me
know!

@;-)

Judy

On Sun, 28 May 2006, Mark Schonewille wrote:

> Alvaro,
>
> Do you mean you created a standalone but can't save data in it? That
> would be normal, since modifications in standalones cannot be saved.
> Instead, you would write the data in a field to a file, for example
> using syntax like
>
> put fld "My Info" into url "file:~/Desktop/Test File.txt"
>
> Note that the file path will be different if you are on Windows. Next
> time you open the standalone, read the data using the following syntax.
>
> put url file:~/Desktop/Test File.txt" into fld "My Info".
>
> I hope this helps you to get going. Don't forget to read the built-in
> docs.

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution