LSet of VB6 into VB.Net

sups123

Member
Joined
Mar 10, 2006
Messages
14
Programming Experience
1-3
Hello

I have two user defined datatypes and i want to copy one UDT to another.
For this in vb6 its LSet UDT1 = UDT2.
But this dosent work in vb.net as LSet in vb.net has some other meaning.
Please if anybody can tell me how can i acheive this in vb.net.

Thanks
sups123
 
Mmmm, this looks a lot like a post i read else where......

Lset as you get more and more into .net you will find gives the opportunity to perform operations that are not type safe, and one of the biggest points about prgramming with .net is that you shouldn't play fast an loose with pieces of memory in that way. Still Lset may still be supported in the Microsoft.VisualBasic Namespace or the Microsoft.Visualbasic.Compatibility Namespace. However there will no doubt be a much better .net way to do this.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconprogrammingelementschangesinvb7.asp
 
If you want to copy one structure to another you should either implement the IClonable interface and provide an implementation for the Clone method or else create a copy constructor, which takes an existing instance as a parameter and copies all the public properties to the new instance.
 
Hmmm... I just realised that you're talking about two different types. If they are not the same type then copying one to the other is a REALLY dodgy operation. If there is some logical relationship between the two, like Integer and Double, then you should define a conversion. Otherwsie what you're doing is previously stated, really dodgy.
 
Hello

My vb code goes like this
======================================
Private Type typByteArray
B(1 To 4) As Byte
End Type
Private Type typFloat
f As Single
End Type
Dim tB As typByteArray
Dim tF As typFloat
'some code here....
.........
LSet tF = tB '''' this dosen't work
======================================
and this i want to convert into vb.net. but Lset of vb6 does not work in the same manner as in vb.net so i was not able to do the same.
Please if any one can help me in solving the above problem as soon as possible.
 
my vb.net code the above is a follows
=======================================
Structure typByteArray
Public B() As Byte
End Structure

Structure typFloat
Public f As Single
End Structure

Dim tB As typByteArray
ReDim tB.B(4)
Dim tF As typFloat

' some code here..........
...........
Lset(tf.f.ToString,tb.f.Tostring) ''' this wont work as in vb6

''another way i tried is

tF.f = Convert.ToSingle(tB.b) .............
is this the right way for what i want to acheive like vb6?

Please reply me for this too.

thanks
sups123
 
Nor should that work. Like I said, copying a series of Byte objects into the memory that is supposed to contain Single objects is REALLY dodgy. VB.NET is a very type-safe language and allowing you to do something like that could compromise the integrity of the stired data. A Byte is is 8 bits and a Single is 32. Where's the guarantee that you're copying 4 Bytes for each Single? Like I said, if there is a logical relationship between the two types then you should define a conversion. If you want to convert four Bytes into one Single then you can use the bit-shifting operators >> and <<.
 
converting four Bytes into one Single how can i use the bit-shifting operators >> and <<.
Can u just brief me about this and how exactly this is used?

thanks
sups123
 
tF.f = System.BitConverter.ToSingle(tB.B, 0)

is this the right way and will it give the desired output for the previous example i had posted
 
Back
Top