question

Brandon Frank avatar image
0 Likes"
Brandon Frank asked Brandon Frank commented

Flexscript combine two integer variables into one (current month and day)

Very straightforward FlexScript syntax issue I'm having:

I have two variables that represent the current day and month of the year. I want to combine them into one variable.

Example:

---------------------------------------------------------------------

int day = getmodelunit(CURRENT_DAY_OF_MONTH);

int month = getmodelunit(CURRENT_MONTH_OF_YEAR);

int today = month&day;

--------------------------------------------------------------------

I want the "today" variable to read as "712" (based on today's date of July 12th). Bonus points if you can tell me how to add a slash so it reads as "7/12".

Thanks!

FlexSim 17.1.1
flexscript
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Allister Wilson avatar image
3 Likes"
Allister Wilson answered Brandon Frank commented

To make 712 from 7 and 12, you can just use arithmetic :

int today = 100 * month + day;

You can't have a slash in a number. You'd need to use a string if you want to represent "7/12" :

string todayStr = numtostring(month) + "/" + numtostring(day);
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Brandon Frank avatar image Brandon Frank commented ·

Thank you!

0 Likes 0 ·