rubberduck-vba / Rubberduck

Every programmer needs a rubberduck. COM add-in for the VBA & VB6 IDE (VBE).
https://rubberduckvba.com
GNU General Public License v3.0
1.91k stars 299 forks source link

Oh yeah! Very, very, very, very long parse message I could not read in order to understand... #936

Closed PeterMTaylor closed 8 years ago

PeterMTaylor commented 8 years ago

G'Day, I found another tricky error from my end. I decided to test Rubberduck with a VBA code that I had obtained from a Bruce McPherson's website http://ramblings.mcpher.com/ cDataSetSkeleton.xlm Excel file to see how it reacts. The trouble is the parser completed reading the project which is fine however found a error message that is WAY WAY long for me to read and could not work out what the complaint is? Shame I could not scroll it side ways/hoping a multi-line breakdown/even stretching the dialogbox wider, WIDER and WIDER! to see what the issue is, here is the snap. 2016-01-13 5 Any suggestions as the meaning of this long message for me to do next or has other issues been raised like this that I may need to be aware of using this feature in future? Ta.

Vogel612 commented 8 years ago

Oh Cool a parser bug. It seems that the code isn't correctly parsed by the current Grammar. These bugs aren't really commonplace.

Would you mind grabbing and pasting the function or sub that's around line 218? It seems that the parens aren't correctly handled there.

PeterMTaylor commented 8 years ago

Sure. To respect the source cDataSetSkeleton.xlm (UserfulStuff) where the info comes from, Bruce McPherson (http://ramblings.mcpher.com) below is his function which Rubberduck spat the parse dummy! :relaxed:

Public Function URLEncode( _
   StringVal As String, _
   Optional SpaceAsPlus As Boolean = False, _
   Optional UTF8Encode As Boolean = True _
) As String

Dim StringValCopy As String: StringValCopy = _
    IIf(UTF8Encode, UTF16To8(StringVal), StringVal)
' Here is where the error is detected!!!
Dim StringLen As Long: StringLen = Len(StringValCopy)

If StringLen > 0 Then
    ReDim Result(StringLen) As String
    Dim i As Long, CharCode As Integer
    Dim Char As String, Space As String

  If SpaceAsPlus Then Space = "+" Else Space = "%20"

  For i = 1 To StringLen
    Char = Mid$(StringValCopy, i, 1)
    CharCode = Asc(Char)
    Select Case CharCode
      Case 97 To 122, 65 To 90, 48 To 57, 45, 46, 95, 126
        Result(i) = Char
      Case 32
        Result(i) = Space
      Case 0 To 15
        Result(i) = "%0" & Hex(CharCode)
      Case Else
        Result(i) = "%" & Hex(CharCode)
    End Select
  Next i
  URLEncode = Join(Result, "")

End If
End Function
Vogel612 commented 8 years ago

Possible duplicate: #861 "Instructions separator breaks parser in specific circumstances"

retailcoder commented 8 years ago

@PeterMTaylor I just pushed a commit to my fork that successfully handled the above function :smile:

This issue will automatically close when I merge my changes into this repo.

PeterMTaylor commented 8 years ago

Cool. Thanks for that. Looking forward to re-test this myself when it is released.