From: CY on 14 Dec 2009 15:01 On 14 Dec, 19:43, "Rick Rothstein" wrote:> > It's not that simple. One way to compare doubles is to use a function like > > the following, which return the same result as StrComp(): > > > Public Function DblComp(ByRef d1 As Double, ByRef d2 As Double) As Long > >    Dim d As Double > > >    d = d1 - d2 > > >    If Abs(d) < 0.000000001 Then > >        DblComp = 0 ' Equal > >    ElseIf d > 0 Then > >        DblComp = 1 ' d1 > d2 > >    Else > >        DblComp = -1 ' d1 < d2 > >    End If > > End Function > > As a one-liner... > > Public Function DblComp(ByRef d1 As Double, ByRef d2 As Double) As Long >   DblComp = Sgn(d2 - d1) * (Abs(d2 - d1) >= 0.000000001) > End Function > > -- > Rick (MVP - Excel) Oops, can be more than true false... sorry, fingers faster than brain as always. From: Jim Mack on 14 Dec 2009 15:35 CY wrote:>> >> Public Function DblComp(ByRef d1 As Double, ByRef d2 As Double) As >> Long DblComp = Sgn(d2 - d1) * (Abs(d2 - d1) >= 0.000000001) >> End Function >> >> -- >> Rick (MVP - Excel) > > Returning a boolean as a long? > ;) //CY Naw, it's a troolian. (-: From: Rick Rothstein on 14 Dec 2009 15:52 >>> Public Function DblComp(ByRef d1 As Double, ByRef d2 As Double) As>>> Long DblComp = Sgn(d2 - d1) * (Abs(d2 - d1) >= 0.000000001) >>> End Function >>> >>> -- >>> Rick (MVP - Excel) >> >> Returning a boolean as a long? >> ;) //CY > > Naw, it's a troolian. (-: Shouldn't that be spelled Troolean? -- Rick (MVP - Excel) From: Horst Heinrich Dittgens on 15 Dec 2009 11:00 > Further more, you can not safely store arbitrary binary data in a string. Hmm, why not? I think VB's strings can contain nulls without loosing/truncating them when strings are copied. And if they are converted into unicode the should be converted back errorfree, or not? From: Dee Earley on 15 Dec 2009 11:37 On 15/12/2009 16:00, Horst Heinrich Dittgens wrote:>> Further more, you can not safely store arbitrary binary data in a string. > > Hmm, why not? I think VB's strings can contain nulls without > loosing/truncating them when strings are copied. And if they are > converted into unicode the should be converted back errorfree, or not? Yes, nulls characters are fine. You will get problems on any machine that is using a non ANSI character set as "binary" data in a string will, quite rightly, be treated as foreign characters and converted to/from MBCS in their charset to unicode. -- Dee Earley (dee.earley(a)icode.co.uk) i-Catcher Development Team iCode Systems First  |  Prev  |  Next  |  Last Pages: 1 2 3 Prev: Lasso Flipping RevisitedNext: How to get milliseconds ?