Say you have to variables dimmed to the same type of structure. Is there a way to make one equal the other without making each individual element equal each other?
If that sounds confusing, I’ll show an example of what I’m trying to do.
structure A
dim A as integer
dim B as integer
end structure
Dim B as A, C as A
Now, is there a way to simply do a B = C instead of having to do
B.A = C.A
B.B = C.B
I’ve tried doing it myself and looking it up, but my Google Fu is week.
Is this really right? I would have thought the opposite.
I used to do lots of VB back in the pre .Net days, but now I mostly use C#. In C#, structs are value types and classes are reference types. If you equate value types you’re copying the data from one memory location to another, but if you equate reference types you’re making them point to the same memory location. So B = C for classes would mean any change to the data in B also changes the data in C.
I agree it’s probably the other way. If B and C are structures, they would refer to different objects in memory. Changes made to one would not affect the other. If B and C are classes, however, they would refer to the same object after the assignment. Changes made through B would also show up in C.
OK, this is the weirdest thing. I was asking because I tried making a function a structure, and then tried making a variable equal the function with a single command, since going through the elements would mean running the function multiple times.
Example:
structure a
dim b as integer
dim c as string
end structure
dim b as a
private function c () as a
some code goes here
end function
private sub whatever
b = c()
end sub
When I first tried something like this, I got an error, so I posted the question. I try it now, and no error.