7/3/2019 10:24 AM | |
Joined: 10/5/2017 Last visit: 2/16/2024 Posts: 7 Rating: (0) |
Device: TP700 Comfort Hello everyone , I am having a frustrating issue with trying to get this below script to work using the For loops "prdctCount" variable declared as "Dim prdctCount" as the array's index reference as shown.
Simply putting "prdctCount" itself as the index like this: SmartTags("ProductsCopy_DB_Dough_Ball{prdctCount}.Date_Time").Value Does not work. It made sense logically to me to have it this way, because if I put the exact index of the array element I want to access like this: SmartTags("ProductsCopy_DB_Dough_Ball{1}.Date_Time").Value It works. This tag is from a DB that has an array of UDT type with information about each dough ball. In the code snippet, I tried using {" & prdctCount & "} to reference the array index using the tag, however, it still does not work. I have had a look at https://support.industry.siemens.com/cs/ww/en/view/26165877 and I cant make sense of anything. Attached in the error message I get when trying it with the aforementioned code. Kind regards
|
Last edited by: Jen_Moderator at: 07/03/2019 14:00:19Optimized link. Last edited by: BGImmelman at: 07/04/2019 11:23:18hmi, array, indexing, for loop, WinCC, VBScript, datalogging, UDT |
|
7/8/2019 1:08 PM | |
Joined: 10/5/2017 Last visit: 2/16/2024 Posts: 7 Rating: (0) |
Nobody have any suggestions / ideas? |
7/10/2019 12:41 PM | |
Joined: 7/5/2013 Last visit: 4/24/2024 Posts: 3073 Rating: (505) |
Hello BGImmelman, I found this discussion about the tag-name-assembly in a script in the German forum. mm76 found that tags with assembled names in scripts work when the tags are used with I/O fields. Finally he created a dummy script (which is not called in the application) where the tags (with the complete names) are assigned with 0. Then also the assembling in the really used script would work. Regards, Frink |
Pi is exactly three! |
|
This contribution was helpful to1 thankful Users |
7/11/2019 8:51 AM | |
Joined: 10/5/2017 Last visit: 2/16/2024 Posts: 7 Rating: (0) |
Hey Prof. Frink,
I had a look at that forum as well, and tried to make sense of it myself, along with your summary. I don't understand what "tags with assembled names" implies, and for them to be used with I/O fields. Are you talking about tags declared locally in the script with "Dim whatever" that are then used with an I/O field element on the screen itself? _____________________________________________________________________________ Is my understanding correct in thinking that I have to set the acquisition mode for all tags I would be using (DB Tags too) to "Cyclic Continuous"? In addition to that, as you said, have a separate dummy VBScript which just initializes all the tags linked to the array DB to 0 (and any other internal hmi tags), for example: SmartTags("ProductsCopy_DB_Dough_Ball{1}.Recipe_Number").Value = 0 (For each element?) while still using a locally declared Dim prdctCount variable to access the array's elements through the loop? ______________________________________________________________________________ Or rather use an internal integer type HMI tag and initialize that in a dummy script too, and then link it to the local prdctCount variable. Something like: SmartTags("indexNr") = prdtCount where I then use the internal tag to reference the array's index instead? SmartTags("ProductsCopy_DB_Dough_Ball{" & indexNr & "}.Recipe_Number").Value For prdctCount = 1 To 10 SmartTags("indexNr") = prdtCount 'CREATE DATASET TO POPULATE CSV FILE ROW dataValues = _ SmartTags("ProductsCopy_DB_Dough_Ball{" & indexNr & "}.Date_Time").Value & ";" & _ SmartTags("ProductsCopy_DB_Dough_Ball{" & indexNr & "}.Recipe_Name").Value & ";" & _ SmartTags("ProductsCopy_DB_Dough_Ball{" & indexNr & "}.Recipe_Number").Value & ";" & _ ... ... ... 'FILL CSV FILE ROW WITH DATASET fctl.LinePrint dataValues Next This feels like some sort of massive over-complication for just wanting to run a for loop to index through an array of UDT of whatever size. I apologize if I missed point. Thank you for at least taking the time to reply. Kind regards, BGImmelman |
2/17/2023 7:36 AM | |
Joined: 7/10/2012 Last visit: 11/22/2023 Posts: 2 Rating: (0) |
Hello BGImmelman Thank you for sharing the solution , this is very helpful . i have a question about the dummy script did u create 1024 line in your dummy script ? dummy 1 = .....[1] ...dummy1=....[1024] i try this solution and i only can acces the element of the array that i mentionned in the dummy script thank you in advance |
5/5/2023 12:10 PM | |
Joined: 8/3/2009 Last visit: 4/24/2024 Posts: 12854 Rating: (1639)
|
Hello everyone This leads all to the definition that is explained in the TIA Help System: https://support.industry.siemens.com/cs/ww/en/view/109813306/109377913227 Check " Note Current system behavior for dynamic access to elements of a user data type... " so If you wnat to get access to the Tags in this dynamicc way they have to be used somewhere else that the data manager recognises them. so in case of the dummy script, every item has to be mentioned or you create a dummy screen where you drag and drop every element of the UDTs (this will only take a few seconds). You do not have to open this Screen in Runtime, it only has to be loaded. Bye Murof |
If this Information really helps, you could use the Rate function |
|
This contribution was helpful to1 thankful Users |
Follow us on