CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2000
    Location
    CA, USA
    Posts
    88

    Passing a Private UDT to a Public Function contained within another form

    Hello all,

    I would like to know how would I pass a private UDT delcared within form1 to a public member of another form? I have been playing around with the CopyMemory and VarPtr funtions, but I can only get it to work paritially. Below is a part of the code..

    Globals.Bas


    option Explicit

    Const CAPITEXTLEN = 25

    Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst as Any, _
    pSrc as Any, _
    byval ByteLen as Long)

    public Type MY_STRUCTURE
    Param1 as string * CAPITEXTLEN
    Param2 as string * CAPITEXTLEN
    Param3 as string * CAPITEXTLEN
    Param4 as Long
    Param5 as Long
    End Type






    frmForm1.frm


    option Explicit

    private MyVariable as MY_STRUCTURE

    private Sub cmdPassData_Click()

    Dim ptrMyVariable as Long

    With MyVariable
    .Param1 = "String1"
    .Param2 = "String2"
    .Param3 = "String3"
    .Param4 = 12
    .Param5 = 18
    End With

    ' CopyMemory ptrMyVariable, MyVariable, 4
    frmForm2.mEntryPoint VarPtr(MyVariable)

    End Sub





    frmForm2.frm

    option Explicit

    private MyVariabl2 as MY_STRUCTURE

    public Sub mEntryPoint(byref ptrPassedVariable as Long)

    CopyMemory MyVariabl2, byval ptrPassedVariable, 4

    With MyVariabl2
    Text1.Text = .Param1
    Text2.Text = .Param2
    Text3.Text = .Param3
    Text4.Text = .Param4
    Text5.Text = .Param5
    End With

    me.Show vbModal

    End Sub




    I am not sure what I am doing wrong... I think I have the right idea, but I may be going about it the hard way. Any thoughts? Thanks

    Mark H.


  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Passing a Private UDT to a Public Function contained within another form

    To pass UDT I never used copymemory. I just added a Class creatable(instancing property of class), and declared there a public UDT. Then I declared my private udt everywhere I needed in my form, but
    private thisUDt as myClass.MyUdt
    Then I can simply pass it in function and sub, or even store it in a variant variable.
    Hope this help

    Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Passing a Private UDT to a Public Function contained within another form

    Have a look here:
    http://codeguru.com/cgi-bin/bbs/wt/s...age=&view=&sb=

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Apr 2000
    Posts
    737

    Re: Passing a Private UDT to a Public Function contained within another form

    just make the UDT as public in .bas module file


    HTH

    cksiow
    http://vblib.virtualave.net - share our codes

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

Featured