Odd script error

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 483
Joined: Thu Nov 13, 2008 6:48 am
Location: Winnipeg, Manitoba

Odd script error

Post by marksmithhfx » Mon May 14, 2018 3:21 am

Well, odd in my book. Would appreciate your wisdom on this.

A have a field on a form called "date" and it is populated by a global var called date_selected. So, when the form is opened the global var is copied into the "date" field. It (the global var) is also used to drive a few other things, including populating a data grid with the results of an sql query based on the date.

All works well and has done so for eons. Now, I thought I would add two button on this form with arrows going left and right to increment or decrement the date

So I started testing with some code for a left arrow (subtract a day) as follows

global date_selected, gConnectID

on mouse_up
put date_selected into it -- this is the global var
convert it to dateItems
subtract 1 from item 3 of it
convert it to long date
put it into date_selected -- put the decremented date back into the global var
put date_selected into fld "date" -- make it visible in the "date" field
go first card of stack "today" -- try and reopen this card
end mouse_up

Now this code will run all day without hiccup if I run it manually in the code window (and I've stepped through the code and it performs all the steps correctly). But... if I close the window and select the button on the form, nothing happens. The date never decrements.

If these clues are not enough to suggest what's going on I'll try creating a simple stack to demonstrate the problem and post it.

Thanks for you help
Mark
macOS 10.13.6 High Sierra, Xcode 9.4, LC 9.0.1, iOS 11.4.1
Targets: Mac, iOS

LiveCode_Panos
Livecode Staff Member
Livecode Staff Member
Posts: 487
Joined: Fri Feb 06, 2015 4:03 pm

Re: Odd script error

Post by LiveCode_Panos » Mon May 14, 2018 11:52 am

Hi Mark,

In this code you have "mouse_up" instead of "mouseUp".

Best,
Panos
--

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 631
Joined: Fri Jun 27, 2008 9:00 pm

Re: Odd script error

Post by Mikey » Mon May 14, 2018 2:52 pm

So wotcha doin with dates? I've got a session for beginners this week at LCG on dates, and this looks like something similar to something I was going to show them.

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 483
Joined: Thu Nov 13, 2008 6:48 am
Location: Winnipeg, Manitoba

Re: Odd script error

Post by marksmithhfx » Tue May 15, 2018 12:48 am

Hey Panos, one thing I totally miss in the new IDE is the fact that it does not write that opening and closing mouseUp handler for you. My memory sucks :( but thanks for pointing out the error of my ways :)

Mickey, I'll post a screenshot when I'm at the right machine.

M
macOS 10.13.6 High Sierra, Xcode 9.4, LC 9.0.1, iOS 11.4.1
Targets: Mac, iOS

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 483
Joined: Thu Nov 13, 2008 6:48 am
Location: Winnipeg, Manitoba

Re: Odd script error

Post by marksmithhfx » Tue May 15, 2018 2:09 am

Hi Mikey, as in the screen shot below the page that pops up is driven by a calendar -- code courtesy of Sarah Reichelt of TROZ Software. I won't profess to knowing what goes on in the calendar, I just pick up the date from dialogdata when a button is pressed. The code from Sarah's program is:

Code: Select all

on mouseUp
        -- gather the date into the English format
  put word 1 of fld "Month Year" into theMonth
  put lineOffset(theMonth, the system monthNames) into monthNum
  set the dialogData to monthNum & "/" & the label of me & "/" & word 2 of fld "Month Year"
  nextstep
end mouseUp
Once there I open my form and do the following on Sarah's dialogdata to format the date you see:

Oh wow, okay, looks like I am doing all kinds of stuff I probably don't need to be doing. I'll put it on the list to cleanup the code. The code for this particular function is spread out all over the place... buttons, card scripts, stack scripts, and looks like I built it hodgepodge when I didn't really understand what I was doing :) But it works. So since it's stable I'll just leave it for now. Suffice to say, AT SOME POINT, a field called "date" which you can see at the top of the screen displays the date. I just wanted a way to cycle back and forth through the dates, from this card, to see who else was in the database. I've got the left arrow working pretty well with this code (works just fine actually)...

Code: Select all

global date_selected, gConnectID

on mouseUp
   -- code for left arrow
   put date_selected into it
   convert it to dateItems
   subtract 1 from item 3 of it
   convert it to long date
   put it into date_selected
   put date_selected into fld "date"
   go first card of stack "today"
   put "SELECT eventid,mothers_name,fsum,site,delivery_date,mothers_phin FROM master where delivery_date =" & quote & date_selected & quote into tQuery
   put revDataFromQuery(,,gConnectID,tQuery) into tRecords
   
   # this part's not required, but a good idea to check for errors
   if tRecords begins with "revdberr" then 
      answer error "There was a problem accessing the Master database: " & tRecords as sheet
      exit mouseUp
   end if
   # end error check   
   set the dgText of group "moms" on this card to tRecords
end mouseUp
I'll pop the arrow on the right side and have it increment by 1 and I'll be done. A lot of this is legacy code I'm playing with that i've written over 6 years while learning (or think I'm learning :) livecode.

BTW, I plan to attend your session if I can - might run during my work hours in which case I'll watch it Thurs evening. Good luck.

Mark
Attachments
Screen Shot 2018-05-14 at 7.34.31 PM.zip
I had to zip it to get it up here. Shows screen layout calendar/dates etc
(212.69 KiB) Downloaded 10 times
macOS 10.13.6 High Sierra, Xcode 9.4, LC 9.0.1, iOS 11.4.1
Targets: Mac, iOS

MaxV
Posts: 1539
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Odd script error

Post by MaxV » Wed May 16, 2018 4:23 pm

Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 631
Joined: Fri Jun 27, 2008 9:00 pm

Re: Odd script error

Post by Mikey » Wed May 16, 2018 4:56 pm

Already in my talk...

Post Reply

Return to “Talking LiveCode”