Results 1 to 6 of 6

Thread: String Array Error

  1. #1
    Board Regular BlakeSkate's Avatar
    Join Date
    Jan 2015
    Location
    Pernsylvoonia
    Posts
    463
    Post Thanks / Like
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Default String Array Error

    Code:
    Sub test()
    Dim textVAR(0 To 5) As String
    Dim i as Long
    
    textVAR(0) = "Do"
    textVAR(1) = "Re"
    textVAR(2) = "Me"
    textVAR(3) = "Fa"
    textVAR(4) = "So"
    textVAR(5) = "La"
    
    For i = LBound(textVAR) To UBound(textVAR)
    
    If textVAR = "Do" Then
    msgbox textVAR
    Else
    msgbox "Nope"
    End If
    
    next i
    End Sub
    if i pull textVAR into the watch window it shows value as "Can't compile module" and type "Empty"
    its highlighting the = on the if statement with type mismatch error
    Last edited by BlakeSkate; Aug 27th, 2019 at 04:13 PM.
    -------------------------------------------------------------------------------
    I may not give the best VBA codes, but they sure are VBA codes.
    Help me help you by posting a snapshot of your data & your expected result
    Please use [ code][ /code] tags when posting VBA as well as proper indentation

  2. #2
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    6,340
    Post Thanks / Like
    Mentioned
    73 Post(s)
    Tagged
    14 Thread(s)

    Default Re: String Array Error

    You must indicate the index

    Code:
    Sub test()
      Dim textVAR(0 To 5) As String
      Dim i As Long
      textVAR(0) = "Do"
      textVAR(1) = "Re"
      textVAR(2) = "Me"
      textVAR(3) = "Fa"
      textVAR(4) = "So"
      textVAR(5) = "La"
      For i = LBound(textVAR) To UBound(textVAR)
        If textVAR(i) = "Do" Then
          MsgBox textVAR(i)
        Else
          MsgBox "Nope"
        End If
      Next i
    End Sub
    Regards Dante Amor

  3. #3
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,383
    Post Thanks / Like
    Mentioned
    471 Post(s)
    Tagged
    47 Thread(s)

    Default Re: String Array Error

    Because textVAR is an array you cannot use
    Code:
    If textVAR = "Do" Then
    I suspect you mean
    Code:
    If textVAR(i) = "Do" Then
    you'll need to add that to the next line as well
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  4. #4
    Board Regular BlakeSkate's Avatar
    Join Date
    Jan 2015
    Location
    Pernsylvoonia
    Posts
    463
    Post Thanks / Like
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Default Re: String Array Error

    thank you both for the replies
    it's been a day
    -------------------------------------------------------------------------------
    I may not give the best VBA codes, but they sure are VBA codes.
    Help me help you by posting a snapshot of your data & your expected result
    Please use [ code][ /code] tags when posting VBA as well as proper indentation

  5. #5
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,383
    Post Thanks / Like
    Mentioned
    471 Post(s)
    Tagged
    47 Thread(s)

    Default Re: String Array Error

    Glad we could help & thanks for the feedback
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  6. #6
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    6,340
    Post Thanks / Like
    Mentioned
    73 Post(s)
    Tagged
    14 Thread(s)

    Default Re: String Array Error

    I'm glad to help you. Thanks for the feedback.
    Regards Dante Amor

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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