Consulting

Results 1 to 4 of 4

Thread: Determine length of concatenated string before writing string tag to tag DB

  1. #1
    VBAX Newbie
    Joined
    Dec 2009
    Posts
    2
    Location

    Determine length of concatenated string before writing string tag to tag DB

    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:

    [vba]
    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
    [/vba]
    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

  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I may be missing something but why not:
    [VBA]
    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

    [/VBA]

  3. #3
    VBAX Newbie
    Joined
    Dec 2009
    Posts
    2
    Location
    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

  4. #4
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •