| |

VerySource

 Forgot password?
 Register
Search
View: 843|Reply: 4

How to implement a clone instance similar to VB.net in vb6?

[Copy link]

1

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-2 02:20:01
| Show all posts |Read mode
'local variable (s) to hold property value (s)
Private mvarA As String 'local copy
 

Public Property Let A (ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.A = 5
    mvarA = vData
End Property


Public Property Get A () As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.A
    A = mvarA
End Property
-------------------------------------------------- ----------
'local variable (s) to hold property value (s)
Private mvarA As String 'local copy
 

Public Property Let A (ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.A = 5
    mvarA = vData
End Property


Public Property Get A () As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.A
    A = mvarA
End Property



byval does not work, how to implement a clone instance of VB.net in vb6?
Reply

Use magic Report

1

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-3-18 12:00:01
| Show all posts
I haven't done VB for a long time, and I feel very uncomfortable looking back.
Reply

Use magic Report

1

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-3-18 12:45:01
| Show all posts
Private Sub Form_Load ()
    Dim testA, testB, testC
    Set testA = New Class1
    '' MsgBox testA.Property (0)
    '' MsgBox CStr (testA.Class)
    testA.A = "A"
     
    Set testB = testA
    testB.A = "B"
    MsgBox testA.A
     
    Set testC = clone (testA)
    testC.A = "C"
    MsgBox testA.A
   '' testA.a =
End Sub

Private Function clone (ByVal instance) As Class1
    Set clone = New Class1
    Set clone = instance
End Function
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-19 12:30:01
| Show all posts
You can only write deep copy code yourself, that is, write one attribute at a time
Reply

Use magic Report

0

Threads

38

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-3-22 10:30:01
| Show all posts
Assign values ​​one by one ~
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list