1

I have an application written in VB6.

This application contain a file with snippet containing a foreach loop. In this loop a method is adding controls to a section (section is a region in report).

I am trying to implement a functionality where:

when theheader is added in headerSection, tt will not add theHeader again, however this snippet is unable to do that. Where am I going wrong?

For Each thisColumn As Column In theColumns
  If thisColumn.Type = Column.ColumnType.Description Then
     AddDescriptionColumn(thisColumn, startColumnAt, headerTop)
  End If
 Private Sub AddDescriptionColumn(ByVal ColumnToAdd As Column, ByRef LeftPosition As Single, ByVal HeaderTop As Single)

  'Get report sections
  Dim headerSection As ActiveReports.Section = _theActiveReport.Sections(PageHeaderName)

  'Add column header text
  Dim theHeader As New ActiveReports.Label
  theHeader.Name = "lblDescription"
  theHeader.Text = ColumnToAdd.DisplayCaption
  theHeader.Font = ColumnToAdd.HeaderFont
  theHeader.Location = New PointF(LeftPosition, HeaderTop)
  theHeader.Size = New SizeF(columnWidth, _columnHeaderHeight)
  If TextHeight(ColumnToAdd.DisplayCaption, theHeader.Font, columnWidth) > _columnHeaderHeight Then
     theHeader.VerticalAlignment = ActiveReports.VerticalTextAlignment.Top
  Else
     theHeader.VerticalAlignment = ActiveReports.VerticalTextAlignment.Bottom
  End If
  theHeader.BackColor = Color.Transparent
  theHeader.MultiLine = True
  theHeader.WordWrap = True
  theHeader.Visible = True
  headerSection.Controls.Add(theHeader)
Nilay Vishwakarma
  • 3,105
  • 1
  • 27
  • 48
Amit Kumar
  • 1,059
  • 3
  • 22
  • 43
  • 3
    `Dim headerSection As ActiveReports.Section = _theActiveReport.Sections(PageHeaderName)` is invalid VB6 syntax. Is this VB.Net source? – wqw Jun 14 '14 at 09:41
  • This is VB.Net code not VB6 code. `SizeF`, `PointF` are .Net types. `For Each thisColumn As Column In theColumns` is VB.Net, it's not legal to use `As` inside `ForEach` in VB6. And as wqw said it's not legal to initialize variables on the `Dim` line in VB6 – MarkJ Jun 18 '14 at 11:53

0 Answers0