Odd script error
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
- Location: London, UK
Odd script error
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
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 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
-
- Livecode Staff Member
- Posts: 818
- Joined: Fri Feb 06, 2015 4:03 pm
Re: Odd script error
Hi Mark,
In this code you have "mouse_up" instead of "mouseUp".
Best,
Panos
--
In this code you have "mouse_up" instead of "mouseUp".
Best,
Panos
--
Re: Odd script error
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.
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
- Location: London, UK
Re: Odd script error
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
Mickey, I'll post a screenshot when I'm at the right machine.
M
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
- Location: London, UK
Re: Odd script error
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:
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)...
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
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
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
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 181 times
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
Re: Odd script error
Use the date library: https://github.com/derbrill/libdate
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: Odd script error
Already in my talk...