ATTENTIONThis 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 |
#1
|
|||
|
|||
Search for cell and value
Hello everybody,
is it possible to search for a specific cell value depending on the itemtype of a flowitem? I have multiple itemtypes (aprox. 30) and depending on the itemtype the Flowitems should be processed on different processors (A1, A2, B1, B2). I.e.: Itemtype 12 is processed on A1, then on B1 / Itemtype 13 on A1, then on B2. I want to set the outputport of my processors depending on the itemtype. Since I have quite a few itemtypes and different processors I want to use a GlobalTable for it. My itemtypes equal the real part numbers, so I cannot get the value for the cell row using getitemtype(item). I don't want the table to be static and say like "ItemType 12 is always in row 3", because I might have to include new itemtypes in the table. This is why I want to "search" my table for the corresponding row. Thank you in advance! Jens |
#2
|
||||
|
||||
Hello Jens,
you can search your global table with a for loop Code:
/**By Global Table Lookup*/ /** \nTable: */ string tablename = /**/"GlobalTable3"/**/; /** \nRow: */ int row = /**/1/**/; for(row;row <= gettablerows(tablename);row++) { if(comparetext(gettablestr("GlobalTable3",row,1),getlabelstr(item,1))) // compare the string of the first label in the item break; // look for the right row and break out from the for loop } /** \nColumn: */ int col = /**/2/**/; // column of the Output port from the globaltable return gettablenum(tablename,row,col) instead of the break in if-statement you can use the command return, which is a bit shorter. Jörg |
The Following User Says Thank You to Jörg Vogel For This Useful Post: | ||
Eleni Liosi (02-16-2014) |
#3
|
|||
|
|||
Hi Jörg,
first of all thanks a lot. I used your code, but can't get it running. Code:
treenode item = parnode(1); treenode current = ownerobject(c); /**By Global Table Lookup*/ /** \nTable: */ string tablename = /**/"test"/**/; /** \nRow: */ int row = /**/1/**/; for(row;row <= gettablerows(tablename);row++) { if(comparetext(gettablestr(tablename,row,1),numtostring(getitemtype(item)))) // compare the string of the first label in the item colorrandom(current); break; // look for the right row and break out from the for loop } /** \nColumn: */ int col = /**/2/**/; // column of the Output port from the globaltable return gettablenum(tablename,row,col); I would be grateful if you might have a look at my test model. Thank you, Jens // Tried something else and it worked, because I only use integers and no strings I can compare the data mathematically. Still, I don't find the real error in the code above! Anyways! Thanks a lot, Jörg! Code:
treenode item = parnode(1); treenode current = ownerobject(c); /**By Global Table Lookup*/ /** \nTable: */ string tablename = /**/"test"/**/; /** \nRow: */ int row = /**/1/**/; for(row;row <= gettablerows(tablename);row++) { if(gettablenum(tablename,row,1) == getitemtype(item)) {break;} } /** \nColumn: */ int col = /**/2/**/; // column of the Output port from the globaltable return gettablenum(tablename,row,col); |
#4
|
||||
|
||||
Code:
if(comparetext(gettablestr(tablename,row,1),numtostring(getitemtype(item)))) // compare the string of the first label in the item { colorrandom(current); break; // look for the right row and break out from the for loop } |
The Following User Says Thank You to Carsten Seehafer For This Useful Post: | ||
Jens Mühlheimer (03-13-2012) |
#5
|
|||
|
|||
Hello,
Isn't this just as the example from the basic training?.. you use a table and a label. on the table each row is a itemtype, and each column is a step, on each cell you have the output port for that step. then on the exit trigger of the processors(or the entry trigger of the queue) you set the set label to +1. On the send to port from the queue you just read from the table entering the itemtype and step of the process for the row and column. not sure if i'm right but this sounds a lot like that... regards Pablo |
#6
|
|||
|
|||
Quote:
I also used this code but it didn't do the trick. I don't know why .. |
#7
|
||||
|
||||
I haven't tested Jörgs code, but the missing brackets jumped into my eyes. Please have a look into Flexsim Users Manual. There is a chapter "Writing Logic in Flexsim" in "Flexsim Coding". It's a good overview about the syntax.
If you set a break point in your code you can see what happen in every line in your code (also in User Manual, Modeling Tools > Flexscript Step Debugging). Greetings Carsten |
The Following User Says Thank You to Carsten Seehafer For This Useful Post: | ||
Jörg Vogel (03-13-2012) |
#8
|
||||
|
||||
Hello Jens,
I compare two strings: one item label and stringvalue in a global table. Because there is only one statement after the if-statement, I have not used the brackets. I attach a small model, which works well for me. Jörg port from a global table.fsm Edit: The code is in the flow tab of each processor. Last edited by Jörg Vogel; 12-03-2014 at 03:31 AM. |
The Following User Says Thank You to Jörg Vogel For This Useful Post: | ||
Jens Mühlheimer (03-13-2012) |
#9
|
|||
|
|||
Thank you for the great help.
I also got it running now. I added another search function (for-loop) to go through the columns and check them for the machine numbers which I get from a string label of a processor. Using this I can use one table to assigne the processors (with alternatives) for all part numbers. |
Thread | Thread Starter | Forum | Replies | Last Post |
Search function | Nico Zahn | Q&A | 2 | 10-23-2010 02:04 AM |
Cell Control in a Rack | Gavin Douglas | Q&A | 2 | 10-22-2008 09:16 AM |
Search box in Time Tables etc. | Nico Zahn | Gripes and Goodies | 9 | 06-16-2008 09:57 AM |
Search and replace | Nico Zahn | Gripes and Goodies | 0 | 05-19-2008 01:54 AM |