Page 3 of 4
Re: Something is not right with Livecode Strings
Posted: Wed Aug 05, 2020 2:48 am
by karmacomposer
Maybe it has to do with the encryption/decryption process.
Even though if you 'put' the decrypted variable - it shows up properly in the message box,
I cannot seem to use it as a normal string variable though.
When I encrypt, I encode it with UTF-8 and the reverse when I decrypt it. I wonder if that has
to do with it???
With a normal string variable, this code works fine:
Code: Select all
if myVariable = "Puppy" then
answer "I love puppies!" with "OK"
end if
But with my decrypted variable myVariable, I would never see the answer box with loving puppies!!!
I wonder why?
Mike
Re: [SOLVED] Something is not right with Livecode Strings
Posted: Wed Aug 05, 2020 4:31 am
by karmacomposer
Wow. What a cluster.
So, FourthWorld saved my butt!!
He told me to call him, so I did. He discovered that I am a bit hyper active and tried very hard to extract information from me.
Thankfully, he has a lot of patience.
So, eventually, after a lot of advice, we discovered that there were null characters all over the place in the data.
My guess is the client who gave me the data gave me crap ''infected'' data - infected with null characters.
As a quick, temporary fix, FourthWorld advised the following line:
Code: Select all
replace null with empty in varVariable --!
I use the replace function quite a bit, but I never realized you could remove null or hidden characters with it.
So, I did so and it worked PERFECTLY!
Thank you FourthWorld. You are a champion among men.
Mike
Re: [SOLVED] Something is not right with my data
Posted: Wed Aug 05, 2020 5:16 am
by FourthWorld
Happy to help. The problem came in during a fortuitous moment; it's easy to take a moment for phone diagnostics while stirring dinner.
More specifically, the problem was encoding: What appeared to be a month name like "November" turned out to be "N<null>o<null>v<null>e<null>m<null>..." - clearly unconverted UTF-16.
The best solution would be to handle consistency at the source, second best to use textDecode on import. But in a rush to get his demo and my dinner completed, a simple replace kludge was sufficient for now (with a flag, of course, to go back and handle that with textDecode for production later).
Re: Something is not right with Livecode Strings
Posted: Wed Aug 05, 2020 6:42 am
by rkriesel
karmacomposer wrote: Wed Aug 05, 2020 2:15 am
In a moment of clarity, I wrote the following code in a new project with nothing loaded:
...
It works 100%.
...
Hi, karmacomposer.
Now that your code works, you might like to simplify it, as a way to learn simpler techniques, and accelerate future coding. Here's a suggestion:
Code: Select all
function testMonthsAndCounts
local tCounts
repeat 100
add 1 to tCounts[ random(12) ]
end repeat
repeat with i = 1 to 12
get it & line i of the monthNames, tCounts[ i ] & cr
end repeat
return it
end testMonthsAndCounts
-- Dick
Re: [SOLVED] Something is not right with my data
Posted: Wed Aug 05, 2020 4:37 pm
by Lagi Pittas
Hi,
I have learn't a few things the hard way over the years.
1. If your program doesn't make sense it's your DATA.
2. Try switching it on and off again.
3. It Work better when you plug it in.
4. Murphy's law - "If it can go wrong it will"
5. "If it ain't broke don't fix it."
6. No Programs are fool proof because fools are so ingenious.
1. Has ALWAYS been my biggest time saver when any bug takes longer than a couple of hours to find.
2. When somebody asks why something that has been working for years suddenly plays up.
Corollary to 4: Murphy was an optimist.
Corollary to 5: If it ain't broke - fix it until it is.
Corollary to 6:
“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to
produce bigger and better idiots. So far, the Universe is winning.”
― Rick Cook, The Wizardry Compiled
Lagi
Re: [SOLVED] Something is not right with my data
Posted: Wed Aug 05, 2020 5:42 pm
by jacque
get it & line i of the monthNames, tCounts[ i ] & cr
@dick, should the "it" in that line be an "i"?
Re: [SOLVED] Something is not right with my data
Posted: Wed Aug 05, 2020 7:06 pm
by rkriesel
jacque wrote: Wed Aug 05, 2020 5:42 pm
get it & line i of the monthNames, tCounts[ i ] & cr
@dick, should the "it" in that line be an "i"?
Hi, Jacque. "it" works here, containing all the lines "it" contained before the statement, and the statement appends another line. The syntax is a compact equivalent of "put <line> & cr after <lines>" using "it" to contain the lines.
Thanks for asking, Jacque. Does my answer satisfy your question?
-- Dick
Re: [SOLVED] Something is not right with my data
Posted: Wed Aug 05, 2020 7:31 pm
by bobcole
I used LC's functions "the monthNames" and "split" to create an array which was then initialized to zero.
After processing a sample of data in a "switch" structure, the array is converted to a text form and stuffed into a results field.
If someone can figure out how to use the "combine" function here, it might make the script even simpler.
FYI,
Bob
Re: [SOLVED] Something is not right with my data
Posted: Wed Aug 05, 2020 7:43 pm
by jacque
rkriesel wrote: Wed Aug 05, 2020 7:06 pm
jacque wrote: Wed Aug 05, 2020 5:42 pm
get it & line i of the monthNames, tCounts[ i ] & cr
@dick, should the "it" in that line be an "i"?
Hi, Jacque. "it" works here, containing all the lines "it" contained before the statement, and the statement appends another line. The syntax is a compact equivalent of "put <line> & cr after <lines>" using "it" to contain the lines.
Thanks for asking, Jacque. Does my answer satisfy your question?
-- Dick
Yes, thanks, I see now. I wasn't thinking ahead far enough.
Re: [SOLVED] Something is not right with my data
Posted: Thu Aug 06, 2020 4:38 am
by Thierry
bobcole wrote: Wed Aug 05, 2020 7:31 pm
If someone can figure out how to use the "combine" function here, it might make the script even simpler.
CountsByMonth.livecode.zip
Hi Bob,
Here is a replacement for the 55 lines of CountsByMonth,
using
combine with some adjustements and simplification:
Code: Select all
put the monthNames into tMonthsArray
replace CR with (TAB & CR) in tMonthsArray
split tMonthsArray by CR and TAB
repeat for each item aMonth in field "Month Data"
add 1 to tMonthsArray[ aMonth]
end repeat
combine tMonthsArray using CR and TAB
put tMonthsArray into field "Monthly Counts"
Kind regards,
Thierry
Re: [SOLVED] Something is not right with my data
Posted: Thu Aug 06, 2020 4:04 pm
by bobcole
Thierry:
Brilliant script. Quite elegant!
Here is a replacement for the 55 lines of CountsByMonth,
using combine with some adjustements and simplification:
Eight instead of 55 lines. Beautiful.
Thanks,
Bob
Re: [SOLVED] Something is not right with my data
Posted: Thu Aug 06, 2020 8:16 pm
by kdjanz
That really is so clear and elegant that even a beginner can understand it clearly.
Love it!
Kudos!
Re: [SOLVED] Something is not right with my data
Posted: Thu Aug 06, 2020 9:38 pm
by karmacomposer
It's important to note that none of this would have been necessary and all commands would have worked fine (as well as the coding logic) if it wasn't for the fact that the source data was encoded base-16 and messing up everything. Once that was recognized and addressed (erasing all nulls), everything worked perfectly.
Mike
Re: [SOLVED] Something is not right with my data
Posted: Thu Aug 06, 2020 10:34 pm
by FourthWorld
karmacomposer wrote: Thu Aug 06, 2020 9:38 pm
It's important to note that none of this would have been necessary and all commands would have worked fine (as well as the coding logic) if it wasn't for the fact that the source data was encoded base-16 and messing up everything. Once that was recognized and addressed (erasing all nulls), everything worked perfectly.
We could call this Lagi's First Law of Programming Sanity (from his earlier
post above):
1. If your program doesn't make sense it's your DATA.
Sage advice.
Re: [SOLVED] Something is not right with my data
Posted: Fri Aug 07, 2020 7:26 am
by Thierry
kdjanz wrote: Thu Aug 06, 2020 8:16 pm
That really is so clear and elegant that even a beginner can understand it clearly.
Love it!
Kudos!
Thanks Bob and Kellly.
@Kelly: TBH, I wasn't expecting a beginner to appreciate those lines of code.
So, I guess you are not really a beginner

One nice things about this code, is that text fields are well named,
so kudos back to Bob.
@Bob: actually, the original code is less than 55,
as it has some comment lines in it.
( I did take this number from the Project Browser)
Regards,
Thierry