i have to object of the same type, but when i set a property of one of them, the VB puts the property on both.
Anybody knows why??
Thank you,
Guilherme Costa
Printable View
i have to object of the same type, but when i set a property of one of them, the VB puts the property on both.
Anybody knows why??
Thank you,
Guilherme Costa
Sounds like a they both reference the same object. Post some code or do a search for the difference between reference-type variables and value-type variables.
VB Code:
Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call horario_ponta_ativo = False ReDim gerador(2) End Sub Dim gerador() As ModbusOCX.Modbus_OCX Private Sub Supervisório_Terra_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load For i As Integer = 0 To 1 gerador(i) = New ModbusOCX.Modbus_OCX Next gerador(0).config_Porta = ModbusOCX.Modbus_OCX.ValoresPorta.COM3 gerador(0).abre_porta() gerador(1).config_Porta = ModbusOCX.Modbus_OCX.ValoresPorta.COM4 gerador(1).abre_porta() relogio.Start() gerador_ponta.Start() End Sub
i hope that this could help you to help me!!!
Guilherme Costa
Huh I'm not sure you set them both to new objects in your loop so it should be fine. So you are saying that gerador(0).config_Porta equals ModbusOCX.Modbus_OCX.ValoresPorta.COM4 instead of COM3? Is that how are you testing that they are set to the samething? This could be an issue with this particular object? Is it derived from an OCX or ActiveX object (hence the OCX in the name)?
yeah, this project i have upgraded from VB6, but i use it in my application like gerador1 and gerador2 now, and it worked fine!
maybe it get lost because i was trying to use as array or something!
Thanks for your help!!
Guilherme Costa