How do I in Filemaker create a script to find next months month name?

I am running FileMaker 10.
I created a button that when clicked it should search a table with the field called "BdayMonth".
The script should use the next month and compare it to the field "BdayMonth" and display those names.
Right now the script that runs when the button is clicked is:
New Window
Goto layout
Set Variable [$NextMonth; Value:_Contacts::cc_NextMonthDayMonth]
Enter Find mode []
Set Field[_Contacts::bDayMonth; $NextMonth]
Perform Find[]
Enter Preview Mode[]
Print Setup[Restore]
Print[Restore]
CLose Window[Current Window]
---------------------------------------------------

On "Contacts" table I have a field called:"cc_NextMonthBdayMonth" it holds the following calculation:
MonthName(MonthsAhead((Get(CurrentDate));1))
---------------------------------------------------
The "MonthName" is a custom function.  The code is:
Let(
   [guess = Date(Month(NextMonth) + months; Day(NextMonth); Year(NextMonth));
   expectedMonth = Mod(Month(NextMonth) + months - 1; 12) + 1];

   If ( Month(guess) = expectedMonth; guess; Date(Month(NextMonth) + months + 1; 1; Year(NextMonth)) - 1 )
)

Where I created the parameters: "NextMonth" & "months"
----------------------------------------
The code worked for the month of March when it was clicked it displayed the records that the month was "April" in the field "bDayMonth" in the "Contacts" table.
But now in the month of "April" when I click onthe button, it still displays the records for "April".

How do I create the correct code or fix this?
j_ramesesInfo Sys MngrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lesouefCommented:
woh, rather complex for what it does? what's the goal here? show records with a date of which the month is the next one (from today)?
and what is months? and monthsahead?
0
j_ramesesInfo Sys MngrAuthor Commented:
Yes, I need it to when clicked gather all the records that the month is the next month so we can print out labels to mail them a birthday card.
Months ahead is a function. the code is above it is:
Let(
   [guess = Date(Month(NextMonth) + months; Day(NextMonth); Year(NextMonth));
   expectedMonth = Mod(Month(NextMonth) + months - 1; 12) + 1];

   If ( Month(guess) = expectedMonth; guess; Date(Month(NextMonth) + months + 1; 1; Year(NextMonth)) - 1 )
)
-----
I accidently said that the name of the functions is : monthName
0
lesouefCommented:
I don't know what is "months", but this is weird to me as I understand that if the month of guess is the expected one, you keep the guess date, and if not, you pick up the next month date. what for? do I miss something? who made this function? do you have the equiv in human language?
is that supposed to get the next month name? or more?
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

j_ramesesInfo Sys MngrAuthor Commented:
What I need the code to do is that when ever the user clicks on the birthday card button is to make a variable the value of the next month.  Then that value will be compared to all records to search in the "bDayMonth" field of the "Contacts" table to search for the value of the variable that is the next month.  For example, say we are in the month of April.  The variable should retrieve the value of "May".  I need a variable with that value because I have two other scripts that use that value.  So when the button is clicked it will look for any record that has the value of "May" in the "bDayMonth" field from the "Contacts" table.  If we are in the month of May, it should pull up the records that the birth month is June.  That is what I need it to do.
0
TocacarCommented:
variable = MonthName(Date(Month( Get ( CurrentDate) ) + 1;Day(Get ( CurrentDate));Year(Get ( CurrentDate))))
0
j_ramesesInfo Sys MngrAuthor Commented:
where do I create the variable & what type of field is it?text?calc?
0
TocacarCommented:
Make a global text field and store the value in that as part of the script, then in the 'Enter Find Mode / Set Field ....' section you can use the global field to set the search criteria in the Set Field step.  Remember to clear the global field at the end of the script.

As it's a *global* text field, you can put this in any table you like and you will be able to grab the value in it regardless of which layout (table occurrence context) you are on.
0
j_ramesesInfo Sys MngrAuthor Commented:
we have a table called "@_Global".
Can I put it there?
Also, how do I clear the global field at the end of the script?
0
TocacarCommented:
That's great, put it in there.  

To clear the global field, just do:  

