Tuesday, February 25, 2020

#1 2020-01-23 04:49:58 pm

Headroom San
Member
From:: Stratford upon Avon
Registered: 2016-07-15
Posts: 39

trying to use a number with leading zero's and failing...

Dear all,

I have a need to pass a variable number to another app.

I set the variable to look like this
set the mrt to 0012345678
when i save the script, applescript removes the leading zero's and I get
set the mrt to 12345678

if i use
set the mrt to 205312345678
i get
set the mrt to 2.0531234567E+10

I have never seen this behaviour before. Whats going on?

BTW . The other app needs to receive the entire number, with the leading zeros.
I have tried sending the number as text and the receiving program does not recognise it.

Thanks for reading this:(


Beware the beast Man, for he is the Devil's pawn. Alone among God's primates, he kills for sport or lust or greed. Yea, he will murder his brother to possess his brother's land. Let him not breed in great numbers, for he will make a desert of his home and yours. Shun him; drive him back into his jungle lair, for he is the harbinger of death.

Offline

 

#2 2020-01-23 05:43:13 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5168

Re: trying to use a number with leading zero's and failing...

Hi.

Headroom San wrote:

if i use
set the mrt to 205312345678
i get
set the mrt to 2.0531234567E+10


I get 2.05312345678E+11.  smile  What system are you using? 205312345678 is larger than the maximum positive integer that AppleScript can handle, so it's compiled as a real: 205312345678.0. Very large and very small reals are presented on screen in "E" notation, but it makes no difference to the numeric value.

BTW . The other app needs to receive the entire number, with the leading zeros.
I have tried sending the number as text and the receiving program does not recognise it.


A number's just a number value. Leading zeros only appear in text. Maybe your other app's expecting a different text encoding.


NG

Offline

 

#3 2020-01-24 12:26:14 am

Headroom San
Member
From:: Stratford upon Avon
Registered: 2016-07-15
Posts: 39

Re: trying to use a number with leading zero's and failing...

Nigel, thanks for your reply.

The client app is quite dumb and simply generates a barcode. Whatever numeric value it sees it turns into a code. It’s a pure mapping operation the value of the number is ignored. This digit = that combination of bars. It’s a numeric only code so any text causes an error.

It sees a zero and generates a specific set of bars, then then does the same each digit and concatenates all the sets and saves the code as an image. It does no analysis of the number or calc or anything..

The service that will read the code needs a fixed length field and the leading zeros mean something so I have to have them.

Take on board what you said about encoding. If I just type the digits into the barcode app , 005312345678, it will accept them and work. If I type the same digits into text edit , then manually copy and then paste them into the barcode app it works. At the moment it is AS refusal to allow numeric leading zeros is the problem.

I wonder if a JS sub might do it. I will keep trying.

Thanks again,

Max


Beware the beast Man, for he is the Devil's pawn. Alone among God's primates, he kills for sport or lust or greed. Yea, he will murder his brother to possess his brother's land. Let him not breed in great numbers, for he will make a desert of his home and yours. Shun him; drive him back into his jungle lair, for he is the harbinger of death.

Offline

 

#4 2020-01-24 01:58:00 am

Headroom San
Member
From:: Stratford upon Avon
Registered: 2016-07-15
Posts: 39

Re: trying to use a number with leading zero's and failing...

Nigel,

I am trying something truly crude here and telling system events to cut and paste from text edit, because the target app WILL accept the number when copied and pasted from textEdit.

It seems I can use applescript to produce a string of 005312345678 as a string. Then i can paste that into text edit. Then i select it in textEdit and paste it into the target app.

That works, but I will have to do better than that!

It gets me out of the hole today, but i need to improve on that!

Thanks,  Max


Beware the beast Man, for he is the Devil's pawn. Alone among God's primates, he kills for sport or lust or greed. Yea, he will murder his brother to possess his brother's land. Let him not breed in great numbers, for he will make a desert of his home and yours. Shun him; drive him back into his jungle lair, for he is the harbinger of death.

Offline

 

#5 2020-01-24 02:10:30 am

Headroom San
Member
From:: Stratford upon Avon
Registered: 2016-07-15
Posts: 39

Re: trying to use a number with leading zero's and failing...

Nigel, me again.

I had not noticed, but the barcode app supplier last update gves me the option of using an imported .CSV file.

I would think that makes all possible.

Max


Beware the beast Man, for he is the Devil's pawn. Alone among God's primates, he kills for sport or lust or greed. Yea, he will murder his brother to possess his brother's land. Let him not breed in great numbers, for he will make a desert of his home and yours. Shun him; drive him back into his jungle lair, for he is the harbinger of death.

Offline

 

#6 2020-01-24 03:08:06 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5168

Re: trying to use a number with leading zero's and failing...

Yes. Text copied to the clipboard from TextEdit gets stored there in a variety of encodings from which your other app can take its pick. AppleScript uses UTF-16 internally. But even writing AppleScript text directly to the clipboard produces (on my Mojave Systems) versions in 'Unicode text' (UTF-16BE), 'string' (MacRoman), UTF-8 and «class ut16» (which is UTF-16LE on Intel machines):

Applescript:

set the clipboard to "005312345678"
the clipboard as record
--> {Unicode text:"005312345678", string:"005312345678", scrap styles:«data styl01000000000010000E00030000000C00000000000000», «class utf8»:"005312345678", «class ut16»:"005312345678"}

I'd have thought one of these would have suited your other app.  hmm  Copying plain text from TextEdit produces the same result without the scrap styles. Copying RTF text from TextEdit, I get the AppleScript result plus RTF data and 'uniform styles'. How have you been transferring data from the script to the app (apart from apparently passing a real instead of text)?

I believe that CSV files generally have UTF-8 endcoding, although they needn't necessarily do so, so it's potentially the same probem with them.


NG

Offline

 

#7 2020-01-24 06:37:26 am

Headroom San
Member
From:: Stratford upon Avon
Registered: 2016-07-15
Posts: 39

Re: trying to use a number with leading zero's and failing...

Nigel,

I am a bit committed elsewhere so I am behind on this.

but

I can send my numbers as a string of text for each code to the .csv file. As in the script you sent me years back, i can keep appending to the end of the CSV to make my list of code payloads.

The barcode app has two modes of input. A single code at a time dialogue box that I just type into.
In a loop;
I was using AS to paste into this, one code at a time,
then export to file.
I end up with folder full of files.

This morning i discovered that it ALSO has a CSV importer built in. This happily reads a .csv which was constructed by AS. I have already been able to manage the import controls from AS.
So I construct my list via AS and then tell the barcode app to import and then generate the CSV.

Clearly, the barcode app uses a different method of validating an import to that of the single dialog box.

I'll write and error trap my script for this then publish it back ASAP.

Thanks

Max


Beware the beast Man, for he is the Devil's pawn. Alone among God's primates, he kills for sport or lust or greed. Yea, he will murder his brother to possess his brother's land. Let him not breed in great numbers, for he will make a desert of his home and yours. Shun him; drive him back into his jungle lair, for he is the harbinger of death.

Offline

 

#8 2020-01-30 02:23:50 am

CK
Member
From:: UK
Registered: 2018-11-04
Posts: 126

Re: trying to use a number with leading zero's and failing...

Skimming this thread, it sounds like you wish to take a number and obtain a text representation of it, padded with leading zeroes as needed.

I saw "005312345678" in one of your posts, so I've used this as a guide and am assuming you require a 12-digit long result.

to stringFromNumber:(N as number)
        local N
        return N as miles as string
end stringFromNumber:

to addLeadingZeroes to N
        local N

        set twelveZeroes to "000000000000"
        if N's class ≠ text then set N to stringFromNumber_(N)
        if the length of N ≥ 12 then return N

        return text -1 thru -12 of (twelveZeroes & N)
end addLeadingZeroes

With those handlers inserted into a script, hopefully, you can process a number like so:

Applescript:

set the clipboard to (addLeadingZeroes to 5312345678)
return the clipboard

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)