Results 1 to 3 of 3

Thread: add more text etc to end of array elememt

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    61

    add more text etc to end of array elememt

    I want to look in all the strings of an array for a substring that has the value of my variable 'Get' in it. Then, I want to add "SB =" and the value of variable SBValue (As Long) to the end of the string in each array element that contains the value of "Get". Eventually all elements of FineArr get "joined" and used in a text file.

    All variables and arrays are declared, I think I just don't have the right syntax, or the right idea?

    For I = LBound(FineArr) To UBound(FineArr)

    If Instr(FineArr(I), Get) Then Tmp2 = FineArr(I), "SB =", SBValue
    FineArr(I) = Tmp2

    Next I


    I'm sure there is a better way to add the necessary to each array element without using a temporary string?

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,430

    Re: add more text etc to end of array elememt

    It's a minor syntax issue, instead of using a comma you should use an ampersand (&), eg:
    Code:
    If Instr(FineArr(I), Get) Then Tmp2 = FineArr(I) & "SB =" & SBValue
    (it is possible to use + but that causes problems in some circumstances)

    You also don't need to use a temporary string, you can assign directly back to the same array element:
    Code:
    If Instr(FineArr(I), Get) Then FineArr(I) = FineArr(I) & "SB =" & SBValue

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    61

    Re: add more text etc to end of array elememt

    Thanks Si, that is now done.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width