PDA

View Full Version : Determine length of concatenated string before writing string tag to tag DB



ADonnell
12-23-2009, 11:43 AM
I am working with RSView 32.

I am taking 3 strings from one machine, concatenating them using VBA to create a master string and determining the length of that master string. Both the master string and its length are tags in my tag DB. Those tags are then sent to another machine.

The problem is that the masterstring length must be sent to the machine before the actual masterstring is sent. I know I should be able to #1 concatenate, #2 determine the length, #3 write the length of the masterstring to tag DB, then #4 after a short delay, write the masterstring to tag DB. But I don't know the code to do that. Any help out there?

How can you determine the length of a string tag before you create the string tag itself?

below is the code i am using:


Sub MasterStringConcatenation()
Dim MasterTag As Tag
Dim ProductIDTag As Tag
Dim RollIDTag As Tag
Dim RollPathTag As Tag
Dim MasterTagLength As Tag

Set MasterTag = gTagDb.GetTag("EI_NEXT_ROLL_STRING")
Set ProductIDTag = gTagDb.GetTag("MEM_PRODUCT_ID")
Set RollIDTag = gTagDb.GetTag("MEM_ROLL_ID")
Set RollPathTag = gTagDb.GetTag("MEM_ROLL_PATH")
Set MasterTagLength = gTagDb.GetTag("EI_NEXT_ROLL_STRING_LEN")


MasterTag.Value = "RollSetup" + vbLf + "Next={" + vbLf + " RollID=001" + vbLf + " RollPrefix =" + _
Chr(34) + RollIDTag.Value + Chr(34) + vbLf + " RecipeID =" + ProductIDTag.Value + vbLf + _
"RollDirectory=" + Chr(34) + RollPathTag.Value + Chr(34) + vbLf + "}"

MasterTagLength.Value = Len(MasterTag.Value)
MsgBox MasterTag.Value
MsgBox MasterTagLength.Value

End Sub

The extra stuff in the concatenation is there to meet special formatting requirements for the machine the string is being sent to.

Thank you for your help!

EDIT: Added VBA Tags Tommy

Tommy
12-24-2009, 06:36 AM
I may be missing something but why not:

Sub MasterStringConcatenation()
Dim MasterTag As Tag
Dim ProductIDTag As Tag
Dim RollIDTag As Tag
Dim RollPathTag As Tag
Dim MasterTagLength As Tag
'Added
Dim HldStr As String

Set MasterTag = gTagDb.GetTag("EI_NEXT_ROLL_STRING")
Set ProductIDTag = gTagDb.GetTag("MEM_PRODUCT_ID")
Set RollIDTag = gTagDb.GetTag("MEM_ROLL_ID")
Set RollPathTag = gTagDb.GetTag("MEM_ROLL_PATH")
Set MasterTagLength = gTagDb.GetTag("EI_NEXT_ROLL_STRING_LEN")

'Changed
HldStr = "RollSetup" & vbLf & "Next={" & vbLf & " RollID=001" & vbLf & " RollPrefix =" & _
Chr(34) & RollIDTag.Value & Chr(34) & vbLf & " RecipeID =" & ProductIDTag.Value & vbLf & _
"RollDirectory=" & Chr(34) & RollPathTag.Value & Chr(34) & vbLf & "}"

'Changed
MasterTagLength.Value = Len(HldStr)
'Added
MasterTag.Value = HldStr
MsgBox MasterTag.Value
MsgBox MasterTagLength.Value

End Sub

ADonnell
12-27-2009, 05:20 PM
Thanks alot Tommy! As I am very new to VBA, could you explain what the hld and/or hldstr function does?

Also, for future postings, how do I put the code in the proper format like you did with my post?

Merry Christmas and a Happy New Year!
-Alex

Tommy
12-28-2009, 07:40 AM
Pick the VBA button and place your code between the tags for the format.

hldstr is a variable that I added just to hold the string to get the count and place it in the tag. This way I set the length before setting the string.