Results 1 to 9 of 9

Thread: working with types , Copy data of type inside other variable with different type

  1. #1

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    709

    working with types , Copy data of type inside other variable with different type

    Hi

    I would like working variables like below

    Code:
    Private Type AA
      AA01 As String * 2
      AA02 As String * 2
    End Type
    Private Type BB
       BB01 As String * 4
    End Type
    Private Sub Form_Load()
      Dim K As AA
      Dim L As BB
      
      K.AA01 = "11"
      K.AA02 = "22"
     
      'Here I want put the data of K inside L
      'Is there some way to do it ?
    End Sub

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,746

    Re: working with types , Copy data of type inside other variable with different type

    Code:
      L.BB01 = K.AA01 & K.AA02
      Debug.Print L.BB01

  3. #3

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    709

    Re: working with types , Copy data of type inside other variable with different type

    Thank you, But Is there some way to do put the put the data directly, no field by field

    Like
    L = K?

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: working with types , Copy data of type inside other variable with different type

    Look up the LSet statement.

  5. #5
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,746

    Re: working with types , Copy data of type inside other variable with different type

    Yes ofcourse, forgot all about the LSet statement!

  6. #6
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: working with types , Copy data of type inside other variable with different type

    My preference would be to write a function before using LSet.
    Code:
    Option Explicit
    
    Private Type AA
      AA01 As String * 2
      AA02 As String * 2
    End Type
    
    Private Type BB
      BB01 As String * 4
    End Type
    
    Private Sub Form_Load()
      Dim K As AA
      Dim L As BB
      
      K.AA01 = "11"
      K.AA02 = "22"
     
      L = ToBB(K)
     
      MsgBox L.BB01
    End Sub
    
    Private Function ToBB(A As AA) As BB
      ToBB.BB01 = A.AA01 & A.AA02
    End Function
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  7. #7
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: working with types , Copy data of type inside other variable with different type

    If somebody is playing with UDTs for anything but API call "struct" stand-ins they are probably lost anyway.

  8. #8
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,746

    Re: working with types , Copy data of type inside other variable with different type

    Do you prefer classes above UDTs in all situations?

  9. #9
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: working with types , Copy data of type inside other variable with different type

    For me there is no one size fits all answer.
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

Tags for this Thread

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