[SOLVED] Something is not right with my data

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

karmacomposer
Posts: 355
Joined: Wed Apr 27, 2011 2:12 pm

Re: Something is not right with Livecode Strings

Post by karmacomposer » Wed Aug 05, 2020 2:48 am

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
Last edited by karmacomposer on Wed Aug 05, 2020 4:34 am, edited 1 time in total.

karmacomposer
Posts: 355
Joined: Wed Apr 27, 2011 2:12 pm

Re: [SOLVED] Something is not right with Livecode Strings

Post by karmacomposer » Wed Aug 05, 2020 4:31 am

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8322
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: [SOLVED] Something is not right with my data

Post by FourthWorld » Wed Aug 05, 2020 5:16 am

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).
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

rkriesel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 89
Joined: Thu Apr 13, 2006 6:25 pm

Re: Something is not right with Livecode Strings

Post by rkriesel » Wed Aug 05, 2020 6:42 am

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

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 349
Joined: Mon Jun 10, 2013 1:32 pm

Re: [SOLVED] Something is not right with my data

Post by Lagi Pittas » Wed Aug 05, 2020 4:37 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5792
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: [SOLVED] Something is not right with my data

Post by jacque » 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"?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

rkriesel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 89
Joined: Thu Apr 13, 2006 6:25 pm

Re: [SOLVED] Something is not right with my data

Post by rkriesel » 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

bobcole
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 16
Joined: Tue Feb 23, 2010 10:53 pm

Re: [SOLVED] Something is not right with my data

Post by bobcole » Wed Aug 05, 2020 7:31 pm

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
CountsByMonth.livecode.zip
(1.65 KiB) Downloaded 43 times

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5792
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: [SOLVED] Something is not right with my data

Post by jacque » Wed Aug 05, 2020 7:43 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 795
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: [SOLVED] Something is not right with my data

Post by Thierry » Thu Aug 06, 2020 4:38 am

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
Regex LiveCode sunnYrex
https://sunny-tdz.com

bobcole
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 16
Joined: Tue Feb 23, 2010 10:53 pm

Re: [SOLVED] Something is not right with my data

Post by bobcole » Thu Aug 06, 2020 4:04 pm

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

kdjanz
Posts: 246
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: [SOLVED] Something is not right with my data

Post by kdjanz » 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!

karmacomposer
Posts: 355
Joined: Wed Apr 27, 2011 2:12 pm

Re: [SOLVED] Something is not right with my data

Post by karmacomposer » 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.

Mike

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8322
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: [SOLVED] Something is not right with my data

Post by FourthWorld » Thu Aug 06, 2020 10:34 pm

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.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 795
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: [SOLVED] Something is not right with my data

Post by Thierry » Fri Aug 07, 2020 7:26 am

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
Regex LiveCode sunnYrex
https://sunny-tdz.com

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”