0
votes

So I know that my code below works. The purpose is to create a tcp Ethernet connection between a scale and computer, so that when a weight is read on the scale, the value is displayed on the computer at the push of a button. I copied this code to a new lab machine that was just imaged for me. As for the winsock, I dynamically created it at run-time by adding it to the references. I understand that this is not what I am supposed to do (see: https://support.microsoft.com/en-us/kb/313984).

With a breakpoint at the CFixPicture_Initialize function, the code hits "set tcpC = new Winsock" line and breaks with error 429: avtiveX componenet can't create object. Does anybody have any ideas as to how I can get this license/get this Winsock control to work? Thanks!

 Option Explicit

Private WithEvents tcpC As Winsock

Private Sub CFixPicture_Close()
    Set tcpC = Nothing
End Sub

Private Sub CFixPicture_Initialize()

    Set tcpC = New Winsock
    tcpC.LocalPort = 0
    tcpC.Connect "192.168.0.1", 8000

End Sub

Private Sub CommandButton1_click()

    On Error GoTo errHandler
   tcpC.SendData "S" & vbCrLf
Exit Sub

errHandler:
   MsgBox "error:" & Err.Description
End Sub

Private Sub tcpC_DataArrival(ByVal bytesTotal As Long)
    Dim strData As String
    Dim strDataString As String
    tcpC.GetData strData
    strDataTrim = Mid(strData, 11)
    Text1.Caption = "Weight: " & vbCrLf
2

2 Answers

1
votes

The control is not present or is present but not registered on the new machine.

  • Copy over mswinsck.ocx from your *system directory to the new machines *system directory
  • Open a console as admnistrator and run regsvr32.exe c:\whatever\mswinsck.ocx

*\System32 or \SysWoW64 on 64 bit Windows.

0
votes

As there was no license for the Winsock, I found a license online. I simply ran this program and voila! The Winsock worked. Thanks!

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=4860&lngWId=1