Help with dynamic arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DJAudette
    New Member
    • Feb 2006
    • 1

    Help with dynamic arrays

    Hello

    I am using vba in excel. I am trying to do the following seeing instr is not working I am writing my own program. Just I am having an issue with this
    dynamic array.

    here is a clip of my code

    Code:
        Dim mystring1() As String ' the serial number field
        Dim mystring2() As String 'the data field
    
        Dim searchfield As Integer, searchbyfield As Integer 'hold length of both fields
        searchfield = Len(searchable) 'get the length of the data string"
        searchbyfield = Len(searchby)'get the lenght of the serial number
        ReDim mystring1(searchbyfield) As String
    ***I get the followin error with the next line of code. "Can't assignt to array"
    searchby is a string past in from the main subroutine.****
        mystring1 = searchby
        ReDim mystring1(searchfield) As String
        mystring2 = searchable
    any idea's on how to help

    Thanks
    Last edited by Killer42; Feb 22 '07, 02:01 AM. Reason: Please use CODE tags in your message
  • AlanHill1965
    New Member
    • Feb 2007
    • 8

    #2
    Hi,

    I think the problems lies with the a bit of confusion in the variables names used.

    Dim mystring1() As String ' the serial number field
    Dim mystring2() As String 'the data field

    Dim searchfield As Integer, searchbyfield As Integer 'hold length of both fields
    searchfield = Len(searchable) 'get the length of the data string"
    searchbyfield = Len(searchby)'g et the lenght of the serial number
    ReDim mystring1(searc hbyfield) As String
    ***I get the followin error with the next line of code. "Can't assignt to array"
    searchby is a string past in from the main subroutine.****
    mystring1 = searchby
    ReDim mystring1(searc hfield) As String
    mystring2 = searchable
    first you creat two arrays 'mystring1 and mystring2', then you re dimension 'mystring1'.

    The next step is the confusion you try to place the variable 'searchby' into a variable called 'mystring1' - which is an array without telling where in the array to place it?, thus the confusion.

    If you just placed a number in brackets the system would then place it for you. If this is not where it is supposed to go the the variable - NOT the array will have to have its name changed.

    I hope this what you are looking for.

    Alan Hill
    'Blue. Eyes and Soul'

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      What was the original problem with Instr()? Perhaps we can help.

      Comment

      Working...