0

This code was converted from VB6 to VB.Net:

Public prvMainForm = VB6Form    
If prvMainForm IsNot Nothing Then
    CObj(prvMainForm).StatusBar.Panels(1) = "Initializing Folders..."
End If

(My code is quite long so I've just added this if block which is where the actual error occurs.)

The error is seen on the single line inside the If statement:

Property 'Item' is 'ReadOnly'

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Snehil
  • 45
  • 1
  • 9
  • 2
    Apparently you meant to set a property of the object that `.Panels(1)` returns. So specify that property. – GSerg Jan 13 '20 at 17:03
  • I tried .Panels(1) in the immediate window and seems like it should be .Panels(1).Text – Snehil Jan 13 '20 at 17:08
  • 1
    In VB6 that statement is equivalent to `Set CObj(...).Panels(1) = ...`. With Set indicating that you meant to replace the object instead of assigning the panel's Text property. VB.NET dropped support for Set, too much ambiguity. – Hans Passant Jan 13 '20 at 17:29

1 Answers1

5

StatusBar.Panels(1) returns a MSComctlLib.Panel.

StatusBar.Panels(1) = "Initializing Folders..." is valid in VB6 because of default properties.

Default properties in VB.NET must have parameters. A parameterless property cannot be default and therefore cannot be omitted. Thus, .Panels(1) = "..." is understood by VB.NET as an attempt to replace the entire Panel in the Panels property, which is not allowed.

You can look up the name of the default property in the VB6 object browser, which turns out to be Property _ObjectDefault As String, so you should be able to do:

CObj(prvMainForm).StatusBar.Panels(1).[_ObjectDefault] = "Initializing Folders..."

As you have observed, assigning Text should do the same:

CObj(prvMainForm).StatusBar.Panels(1).Text = "Initializing Folders..."
GSerg
  • 76,472
  • 17
  • 159
  • 346