Results 1 to 5 of 5

Thread: two different objects, VB use just one

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Location
    Porto Alegre, RS
    Posts
    210

    two different objects, VB use just one

    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

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Location
    Porto Alegre, RS
    Posts
    210
    VB Code:
    1. Public Sub New()
    2.         MyBase.New()
    3.  
    4.         'This call is required by the Windows Form Designer.
    5.         InitializeComponent()
    6.  
    7.         'Add any initialization after the InitializeComponent() call
    8.         horario_ponta_ativo = False
    9.         ReDim gerador(2)
    10.     End Sub
    11.  
    12. Dim gerador() As ModbusOCX.Modbus_OCX
    13.  
    14. Private Sub Supervisório_Terra_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    15.  
    16.         For i As Integer = 0 To 1
    17.             gerador(i) = New ModbusOCX.Modbus_OCX
    18.         Next
    19.  
    20.         gerador(0).config_Porta = ModbusOCX.Modbus_OCX.ValoresPorta.COM3
    21.         gerador(0).abre_porta()
    22.  
    23.         gerador(1).config_Porta = ModbusOCX.Modbus_OCX.ValoresPorta.COM4
    24.         gerador(1).abre_porta()
    25.  
    26.         relogio.Start()
    27.         gerador_ponta.Start()
    28.  
    29.     End Sub

    i hope that this could help you to help me!!!

    Guilherme Costa

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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)?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Location
    Porto Alegre, RS
    Posts
    210
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width