2/16/2012 10:50 AM | |
Joined: 8/31/2005 Last visit: 8/20/2024 Posts: 2198 Rating: (328)
|
This is my Idee (I put it in the attachment too) AttachmentFB.zip (99 Downloads) |
|
|
2/16/2012 11:25 AM | |
Joined: 10/7/2005 Last visit: 9/16/2024 Posts: 3020 Rating: (1054)
|
Hello anthroid bad news first: You need a numericvalue (a number) and can NOT use symbolic names to indirectly open DB's in STL (SCL allows it for Block internal variables, but I don't think it's going to really help you in your case and also don'tknow if you have SCL). Here's what you can dothough: Case 1: All the DB numbers of your few hundred DB's are sequential, let's say for example starting with DB101 and ending with DB400. Your INT value in this examplehas a range of 1 to 300. Code: L INT_value // INT_valuein the range of 1 ... 300 + 100 // add 100 to it T TEMP_INT//store DB numberin localINT variable OPN DB [TEMP_INT] // Open DB xyz (e.g. DB110 if original INT_valuewas 10) // Access whatever variable you need to access in the now open DB Case 2: The DB numbers of your few hundred DB's are "all over the place", for example DB 10, 12, 17, 20, 30, 31, 32, 33, 34, 38, 42etc. etc.. Your INT value however is in this example still a "linear" index value in therange of 1 to 300. An index value of 1 now needs to open DB10, a value of 2opens DB12, 3 opens DB 17 etc, etc. To make the link between the "linear" index value and the asscociated DB number, you create a so called "lookup table" which maylook likebelow: Address Symbol Value 0 A1234 10 2 A1235 12 4 A123617 6 A123720 8 A1238 30 etc. Code: L INT_value // INT_value in the range of 1 ... 300 + -1 // subtract 1(first DB value in lookup DB is in address 0) SLD4 // SLD 3 = Make S7 pointer, SLD 1 =multiply with 2 as DB is made up of INT's T TEMP_DWORD//store pointer value in local DWORD variable OPN DB "lookup" // open lookup DB L DBW [TEMP_DWORD] // load DB number for the lookup entry T TEMP_INT //store DB number in local INT variable OPN DB [TEMP_INT] // Open DB xyz (e.g. DB17 if original INT_value was 3) // Access whatever variable you need to access in the now open DB I hope this helps and note too that you'll find plenty of indirect addressing related examples with a search on that subject here. |
Cheers |
|
2/16/2012 4:22 PM | |
Joined: 11/4/2011 Last visit: 8/4/2024 Posts: 9 Rating: (0) |
ha, very good point. i think i'll have to build a table to link the values to DB numbers. thanks. |
Follow us on