1

I maintain an ASP.NET/VB.NET website that targets .NET 3.5. I used to build with no issues. all of the sudden I start getting building errors:

error BC30389: 'i' is not accessible in this context because it is 'Friend'

for every single-letter for loop control variable. for example:

For i = 0 To oDataTable.Columns.Count - 1
strHtml += "<td style='border : 1px solid black; font-size :13pt;'>" +         oDataTable.Columns(i).ColumnName + "</td>"
Next

If I change the var name from 'i' to 'ii' it goes away but that's not an option because we use for loop control vars like that in a million places in this site. I have never seen this type of errors before.

Here are my compiler settings:

<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="OptionInfer" value="true"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>

The only thing new on my work station is that I installed .NET 4.5.2.

Any help would be greatly appreciated.

  • 3
    It sounds like a Friend variable exists with the name `i` that is conflicting with your loop variables. If you right click and choose _Go to definition_ maybe you can find the friend variable. – Chris Dunaway Aug 06 '15 at 14:46
  • Did you Dim your variable first? If not, I would suggest you turn Option Strict On – the_lotus Aug 06 '15 at 15:43

1 Answers1

0

I think For Each is the better approch to loop through a collection which size is unknown. so you can loop through the Datacolumns using For Each as this

    Dim strHtml As new  StringBuilder()
    For Each dc As DataColumn In oDataTable.Columns
        strHtml.Append("<td style='border : 1px solid black; font-size :13pt;'>" + dc.ColumnName + "</td>")
    Next

And here i suggest you to use StringBuilder instead for string. since it consumes less amount of memory.

Community
  • 1
  • 1
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88