bhoogter / VB6TocSharp

Free converter from VB6 to C#. See README for quick-start. See Wiki for more information.
MIT No Attribution
89 stars 32 forks source link

ConvertEnumLine does not like a comment line #13

Closed amooefel closed 2 years ago

amooefel commented 2 years ago

Conversion didn't like a commented line as part of an ENUM. For example:

Public Enum CP_PL_ENUM
   INDEX_STATUS = 0        'hidden
   INDEX_LINE_ID = 1       'hidden
   INDEX_LINE_NO = 2
   INDEX_ITEM = 3
   INDEX_ITEM_MFGSKU = 4
   INDEX_ITEM_VENSKU = 5
   INDEX_ITEM_STATUS = 6
   INDEX_PRODTYPE = 7
   INDEX_PROMO = 8
   INDEX_SOURCED = 9
   INDEX_CALC_PRICE = 10
   INDEX_DISCOUNT = 11
   INDEX_SURCHARGE = 12
   INDEX_LISTPRICE = 13
   INDEX_VALIDDATES = 14
   INDEX_MULTIPLESKUS = 15
''   INDEX_PROG_LINE_ID = 16   ' hidden
   COUNT_FIX_COLS = 16 ' number of defined fixed indexes (make sure to increase this if you need (add) another column
End Enum

The 2nd last line was commented (strangely by 2 apostrophes... shouldn't matter), but the ConvertEnumLine gets called with a blank line, which it doesn't expect.

Not sure if this is the appropriate fix, but I added a check for the line:

Public Function ConvertEnumLine(ByVal L As String) As String
  Dim Name As String, Value As String
  Dim Parts() As String

  If Len(L) > 0 Then
    Parts = Split(L, " = ")
    Name = Trim(Parts(0))
    If UBound(Parts) >= 1 Then Value = Trim(Parts(1)) Else Value = ""
    ConvertEnumLine = ""
    If Right(CurrentEnumName, 1) = "+" Then ConvertEnumLine = ConvertEnumLine & ", "
    ConvertEnumLine = ConvertEnumLine & Name
    If Value <> "" Then ConvertEnumLine = ConvertEnumLine & " = " & ConvertExpression(Value)
    CurrentEnumName = CurrentEnumName & "+"  ' convenience
  End If
End Function

Otherwise, the program completed without error.

Andrew.

bhoogter commented 2 years ago

Good catch. Fixed pretty much the way you suggested, other than adding a Trim().

Thanks for the report.