Set Field [ <your global field's name> ] = ""
0
lesouefCommented:
why do you want to store it?
the var is text, always in fm. to calc its value, use tocacar's formula whihc is correct.
you can use it directly by searching the date field in contacts=
$var & "-*-*"
if - is you regional date separator with the US date format.
change this  if you use another format. European french format would be:
"*/" & $var & "/*"
0
j_ramesesInfo Sys MngrAuthor Commented:
Also, how do I clear the global field at the end of the script?
0
lesouefCommented:
set global field = ""
0
TocacarCommented:
lesouef:  I thought that also, but then I thought he may be better off storing the value in a global field as he says he uses the currentmonth+1 value in two other scripts.

j_rameses:  Don't worry about clearing the global field - I see above that you want to use this value again in other scripts.  The best time/ place to save this value in the global field would be as part of a script that runs automatically when a user logs in.  The script (call it 'login' if you like) should have the following steps:

set variable $myvariable = use the calc I provided above
set Field [<my global field>] = $myvariable

To have this script run automatically whenever someone logs in, go to File/ File Options and select the script to run at login (the settings to select are obvious).

You will now be able to access this value throughout the user session, and use it in any script you like.

An alternative to using a global field is to instead just create a global variable.  You do this using two "$" signs in front of the variable name:

$$myvariable  (is global)
$myvariable    (is local)

Either option will suit your purposes just fine, but if you go the global variable route, remember to always have 2 dollar signs ($$) in front of the variable name.




0
lesouefCommented:
the global field has an advantage in case you'd like to use to filter a portal
0
j_ramesesInfo Sys MngrAuthor Commented:
So, in the "@_Global" table I should use the field "cc_NextMonth" and enter the following calculation:
variable = MonthName(Date(Month( Get ( CurrentDate) ) + 1;Day(Get ( CurrentDate));Year(Get ( CurrentDate))))
Where variable is equal to my "cc_NextMonth"?
-----------------------
Then my script which is called: Next Month B-day Card" has the following code?:
New Window [Name: @_Global::cc_NextMonth & "'s Birthday Mailing Card List"; Height:850; Width:.....]
Goto layout
Set Variable [$NextMonth; Value: @_Global::cc_NextMonth ]
Enter Find mode []
Set Field[_Contacts::bDayMonth; $NextMonth]
Perform Find[]
Enter Preview Mode[]
Print Setup[Restore]
Print[Restore]
CLose Window[Current Window]

Is that what the code should look like for the script?
0
TocacarCommented:
You're almost there.  It's just a little bit scrambled.

1.  Make a brand new global field, stored your global table, called 'NextMonth' (this is a text field set to have global storage).  You are going to use this field in your scripts.

2. Make a script called 'Log In Script' with the following two steps:

set variable $myvariable = use the calc I provided above
set Field [<my global field>] = $myvariable

If you already have a script set to run at login, just include these two steps in it.  If you don't already have a script set to run at login, create one, as mentioned above, and then go to File/ File Options and select it to run when the file is opened (i.e., when the user logs in); the settings to choose are obvious.

2.  With that done, close the file, then log back in.  Your global field 'NextMonth' now has the name of next month stored in it.

3.  Now, modify your script as follows:

New Window [Name: @_Global::NextMonth & "'s Birthday Mailing Card List"; Height:850; Width:.....]
Goto layout
Enter Find mode []
Set Field[_Contacts::bDayMonth; @_Global::NextMonth]
Perform Find[]
Enter Preview Mode[]
Print Setup[Restore]
Print[Restore]
CLose Window[Current Window]

4.  Voila!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
j_ramesesInfo Sys MngrAuthor Commented:
Let me disect this:
set variable $myvariable = use the calc I provided above
set Field [<my global field>] = $myvariable

$myvariable = use that name or come up with my own?
-------------------------------
use the calc I provided above = MonthName(Date(Month( Get ( CurrentDate) ) + 1;Day(Get ( CurrentDate));Year(Get ( CurrentDate))))
--------------------------------
[<my global field>] = should this be a different name i create or is it "NextMonth" & do i have to use the "<>" symbols
0
TocacarCommented:
$myvariable = use that name or come up with my own?  
 
        -  by all means, feel free to choose, it's not important.  I simply used that as an obvious way to refer to it during the example

use the calc I provided above = MonthName(Date(Month( Get ( CurrentDate) ) + 1;Day(Get ( CurrentDate));Year(Get ( CurrentDate))))
       
       -  correct

[<my global field>] = should this be a different name i create or is it "NextMonth"
 
       -  once again, feel free to choose, it isn't import.  I was simply illustrating the example.  Giving it another name will not make it work any differently.

 & do i have to use the "<>" symbols

      -  no, this was just my way of encapsulating the field name to make it *stand out* from the rest of the text.




0
j_ramesesInfo Sys MngrAuthor Commented:
Lets say <my global field> i will call "theFollowingMonth"
where will I use this "theFollowingMonth"?
Is this the one I will use on my other two scripts?
0
TocacarCommented:
Yes.
0
j_ramesesInfo Sys MngrAuthor Commented:
I am on the creating script page.
I have:
Set Variable [$myVariable; Value:MonthName(Date(Month( Get ( CurrentDate) ) + 1;Day(Get ( CurrentDate));Year(Get ( CurrentDate))))]
Set Field [@_Globals::NextMonth]
0
TocacarCommented:
Change:  

Set Field [@_Globals::NextMonth]

To:

Set Field [@_Globals::NextMonth] = $myVariable

Then you will have the name of next month stored in the global field.
0
j_ramesesInfo Sys MngrAuthor Commented:
oops i hit the submit button.
i continuation to the above:
               set Field [@-Globals::NextMonth] = $myvariable
Where do I put the value "$myVariable"?
Do I click on "CaLCULATED Result" button and enter the value "$myVariable"
     
0
j_ramesesInfo Sys MngrAuthor Commented:
I could only make it look like:
Set Field [@_Globals::NextMonth]; $myVariable
0
j_ramesesInfo Sys MngrAuthor Commented:
How do I get the button to display the value of @_Global::NextMonth + whatever other wording i want?
0
TocacarCommented:
I don't understand your apparent confusion.  You are asking questions about script steps that are already familiar to you, as you demonstrate in your original question.  

To display the value of the global field on the button, in Layout Mode, go to Insert/Merge Field and select the global field from the list.  You can add any other text you want by simply typing it, using the keyboard.

You now have all the information you need to complete your task.
0
j_ramesesInfo Sys MngrAuthor Commented:
I forgot to mention, I figure it out before your response.
I am only wondering if a button can have the text in it change to the value of "NextMonth"?
I did it for the tooltip and it works.
0
TocacarCommented:
It can, as described in my most recent post.
0
j_ramesesInfo Sys MngrAuthor Commented:
oops sorry I should read more carefully
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
FileMaker Pro

From novice to tech pro — start learning today.