ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Tips and Tricks
Downloads

Tips and Tricks Share helpful modeling ideas

  #1  
Old 12-15-2007
Cliff King's Avatar
Cliff King Cliff King is offline
Vice President Technical Services
 
Join Date: Jul 2007
Location: Utah
Posts: 272
Downloads: 158
Uploads: 14
Thanks: 102
Thanked 304 Times in 110 Posts
Rep Power: 412
Cliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud of
Default Using multi-dimensional arrays with flexscript

There are no multi-dimensional arrays in flexscript per se; however the script shown below can be helpful when working with multi-dimensional data. It basically takes a one dimensional array and sets it up to be referenced as if it were a two dimensional array. You can extend this concept to further dimensions as well.

//The following two macros named ROW and COL can be defined within
// the code, or defined globally in Tools>Global Variables>Global Macros.
// If defined globally, they will show in a different color which is useful.
#define ROW (cols+1)*
#define COL +

int cols = 5;
int rows = 20;
doublearray myarray = makearray((cols+1)*(rows+1));
myarray[ ROW 1 COL 1] = 4.3;
myarray[ ROW 1 COL 2] = 4.4;
myarray[ ROW 1 COL 3] = 4.5;
myarray[ ROW 1 COL 4] = 4.6;
myarray[ ROW 1 COL 5] = 4.7;
myarray[ ROW 2 COL 1] = 5.3;
myarray[ ROW 2 COL 2] = 5.4;
myarray[ ROW 2 COL 3] = 5.5;
myarray[ ROW 2 COL 4] = 5.6;
myarray[ ROW 2 COL 5] = 5.7;

for(int i = 1; i <= 2; i++)
{
for(int j = 1; j <= 5; j++)
{
pt("row "); pd(i); pt(" col "); pd(j);
pt(" "); pf(myarray[ ROW i COL j]); pr();
}
}

The printout is as follows:
row 1 col 1 4.300000
row 1 col 2 4.400000
row 1 col 3 4.500000
row 1 col 4 4.600000
row 1 col 5 4.700000
row 2 col 1 5.300000
row 2 col 2 5.400000
row 2 col 3 5.500000
row 2 col 4 5.600000
row 2 col 5 5.700000

Last edited by Cliff King; 12-15-2007 at 11:35 AM.



All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.