|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Type comparisonHi
Is there a easy way to compare "Type" structure. Assignment is straight forward, but comparation does not pass the compiler. Thanks "Phil H" <phung1***@hotmail.com> wrote How about a little example code that you'd like to work? I'm not exactly> Is there a easy way to compare "Type" structure. Assignment is straight > forward, but comparation does not pass the compiler. sure what you mean by comparing "Type" structure.... LFS "Phil H" <phung1***@hotmail.com> wrote in message You can't. You have to compare the members. If there is more than one member news:emor4eY%23JHA.1492@TK2MSFTNGP03.phx.gbl... > Hi > > Is there a easy way to compare "Type" structure. Assignment is straight > forward, but comparation does not pass the compiler. to compare, make a function for it. Usually I would make a function that would return the same values as StrComp() function. Putting everything in a class makes the code easy to maintain and manage. Example: Public Type TStudent FullName As String GPA As Double End Type Friend Function CompGPA(st1 As TStudent, st2 As TStudent) As Long If st1.GPA > st2.GPA Then ' Greater than CompGPA = 1 ElseIf st1.GPA < st2.GPA Then ' Less than CompGPA = -1 Else ' Equal CompGPA = 0 End If End Function Thanks. That's what I am doing now.
I thought there is some 'memory' compare I can use. You see I don't really care what is different. If I know the struc is different, I know I have to update the db. Class is nice, but it's the 'type' that really keep relevant data togehter. Show quoteHide quote "Nobody" <nob***@nobody.com> wrote in message news:evkb57Y%23JHA.5780@TK2MSFTNGP03.phx.gbl... > "Phil H" <phung1***@hotmail.com> wrote in message > news:emor4eY%23JHA.1492@TK2MSFTNGP03.phx.gbl... >> Hi >> >> Is there a easy way to compare "Type" structure. Assignment is straight >> forward, but comparation does not pass the compiler. > > You can't. You have to compare the members. If there is more than one > member to compare, make a function for it. Usually I would make a function > that would return the same values as StrComp() function. Putting > everything in a class makes the code easy to maintain and manage. Example: > > Public Type TStudent > FullName As String > GPA As Double > End Type > > Friend Function CompGPA(st1 As TStudent, st2 As TStudent) As Long > If st1.GPA > st2.GPA Then > ' Greater than > CompGPA = 1 > ElseIf st1.GPA < st2.GPA Then > ' Less than > CompGPA = -1 > Else > ' Equal > CompGPA = 0 > End If > End Function > > Phil Hunt wrote:
> Thanks. That's what I am doing now. The "problem" is that the structure only contains pointers to some datatypes. For > I thought there is some 'memory' compare I can use. You see I don't really > care what is different. If I know the struc is different, I know I have to > update the db. Class is nice, but it's the 'type' that really keep relevant > data togehter. example, if you compare to "equal" structures, you may find they're "different" because they're each pointing to different copies of the "same" String. "Phil Hunt" <a**@aaa.com> wrote in message But a Class is a 'type'.news:eltrSVb%23JHA.2872@TK2MSFTNGP05.phx.gbl... > Thanks. That's what I am doing now. > I thought there is some 'memory' compare I can use. You see I don't really > care what is different. If I know the struc is different, I know I have to > update the db. Class is nice, but it's the 'type' that really keep relevant > data togehter. > -ralph The 'type' I am talking about is more like a struc, or group level in the
old days. Show quoteHide quote "Ralph" <nt_consultin***@yahoo.com> wrote in message news:%23fjbVOc%23JHA.4648@TK2MSFTNGP02.phx.gbl... > > "Phil Hunt" <a**@aaa.com> wrote in message > news:eltrSVb%23JHA.2872@TK2MSFTNGP05.phx.gbl... >> Thanks. That's what I am doing now. >> I thought there is some 'memory' compare I can use. You see I don't >> really >> care what is different. If I know the struc is different, I know I have >> to >> update the db. Class is nice, but it's the 'type' that really keep > relevant >> data togehter. >> > > But a Class is a 'type'. > > -ralph > > "Phil Hunt" <a**@aaa.com> wrote in message lolnews:uEle6kc%23JHA.2824@TK2MSFTNGP03.phx.gbl... > The 'type' I am talking about is more like a struc, or group level in the > old days. > .... and your point is? [But let us not quibble. I'm only suggesting that if you sit back and view what it is you are trying to do with this collection/group of "relevant data" - I believe you will discover you have an object or data type. Objects are defined by 'classes'. Objects know about their 'relevant data', they can play and morph and compare and generally do useful stuff. Structs are simple, dull memory blocks that need to be carried around and minded by external processes.] The reason I asked in the first place is: it is so easy to assign to UDT,
but it won't let you compare. Case closed. Show quoteHide quote "Ralph" <nt_consultin***@yahoo.com> wrote in message news:OLyCQgd%23JHA.3544@TK2MSFTNGP04.phx.gbl... > > "Phil Hunt" <a**@aaa.com> wrote in message > news:uEle6kc%23JHA.2824@TK2MSFTNGP03.phx.gbl... >> The 'type' I am talking about is more like a struc, or group level in the >> old days. >> > > lol > > ... and your point is? > > [But let us not quibble. I'm only suggesting that if you sit back and view > what it is you are trying to do with this collection/group of "relevant > data" - I believe you will discover you have an object or data type. > Objects > are defined by 'classes'. Objects know about their 'relevant data', they > can > play and morph and compare and generally do useful stuff. Structs are > simple, dull memory blocks that need to be carried around and minded by > external processes.] > > > > |
|||||||||||||||||||||||