Results 1 to 4 of 4

Thread: how to send keywords within strings

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    2

    how to send keywords within strings

    Hi programmers can u pls help..

    Am looking for the easiest way to pass a string as an argument in a subroutine call -the catch is that although i want to send the string as one big simple string, i want the receiving subroutine to then see the string as now not just one big string, but instead as a bunch of disparate smaller strings and keywords and operators etc for this subroutine's *onward processing*..

    Here is an example of the complete string i want to send:

    "this value is " & ActiveSheet.Cells(intRowIndex, intColIndex).Value & " and the next value is " & ActiveSheet.Cells(intRowIndex, intColIndex + 2).Value

    -as you can see, the calling subroutine will fail after reading past "this value is "...

    unfortunately this structure of [literal] & [keyword] & [literal] etc could change for each subroutine call, depending on the structure of each argument instance.

    Hope that makes sense.. -Any ideas for a simple solution would be greatly appreciated.

  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: how to send keywords within strings

    In that case you don't want to send one big string but multiple strings instead. Easiest way to go would be to create an array of strings:
    Code:
    ' just for a sample
    Public Sub ReceiveArray(Arr As Variant)
        Dim lngA As Long
    
        For lngA = 0 To UBound(Arr)
            Debug.Print Arr(lngA) & " ";
        Next
    
        Debug.Print vbNewLine
    End Sub
    
    ' creating an array and calling the procedure
    Private Sub Form_Load()
        ReceiveArray Array("this value is", ActiveSheet.Cells(intRowIndex, intColIndex).Value, "and the next value is", ActiveSheet.Cells(intRowIndex, intColIndex + 2).Value)
    End Sub
    Other than that this seems a bit silly to me, so the best question to ask: what are you trying to do?

  3. #3
    Fanatic Member
    Join Date
    Dec 2007
    Location
    West Yorkshire, UK
    Posts
    791

    Re: how to send keywords within strings

    How about setting your literals to constants
    const 1st = "this value is "
    const 2nd = " and the next value is "

    1st & ActiveSheet.Cells(intRowIndex, intColIndex).Value & 2nd & ActiveSheet.Cells(intRowIndex, intColIndex + 2).Value

    Then in your receiving subroutine, use split() based on the Constants 1st, 2nd etc to extract the data again.

    However, I agree with Merri, it doesn't seem to be the most efficient way of doing it

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    2

    Re: how to send keywords within strings

    Hey thanks to both of you for your responses.

    I was considering an array but wasnt sure of syntax -thanks

    Reason for request is that I am calling a subroutine multiple times and of the 100-odd lines of code within it, there is only one that is unique for each call of this sub-routine -a file.writeline() statement, of which i pass into the parentheses the big string i was referring to.

    Probably not worth the effort but I figured was worth asking.

    Thanks again.

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