0

I've been given a VB6 program to convert to .NET, and while most of the VB6 specifics I've been able to figure out through googling, there's one that I just have no idea about. Winsock is used, but the conversion utility replaced it with AxMSWinsockLib.AxWinsock. The old code references an index property, which AxMSWinsockLib.AxWinsock doesn't have apparently, but I can't figure out what it's trying to do here. Any ideas?

Public Function PortsOpen(ByRef colWinsock As Collection, ByRef objWinsock As Winsock, ByVal LocalIPAddress As String) As Boolean

Dim Counter As Long
Dim sWS() As String

'Initial to open com. port

Counter = 0

If colWinsock.Count >= objWinsock.Index + 1 Then
    sWS = colWinsock.Item(objWinsock.Index + 1)
MarkJ
  • 30,070
  • 5
  • 68
  • 111
cost
  • 4,420
  • 8
  • 48
  • 80
  • 2
    Oh, does it have to do with [Control Arrays](http://www.thevbprogrammer.com/Ch09/09-05-ControlArrays.htm)? "You set up a control array by *naming one or more controls of the same type the same name and set the Index property of each control in the array* to a non-negative value (i.e., the controls in the control array are usually indexed from 0 to one less than the number of controls in the array)." –  Nov 06 '12 at 17:48
  • @pst I believe you are correct; you should post this as an answer. – Holistic Developer Nov 07 '12 at 00:01

1 Answers1

1

In VB6 you are allowed to have an array of controls then reference them later using an Index. This behavior does not exist anymore in .Net

I believe in your case, the old VB6 used arrays of winsock to facilitate communication with other peers.

For example, if the original form in VB6 was designed by adding a WinSock control, then changing its name to mySock and then manually setting its Index property value to 0, it becomes mySock(0)

Later in the program, all you need to do to make another copy of the control is

Dim currentNumberOfWinSocks as Integer
currentNumberOfWinSocks = mySock.UpperBound
Load mySock(currentNumberOfWinSocks + 1)

so for you to change this logic to .Net, you will have to go around this by declaring the Winsock variable array totally from the code side without relaying on the design control.

Ahmad
  • 12,336
  • 6
  • 48
  • 88