Home All Groups Group Topic Archive Search About

AND Operator and Currency data type

Author
23 Mar 2006 11:04 AM
Francesco Ranieri
Hi to all,
I need your help to solve this problem!

How to apply AND operator with Currency data type, if its value is larger
then Long limit?

I.E.:
Dim curValue As Currency
Dim lngValue As Long

'This is > Long max limit
curValue = 811635526176
'AND operator manage up to Long variables
lngValue =  curValue AND 65535@

.... and this line gives me an error!!

Thanks in advance
Francesco

P.S.: I'm trying to create a FloatingPoint to Binary function conversion....
with large number!
If you have had any experience with this problem, your help will be
appreciated... thanks

--
____________________________________________
Dott. Francesco Ranieri
Command and Control Systems
Divisione Produzione Difesa e Spazio
Engineering - Ingegneria Informatica S.p.A.
Viale Virgilio, 146
74100 - Taranto - Italy
Tel.\Fax: 099 - 735 08 90
Tel.: 099 - 730 12 66
E-Mail: francesco.rani***@eng.it
Web Site: www.eng.it

Author
23 Mar 2006 2:20 PM
Robert Comer
I'm not an expert on VB, but it looks like we have a couple of problems
here, for one it doesn't look like VB6 can And two Currency or Doubles, I
don't know why that is, but there's also a problem in that you are assigning
your Long to the value of a Currency and that causes an overflow.

Here's a code block that does what you want and is easy to read as well: (If
I understand what you're trying to do!)

Dim curValue As Currency
Dim lngValue As Long

curValue = 811635526176#

If curValue <= 65535@ Then
    lngValue = curValue
End If

The VB pros around here will probably come up with something better...

--
Bob Comer


Show quoteHide quote
"Francesco Ranieri" <francesco.rani***@eng.it> wrote in message
news:%23$EEIkmTGHA.5468@TK2MSFTNGP14.phx.gbl...
> Hi to all,
> I need your help to solve this problem!
>
> How to apply AND operator with Currency data type, if its value is larger
> then Long limit?
>
> I.E.:
> Dim curValue As Currency
> Dim lngValue As Long
>
> 'This is > Long max limit
> curValue = 811635526176
> 'AND operator manage up to Long variables
> lngValue =  curValue AND 65535@
>
> ... and this line gives me an error!!
>
> Thanks in advance
> Francesco
>
> P.S.: I'm trying to create a FloatingPoint to Binary function
> conversion....
> with large number!
> If you have had any experience with this problem, your help will be
> appreciated... thanks
>
> --
> ____________________________________________
> Dott. Francesco Ranieri
> Command and Control Systems
> Divisione Produzione Difesa e Spazio
> Engineering - Ingegneria Informatica S.p.A.
> Viale Virgilio, 146
> 74100 - Taranto - Italy
> Tel.\Fax: 099 - 735 08 90
> Tel.: 099 - 730 12 66
> E-Mail: francesco.rani***@eng.it
> Web Site: www.eng.it
>
>
Author
23 Mar 2006 5:02 PM
Francesco Ranieri
Robert, thank you for your response.
I try to explain myself!

'Suppose the new definitions
Dim curNewTemp As Currency

'Long largest positive value is 2.147.483.647
'Currency largest positive value is 922.337.203.685.477,5807
curValue = 811635526176@

'This operation would response: 18.976
curNewTemp = (curValue AND 65535@)
.... but gives me the overflow error.

The problem the AND operator: its syntax says

Result = Expression1 AND Expression2

where Expression1, Expression2, Result can have values up to Long limit!



Show quoteHide quote
"Robert Comer" <bobco***@mindspring.com> ha scritto nel messaggio
news:%23N2KyToTGHA.5332@tk2msftngp13.phx.gbl...
> I'm not an expert on VB, but it looks like we have a couple of problems
> here, for one it doesn't look like VB6 can And two Currency or Doubles, I
> don't know why that is, but there's also a problem in that you are
assigning
> your Long to the value of a Currency and that causes an overflow.
>
> Here's a code block that does what you want and is easy to read as well:
(If
> I understand what you're trying to do!)
>
> Dim curValue As Currency
> Dim lngValue As Long
>
> curValue = 811635526176#
>
> If curValue <= 65535@ Then
>     lngValue = curValue
> End If
>
> The VB pros around here will probably come up with something better...
>
> --
> Bob Comer
>
>
> "Francesco Ranieri" <francesco.rani***@eng.it> wrote in message
> news:%23$EEIkmTGHA.5468@TK2MSFTNGP14.phx.gbl...
> > Hi to all,
> > I need your help to solve this problem!
> >
> > How to apply AND operator with Currency data type, if its value is
larger
> > then Long limit?
> >
> > I.E.:
> > Dim curValue As Currency
> > Dim lngValue As Long
> >
> > 'This is > Long max limit
> > curValue = 811635526176
> > 'AND operator manage up to Long variables
> > lngValue =  curValue AND 65535@
> >
> > ... and this line gives me an error!!
> >
> > Thanks in advance
> > Francesco
> >
> > P.S.: I'm trying to create a FloatingPoint to Binary function
> > conversion....
> > with large number!
> > If you have had any experience with this problem, your help will be
> > appreciated... thanks
> >
> > --
> > ____________________________________________
> > Dott. Francesco Ranieri
> > Command and Control Systems
> > Divisione Produzione Difesa e Spazio
> > Engineering - Ingegneria Informatica S.p.A.
> > Viale Virgilio, 146
> > 74100 - Taranto - Italy
> > Tel.\Fax: 099 - 735 08 90
> > Tel.: 099 - 730 12 66
> > E-Mail: francesco.rani***@eng.it
> > Web Site: www.eng.it
> >
> >
>
>
Author
23 Mar 2006 6:08 PM
Robert Comer
> 'This operation would response: 18.976
> curNewTemp = (curValue AND 65535@)
> ... but gives me the overflow error.

Okay, I understand now.  I don't really see a way to get it to work yet, but
I'll think about it some more. (or hopefully someone else will come up with
something...)

--
Bob Comer



Show quoteHide quote
"Francesco Ranieri" <francesco.rani***@eng.it> wrote in message
news:OarzbspTGHA.4864@TK2MSFTNGP12.phx.gbl...
> Robert, thank you for your response.
> I try to explain myself!
>
> 'Suppose the new definitions
> Dim curNewTemp As Currency
>
> 'Long largest positive value is 2.147.483.647
> 'Currency largest positive value is 922.337.203.685.477,5807
> curValue = 811635526176@
>
> 'This operation would response: 18.976
> curNewTemp = (curValue AND 65535@)
> ... but gives me the overflow error.
>
> The problem the AND operator: its syntax says
>
> Result = Expression1 AND Expression2
>
> where Expression1, Expression2, Result can have values up to Long limit!
>
>
>
> "Robert Comer" <bobco***@mindspring.com> ha scritto nel messaggio
> news:%23N2KyToTGHA.5332@tk2msftngp13.phx.gbl...
>> I'm not an expert on VB, but it looks like we have a couple of problems
>> here, for one it doesn't look like VB6 can And two Currency or Doubles, I
>> don't know why that is, but there's also a problem in that you are
> assigning
>> your Long to the value of a Currency and that causes an overflow.
>>
>> Here's a code block that does what you want and is easy to read as well:
> (If
>> I understand what you're trying to do!)
>>
>> Dim curValue As Currency
>> Dim lngValue As Long
>>
>> curValue = 811635526176#
>>
>> If curValue <= 65535@ Then
>>     lngValue = curValue
>> End If
>>
>> The VB pros around here will probably come up with something better...
>>
>> --
>> Bob Comer
>>
>>
>> "Francesco Ranieri" <francesco.rani***@eng.it> wrote in message
>> news:%23$EEIkmTGHA.5468@TK2MSFTNGP14.phx.gbl...
>> > Hi to all,
>> > I need your help to solve this problem!
>> >
>> > How to apply AND operator with Currency data type, if its value is
> larger
>> > then Long limit?
>> >
>> > I.E.:
>> > Dim curValue As Currency
>> > Dim lngValue As Long
>> >
>> > 'This is > Long max limit
>> > curValue = 811635526176
>> > 'AND operator manage up to Long variables
>> > lngValue =  curValue AND 65535@
>> >
>> > ... and this line gives me an error!!
>> >
>> > Thanks in advance
>> > Francesco
>> >
>> > P.S.: I'm trying to create a FloatingPoint to Binary function
>> > conversion....
>> > with large number!
>> > If you have had any experience with this problem, your help will be
>> > appreciated... thanks
>> >
>> > --
>> > ____________________________________________
>> > Dott. Francesco Ranieri
>> > Command and Control Systems
>> > Divisione Produzione Difesa e Spazio
>> > Engineering - Ingegneria Informatica S.p.A.
>> > Viale Virgilio, 146
>> > 74100 - Taranto - Italy
>> > Tel.\Fax: 099 - 735 08 90
>> > Tel.: 099 - 730 12 66
>> > E-Mail: francesco.rani***@eng.it
>> > Web Site: www.eng.it
>> >
>> >
>>
>>
>
>
Author
24 Mar 2006 2:47 AM
Bob O`Bob
Robert Comer wrote:
>> 'This operation would response: 18.976
>> curNewTemp = (curValue AND 65535@)
>> ... but gives me the overflow error.
>
> Okay, I understand now.  I don't really see a way to get it to work yet, but
> I'll think about it some more. (or hopefully someone else will come up with
> something...)
>

so far, I've given it only the most rudimentary of testing, but you're
welcome to it:

     Option Explicit

     Public Type CurrAsRecord
         Curr As Currency
     End Type

     Public Type TwoLongAsRecord
         a As Long
         b As Long
     End Type

     Public Function CurrAnd(a As Currency, b As Currency) As Currency
     Dim a1 As CurrAsRecord, a2 As TwoLongAsRecord
     Dim b1 As CurrAsRecord, b2 As TwoLongAsRecord
     Dim c1 As CurrAsRecord, c2 As TwoLongAsRecord
         a1.Curr = a
         b1.Curr = b
         LSet a2 = a1
         LSet b2 = b1
         c2.a = a2.a And b2.a
         c2.b = a2.b And b2.b
         LSet c1 = c2
         CurrAnd = c1.Curr
     End Function




Bob
--
Author
24 Mar 2006 9:10 AM
Schmidt
"Bob O`Bob" <filter***@yahoogroups.com> schrieb im Newsbeitrag
news:%23tTUP1uTGHA.4864@TK2MSFTNGP12.phx.gbl...

> so far, I've given it only the most rudimentary of testing, but you're
> welcome to it:

CurrAnd (7654321@, 1234567@)
gives: 352850,3312
where 1098369 would be the correct result.

You should enhance your function by additional
"Transforming"-Steps regarding the 10000th Fixed-Fraction.

'only Non-Fractional Currencies are allowed
Private Function CurrAnd(ByVal a@, ByVal b@) As Currency
Dim a1 As CurrAsRecord, a2 As TwoLongAsRecord
Dim b1 As CurrAsRecord, b2 As TwoLongAsRecord
Dim c1 As CurrAsRecord, c2 As TwoLongAsRecord
    a1.Curr = a / 10000 '<-transform
    b1.Curr = b / 10000 '<-transform
    LSet a2 = a1
    LSet b2 = b1
    c2.a = a2.a And b2.a
    c2.b = a2.b And b2.b
    LSet c1 = c2
    CurrAnd = c1.Curr * 10000 '<-back-transform
End Function

Olaf
Author
24 Mar 2006 12:27 PM
Francesco Ranieri
Thanks a lot

My goal is to create a general purpose converter from Double (Float32:
dblPRMValue) to Currency (Float32ToBinaryLong) whose memory-representation
is the Binary value of that double, with the approximation wanted
(intPRMScalation)!

Take a look around this code and say to me if you can improve its
efficiency.

'***************START CODE
Private Type recUDCurrencyStructure
   curValue As Currency
End Type

Private Type recUDDoubleLong
   lngHiValue As Long
   lngLoValue As Long
End Type


Private lngPRVPowerOf2List(0 To 31) As Long


Public Function Float32ToBinaryLong(ByVal dblPRMValue As Double, ByVal
intPRMScalation As Integer, Optional intPRMError As Integer) As Currency
Dim intIndex As Integer
Dim lngLoWord As Long, lngHiWord As Long, lngValue As Long
Dim dblFractionValue As Double, dblBinaryFraction As Double
Dim curIntSide As Currency, curFracSide As Currency, curValue As Currency
Dim bytTemp(8) As Byte
Dim recCSResult As recUDCurrencyStructure
Dim recDLHiLoDoubleWord As recUDDoubleLong

   On Error GoTo ErrorHandler

   ' Binary fraction bits are powers of 0.5
   dblBinaryFraction = 0.5

   'Ricava la parte intera
   curIntSide = CCur(Fix(dblPRMValue))

   'Rende scalato il valore, shiftando a sinistra i bit (moltiplicazione)
   curIntSide = curIntSide * ((2@) ^ CCur(intPRMScalation))

   'Ricava la parte frazionaria
   dblFractionValue = Frac(dblPRMValue)

   curFracSide = 0
   For intIndex = (intPRMScalation - 1) To 0 Step -1
      ' If the input number is larger than the fraction bit,
      If dblFractionValue >= dblBinaryFraction Then
         '   add a "1" to the output and
         curFracSide = curFracSide + ((2@) ^ CCur(intIndex))
         '   reduce the input number by the fraction bit's value.
         dblFractionValue = dblFractionValue - dblBinaryFraction
      Else
         '   just tag on a "0" to the end of the output.
      End If

      ' The fraction bit must be cut in half.
      dblBinaryFraction = dblBinaryFraction / 2#
   Next intIndex

   'Sommo le due parti
   curValue = curIntSide + curFracSide

   'Devo prendere i due byte più bassi e copiarli in un long
   lngLoWord = LogicAND(curValue, 65535@)
   lngLoWord = HToNInt32(lngLoWord)

   'Devo prendere i due byte più altri e copiarli in un long
   'Faccio uno shift a destra di 16 bit (65536 = 2 ^ 16)
   lngHiWord = Fix(curValue / 65536@)
   lngHiWord = HToNInt32(lngHiWord)

   Call CopyMemory(bytTemp(0), _
                   lngHiWord, _
                   4)
   Call CopyMemory(bytTemp(4), _
                   lngLoWord, _
                   4)
   bytTemp(5) = bytTemp(3)
   bytTemp(4) = bytTemp(2)
   bytTemp(3) = bytTemp(1)
   bytTemp(2) = bytTemp(0)
   bytTemp(1) = 0
   bytTemp(0) = 0

   Call CopyMemory(lngHiWord, _
                   ByVal VarPtr(bytTemp(0)), _
                   4)
   Call CopyMemory(lngLoWord, _
                   ByVal VarPtr(bytTemp(4)), _
                   4)
   'Little-Endian Parziale
   recDLHiLoDoubleWord.lngHiValue = HToNInt32(lngLoWord)
   recDLHiLoDoubleWord.lngLoValue = HToNInt32(lngHiWord)

   LSet recCSResult = recDLHiLoDoubleWord

   'Ritorna il valore
   Float32ToBinaryLong = recCSResult.curValue * 10000@

   Exit Function

ErrorHandler:
   intPRMError = Err.Number
End Function

Public Function Frac(dblPRMValue As Double) As Double
Dim dblTemp As Double

   dblTemp = dblPRMValue - CLng(dblPRMValue)

   If dblTemp >= 0 Then Frac = dblTemp Else Frac = (1# - dblTemp)
End Function

Private Function LogicAND(ByVal curPRMLeftExpression As Currency, ByVal
curPRMRightExpression As Currency, Optional strPRMError As String) As
Currency
Dim recCSLeftExpression As recUDCurrencyStructure, recCSRightExpression As
recUDCurrencyStructure, recCSResult As recUDCurrencyStructure
Dim recDLLeftExpression As recUDDoubleLong, recDLRightExpression As
recUDDoubleLong, recDLResult As recUDDoubleLong

   On Error GoTo ErrorHandler

   strPRMError = ""

   'Set the left value to structure, after transforming
   recCSLeftExpression.curValue = curPRMLeftExpression / 10000@
   'Set the rigth value to structure, after transforming
   recCSRightExpression.curValue = curPRMRightExpression / 10000@

   'Copy the user-defined values Currency into memory-space of 2 Long
   LSet recDLLeftExpression = recCSLeftExpression
   LSet recDLRightExpression = recCSRightExpression

   'Apply AND operator on Long pairs
   recDLResult.lngHiValue = recDLLeftExpression.lngHiValue And
recDLRightExpression.lngHiValue
   recDLResult.lngLoValue = recDLLeftExpression.lngLoValue And
recDLRightExpression.lngLoValue

   'Copy the 2 Long memory-space into user-defined value Currency
   LSet recCSResult = recDLResult

   'Return the valued, after back-transforming
   LogicAND = recCSResult.curValue * 10000@

   Exit Function

ErrorHandler:
   strPRMError = "[" & Err.Number & "] - " & Err.Description
End Function

Public Sub PowerOf2ListInitialize()
Dim lngIndex As Long

   On Error Resume Next

   For lngIndex = 0& To 31&
      lngPRVPowerOf2List(lngIndex) = 2& ^ lngIndex
   Next lngIndex
End Sub
'***************END CODE

Thanks again
Francesco

Show quoteHide quote
"Schmidt" <s**@online.de> ha scritto nel messaggio
news:uf$D4RyTGHA.5108@TK2MSFTNGP11.phx.gbl...
>
> "Bob O`Bob" <filter***@yahoogroups.com> schrieb im Newsbeitrag
> news:%23tTUP1uTGHA.4864@TK2MSFTNGP12.phx.gbl...
>
> > so far, I've given it only the most rudimentary of testing, but you're
> > welcome to it:
>
> CurrAnd (7654321@, 1234567@)
> gives: 352850,3312
> where 1098369 would be the correct result.
>
> You should enhance your function by additional
> "Transforming"-Steps regarding the 10000th Fixed-Fraction.
>
> 'only Non-Fractional Currencies are allowed
> Private Function CurrAnd(ByVal a@, ByVal b@) As Currency
> Dim a1 As CurrAsRecord, a2 As TwoLongAsRecord
> Dim b1 As CurrAsRecord, b2 As TwoLongAsRecord
> Dim c1 As CurrAsRecord, c2 As TwoLongAsRecord
>     a1.Curr = a / 10000 '<-transform
>     b1.Curr = b / 10000 '<-transform
>     LSet a2 = a1
>     LSet b2 = b1
>     c2.a = a2.a And b2.a
>     c2.b = a2.b And b2.b
>     LSet c1 = c2
>     CurrAnd = c1.Curr * 10000 '<-back-transform
> End Function
>
> Olaf
>
>
Author
24 Mar 2006 3:34 PM
Jim Mack
Francesco Ranieri wrote:
> Thanks a lot
>
> My goal is to create a general purpose converter from Double (Float32:
> dblPRMValue) to Currency (Float32ToBinaryLong) whose
> memory-representation is the Binary value of that double, with the
> approximation wanted (intPRMScalation)!


I'm having some difficulty understanding what exactly you're trying to accomplish.

Could you give us a few examples of input and output values that demonstrate what problem you're trying to solve?

What you're doing seems overly complicated.

--
        Jim
Author
4 Apr 2006 9:02 AM
Tony Proctor
Me too Jim.

If Francesco were doing something like this in C then I would assume he was
looking at the internal bit structure of the Currency datum, without regard
to the numeric significance of those bits. For instance, if the datum had
been floating point then he might have been trying to isolate the mantissa
and exponent.

Assuming that to be true then the following code demonstrates a simple (and
efficient) way of accessing the bits. The sample calls also illustrate that
the Currency data type is representing a fixed-point decimal, even though
it's still a two's-complement format. For Currency values of 0, +1, and -1,
the Hex repesresentation of the bit patterns is:

    00000000 00000000
    00000000 00002710
    FFFFFFFF FFFFD8F0

        Tony Proctor

'=========== Form1.frm ===========
Private Declare Sub GetMem8 Lib "msvbvm60" (ByVal Addr As Long, ByVal
RetAddr As Long)

Private Type Long2
    lLO As Long
    lHO As Long
End Type

Private Function Hex8(lVal As Long) As String
    Hex8 = Right$("0000000" & Hex(lVal), 8)
End Function

Private Sub Form_Load()
Dim cuLargeVal As Currency
Dim tLong2 As Long2

    cuLargeVal = 0
    GetMem8 VarPtr(cuLargeVal), VarPtr(tLong2)
    Debug.Print Hex8(tLong2.lHO) & " " & Hex8(tLong2.lLO)

    cuLargeVal = 1
    GetMem8 VarPtr(cuLargeVal), VarPtr(tLong2)
    Debug.Print Hex8(tLong2.lHO) & " " & Hex8(tLong2.lLO)

    cuLargeVal = -1
    GetMem8 VarPtr(cuLargeVal), VarPtr(tLong2)
    Debug.Print Hex8(tLong2.lHO) & " " & Hex8(tLong2.lLO)
End Sub
'==============================

"Jim Mack" <jmack@mdxi.nospam.com> wrote in message
news:OgOy$h1TGHA.4976@TK2MSFTNGP11.phx.gbl...
Francesco Ranieri wrote:
> Thanks a lot
>
> My goal is to create a general purpose converter from Double (Float32:
> dblPRMValue) to Currency (Float32ToBinaryLong) whose
> memory-representation is the Binary value of that double, with the
> approximation wanted (intPRMScalation)!


I'm having some difficulty understanding what exactly you're trying to
accomplish.

Could you give us a few examples of input and output values that demonstrate
what problem you're trying to solve?

What you're doing seems overly complicated.

--
        Jim
Author
24 Mar 2006 6:35 PM
Dan Barclay
I was about to suggest you contact Jim Mack (champion bit twiddler), but I
see he has joined the thread already!

He didn't mention it, but his web site is www.microdexterity.com

Later,
Dan


Show quoteHide quote
"Francesco Ranieri" <francesco.rani***@eng.it> wrote in message
news:u9VME3zTGHA.4608@tk2msftngp13.phx.gbl...
> Thanks a lot
>
> My goal is to create a general purpose converter from Double (Float32:
> dblPRMValue) to Currency (Float32ToBinaryLong) whose memory-representation
> is the Binary value of that double, with the approximation wanted
> (intPRMScalation)!
>
> Take a look around this code and say to me if you can improve its
> efficiency.
>
> '***************START CODE
> Private Type recUDCurrencyStructure
>   curValue As Currency
> End Type
>
> Private Type recUDDoubleLong
>   lngHiValue As Long
>   lngLoValue As Long
> End Type
>
>
> Private lngPRVPowerOf2List(0 To 31) As Long
>
>
> Public Function Float32ToBinaryLong(ByVal dblPRMValue As Double, ByVal
> intPRMScalation As Integer, Optional intPRMError As Integer) As Currency
> Dim intIndex As Integer
> Dim lngLoWord As Long, lngHiWord As Long, lngValue As Long
> Dim dblFractionValue As Double, dblBinaryFraction As Double
> Dim curIntSide As Currency, curFracSide As Currency, curValue As Currency
> Dim bytTemp(8) As Byte
> Dim recCSResult As recUDCurrencyStructure
> Dim recDLHiLoDoubleWord As recUDDoubleLong
>
>   On Error GoTo ErrorHandler
>
>   ' Binary fraction bits are powers of 0.5
>   dblBinaryFraction = 0.5
>
>   'Ricava la parte intera
>   curIntSide = CCur(Fix(dblPRMValue))
>
>   'Rende scalato il valore, shiftando a sinistra i bit (moltiplicazione)
>   curIntSide = curIntSide * ((2@) ^ CCur(intPRMScalation))
>
>   'Ricava la parte frazionaria
>   dblFractionValue = Frac(dblPRMValue)
>
>   curFracSide = 0
>   For intIndex = (intPRMScalation - 1) To 0 Step -1
>      ' If the input number is larger than the fraction bit,
>      If dblFractionValue >= dblBinaryFraction Then
>         '   add a "1" to the output and
>         curFracSide = curFracSide + ((2@) ^ CCur(intIndex))
>         '   reduce the input number by the fraction bit's value.
>         dblFractionValue = dblFractionValue - dblBinaryFraction
>      Else
>         '   just tag on a "0" to the end of the output.
>      End If
>
>      ' The fraction bit must be cut in half.
>      dblBinaryFraction = dblBinaryFraction / 2#
>   Next intIndex
>
>   'Sommo le due parti
>   curValue = curIntSide + curFracSide
>
>   'Devo prendere i due byte più bassi e copiarli in un long
>   lngLoWord = LogicAND(curValue, 65535@)
>   lngLoWord = HToNInt32(lngLoWord)
>
>   'Devo prendere i due byte più altri e copiarli in un long
>   'Faccio uno shift a destra di 16 bit (65536 = 2 ^ 16)
>   lngHiWord = Fix(curValue / 65536@)
>   lngHiWord = HToNInt32(lngHiWord)
>
>   Call CopyMemory(bytTemp(0), _
>                   lngHiWord, _
>                   4)
>   Call CopyMemory(bytTemp(4), _
>                   lngLoWord, _
>                   4)
>   bytTemp(5) = bytTemp(3)
>   bytTemp(4) = bytTemp(2)
>   bytTemp(3) = bytTemp(1)
>   bytTemp(2) = bytTemp(0)
>   bytTemp(1) = 0
>   bytTemp(0) = 0
>
>   Call CopyMemory(lngHiWord, _
>                   ByVal VarPtr(bytTemp(0)), _
>                   4)
>   Call CopyMemory(lngLoWord, _
>                   ByVal VarPtr(bytTemp(4)), _
>                   4)
>   'Little-Endian Parziale
>   recDLHiLoDoubleWord.lngHiValue = HToNInt32(lngLoWord)
>   recDLHiLoDoubleWord.lngLoValue = HToNInt32(lngHiWord)
>
>   LSet recCSResult = recDLHiLoDoubleWord
>
>   'Ritorna il valore
>   Float32ToBinaryLong = recCSResult.curValue * 10000@
>
>   Exit Function
>
> ErrorHandler:
>   intPRMError = Err.Number
> End Function
>
> Public Function Frac(dblPRMValue As Double) As Double
> Dim dblTemp As Double
>
>   dblTemp = dblPRMValue - CLng(dblPRMValue)
>
>   If dblTemp >= 0 Then Frac = dblTemp Else Frac = (1# - dblTemp)
> End Function
>
> Private Function LogicAND(ByVal curPRMLeftExpression As Currency, ByVal
> curPRMRightExpression As Currency, Optional strPRMError As String) As
> Currency
> Dim recCSLeftExpression As recUDCurrencyStructure, recCSRightExpression As
> recUDCurrencyStructure, recCSResult As recUDCurrencyStructure
> Dim recDLLeftExpression As recUDDoubleLong, recDLRightExpression As
> recUDDoubleLong, recDLResult As recUDDoubleLong
>
>   On Error GoTo ErrorHandler
>
>   strPRMError = ""
>
>   'Set the left value to structure, after transforming
>   recCSLeftExpression.curValue = curPRMLeftExpression / 10000@
>   'Set the rigth value to structure, after transforming
>   recCSRightExpression.curValue = curPRMRightExpression / 10000@
>
>   'Copy the user-defined values Currency into memory-space of 2 Long
>   LSet recDLLeftExpression = recCSLeftExpression
>   LSet recDLRightExpression = recCSRightExpression
>
>   'Apply AND operator on Long pairs
>   recDLResult.lngHiValue = recDLLeftExpression.lngHiValue And
> recDLRightExpression.lngHiValue
>   recDLResult.lngLoValue = recDLLeftExpression.lngLoValue And
> recDLRightExpression.lngLoValue
>
>   'Copy the 2 Long memory-space into user-defined value Currency
>   LSet recCSResult = recDLResult
>
>   'Return the valued, after back-transforming
>   LogicAND = recCSResult.curValue * 10000@
>
>   Exit Function
>
> ErrorHandler:
>   strPRMError = "[" & Err.Number & "] - " & Err.Description
> End Function
>
> Public Sub PowerOf2ListInitialize()
> Dim lngIndex As Long
>
>   On Error Resume Next
>
>   For lngIndex = 0& To 31&
>      lngPRVPowerOf2List(lngIndex) = 2& ^ lngIndex
>   Next lngIndex
> End Sub
> '***************END CODE
>
> Thanks again
> Francesco
>
> "Schmidt" <s**@online.de> ha scritto nel messaggio
> news:uf$D4RyTGHA.5108@TK2MSFTNGP11.phx.gbl...
>>
>> "Bob O`Bob" <filter***@yahoogroups.com> schrieb im Newsbeitrag
>> news:%23tTUP1uTGHA.4864@TK2MSFTNGP12.phx.gbl...
>>
>> > so far, I've given it only the most rudimentary of testing, but you're
>> > welcome to it:
>>
>> CurrAnd (7654321@, 1234567@)
>> gives: 352850,3312
>> where 1098369 would be the correct result.
>>
>> You should enhance your function by additional
>> "Transforming"-Steps regarding the 10000th Fixed-Fraction.
>>
>> 'only Non-Fractional Currencies are allowed
>> Private Function CurrAnd(ByVal a@, ByVal b@) As Currency
>> Dim a1 As CurrAsRecord, a2 As TwoLongAsRecord
>> Dim b1 As CurrAsRecord, b2 As TwoLongAsRecord
>> Dim c1 As CurrAsRecord, c2 As TwoLongAsRecord
>>     a1.Curr = a / 10000 '<-transform
>>     b1.Curr = b / 10000 '<-transform
>>     LSet a2 = a1
>>     LSet b2 = b1
>>     c2.a = a2.a And b2.a
>>     c2.b = a2.b And b2.b
>>     LSet c1 = c2
>>     CurrAnd = c1.Curr * 10000 '<-back-transform
>> End Function
>>
>> Olaf
>>
>>
>
>
Author
25 Mar 2006 6:22 AM
Bob O`Bob
Schmidt wrote:
> "Bob O`Bob" <filter***@yahoogroups.com> schrieb im Newsbeitrag
> news:%23tTUP1uTGHA.4864@TK2MSFTNGP12.phx.gbl...
>
>> so far, I've given it only the most rudimentary of testing, but you're
>> welcome to it:
>
> CurrAnd (7654321@, 1234567@)
> gives: 352850,3312
> where 1098369 would be the correct result.

That's a matter of opinion.

Mine differs.

What you're proposing is a substantially different operation.
Mine is an actual bitwise AND, while yours involves a weird (IMO)
normalization-like operation, which clearly fails in many cases
when the highest few bits get used.

One simply has to understand that "7654321@" means 7654321.0000

CurrAnd (765.4321@, 123.4567@) gives 109.8369, which is IMO far preferable.




    Bob
Author
25 Mar 2006 9:19 AM
Rick Rothstein
Show quote Hide quote
>>> so far, I've given it only the most rudimentary of testing, but you're
>>> welcome to it:
>>
>> CurrAnd (7654321@, 1234567@)
>> gives: 352850,3312
>> where 1098369 would be the correct result.
>
> That's a matter of opinion.
>
> Mine differs.
>
> What you're proposing is a substantially different operation.
> Mine is an actual bitwise AND, while yours involves a weird (IMO)
> normalization-like operation, which clearly fails in many cases
> when the highest few bits get used.
>
> One simply has to understand that "7654321@" means 7654321.0000
>
> CurrAnd (765.4321@, 123.4567@) gives 109.8369, which is IMO far
> preferable.

I have to admit Bob, but I am a little confused by your answer here. If we
understand 7654321@ means 7654321.0000, then where did the 765.4321 come
from? Why are we looking at values in the decimal portion? Unless I am
completely missing something here, I too think that

     7654321 And 1234567 = 1098369

no matter what appropriately large enough data type is housing the values.

Rick
Author
25 Mar 2006 8:51 PM
Bob O`Bob
Rick Rothstein wrote:
Show quoteHide quote
>>>> so far, I've given it only the most rudimentary of testing, but you're
>>>> welcome to it:
>>> CurrAnd (7654321@, 1234567@)
>>> gives: 352850,3312
>>> where 1098369 would be the correct result.
>> That's a matter of opinion.
>>
>> Mine differs.
>>
>> What you're proposing is a substantially different operation.
>> Mine is an actual bitwise AND, while yours involves a weird (IMO)
>> normalization-like operation, which clearly fails in many cases
>> when the highest few bits get used.
>>
>> One simply has to understand that "7654321@" means 7654321.0000
>>
>> CurrAnd (765.4321@, 123.4567@) gives 109.8369, which is IMO far
>> preferable.
>
> I have to admit Bob, but I am a little confused by your answer here. If we
> understand 7654321@ means 7654321.0000, then where did the 765.4321 come
> from? Why are we looking at values in the decimal portion? Unless I am
> completely missing something here, I too think that
>
>      7654321 And 1234567 = 1098369
>
> no matter what appropriately large enough data type is housing the values.

I understand your confusion, but it's based on the /assumption/ of a
specific binary<=>decimal representation.  It's a pretty reasonable assumption,
correct almost all of the time, BUT the currency data type simply uses
a /different/ b-to-d.

In a currency variable, the binary representation of the number 2 looks *exactly*
like the binary representation of 2000 does in a long, 11111010000.
It is NOT just one bit.  So in /that/ b-to-d representation, it does not make
sense to use 2 as a flag.  Instead, it makes sense to use 0.0002

Logical operations like AND, OR, and so on are defined as operating on bits.
The "numbers" represented by those bits are immaterial.

It is mathematically *correct* to say that (2@ AND 1@) = 0.0960@

It's all a matter of whether the user of the function wants a bitwise operation
using the currency representation, or a bitwise operation using the more common
representation of most integer datatypes.



    Bob
--
Author
25 Mar 2006 9:00 PM
Bob O`Bob
Bob O`Bob wrote:

> In a currency variable, the binary representation of the number 2 looks
> *exactly*
> like the binary representation of 2000 does in a long, 11111010000.

Whoops!  Scaling error.

Please ignore the specific examples I posted, they're
probably all wrong, but the concepts should still be clear.



    ".0Bob"
--
Author
25 Mar 2006 9:01 PM
Rick Rothstein
Show quote Hide quote
>>>>> so far, I've given it only the most rudimentary of testing, but you're
>>>>> welcome to it:
>>>> CurrAnd (7654321@, 1234567@)
>>>> gives: 352850,3312
>>>> where 1098369 would be the correct result.
>>> That's a matter of opinion.
>>>
>>> Mine differs.
>>>
>>> What you're proposing is a substantially different operation.
>>> Mine is an actual bitwise AND, while yours involves a weird (IMO)
>>> normalization-like operation, which clearly fails in many cases
>>> when the highest few bits get used.
>>>
>>> One simply has to understand that "7654321@" means 7654321.0000
>>>
>>> CurrAnd (765.4321@, 123.4567@) gives 109.8369, which is IMO far
>>> preferable.
>>
>> I have to admit Bob, but I am a little confused by your answer here. If
>> we understand 7654321@ means 7654321.0000, then where did the 765.4321
>> come from? Why are we looking at values in the decimal portion? Unless I
>> am completely missing something here, I too think that
>>
>>      7654321 And 1234567 = 1098369
>>
>> no matter what appropriately large enough data type is housing the
>> values.
>
> I understand your confusion, but it's based on the /assumption/ of a
> specific binary<=>decimal representation.  It's a pretty reasonable
> assumption,
> correct almost all of the time, BUT the currency data type simply uses
> a /different/ b-to-d.
>
> In a currency variable, the binary representation of the number 2 looks
> *exactly*
> like the binary representation of 2000 does in a long, 11111010000.
> It is NOT just one bit.  So in /that/ b-to-d representation, it does not
> make
> sense to use 2 as a flag.  Instead, it makes sense to use 0.0002
>
> Logical operations like AND, OR, and so on are defined as operating on
> bits.
> The "numbers" represented by those bits are immaterial.
>
> It is mathematically *correct* to say that (2@ AND 1@) = 0.0960@
>
> It's all a matter of whether the user of the function wants a bitwise
> operation
> using the currency representation, or a bitwise operation using the more
> common
> representation of most integer datatypes.

Okay, I see what you are saying now. It just seems my "computer upbringing"
has conditioned me to be more comfortable with the fully whole number
approach to binary operations. And yes, I understand the scaling bit (no pun
intended) of the Currency data type, but still...<g>

Rick
Author
25 Mar 2006 5:20 PM
Schmidt
"Bob O`Bob" <filter***@yahoogroups.com> schrieb im Newsbeitrag
news:e3DB6R9TGHA.4956@TK2MSFTNGP09.phx.gbl...

> That's a matter of opinion.
Yep, I was/am aware of that.

> What you're proposing is a substantially different operation.
> Mine is an actual bitwise AND, while yours involves a weird (IMO)
> normalization-like operation, which clearly fails in many cases
> when the highest few bits get used.
Of course. (if used with Operands greater than 922337203685477 -
sitting in (and above) the 2^50Bit-Range.
But it is a "Long-and-Integer-Type-Compatible" enhancement to
VBs And-Operator, working secure up to 49Bits.

My point of view is, if someone has written his own Class, to handle
large Files (>2GB) for example, then he's using probably the VB-
Currency-Type for the Class's Methods/Params.
I'm sure, in the most implementations, the 4Digit fractional part of the
Currency-Type is "out-calculated", so that a:
cLargeFile.Seek 1
can be used, to position the filepointer at the first byte.

Of course, the other point of view also has its benefits.
cLargeFile.Seek 0.0001
is looking somewhat "unusual", but the implementation under the
hood of the class-interface is much simpler, dividing/multiplying with
10000 is not necessary, the Filerange would be higher than with the
philosophy above (even if 900TeraByte seams enough too).
For people who think in this way, your posted AND-Function would
be the preffered choice.

It's not a question of "better" or "worse" - it depends on the situation,
wich Function suits better.

I've thought, the OP was preferring a version without taking the
fractional part into aspect.

But since his last posting I'm very confused on what he really wants
to achieve (many unnecessary and weird operations in his code).

Olaf
Author
25 Mar 2006 6:07 PM
Rick Rothstein
Show quote Hide quote
>> What you're proposing is a substantially different operation.
>> Mine is an actual bitwise AND, while yours involves a weird (IMO)
>> normalization-like operation, which clearly fails in many cases
>> when the highest few bits get used.
>
> Of course. (if used with Operands greater than 922337203685477 -
> sitting in (and above) the 2^50Bit-Range.
> But it is a "Long-and-Integer-Type-Compatible" enhancement to
> VBs And-Operator, working secure up to 49Bits.
>
> I've thought, the OP was preferring a version without taking the
> fractional part into aspect.
>
> But since his last posting I'm very confused on what he really wants
> to achieve (many unnecessary and weird operations in his code).

I'm also confused about whether the OP wanted fractional values to be taken
into account (personally, doing so with an AND operation seems somewhat
strange to me); however, if one is interested in handling larger
(non-fractional) numbers than a Currency can hold, we can always resort to
binary representation and do the work there. Below are three functions that
will do that... the programmer only calls BigAND directly (it calls the
other two functions as necessary). BigAND (and each of the functions it
calls) can handle numbers that will fit into a Decimal data type (which are
96-bit values).

Rick

Function BigAND(Value1 As Variant, Value2 As Variant) As Variant
  Dim X As Long
  Dim V1 As String
  Dim V2 As String
  Dim Ans As String
  If Value1 > Value2 Then
    V1 = Dec2Bin(Value1)
    V2 = Dec2Bin(Value2, Len(V1))
  Else
    V2 = Dec2Bin(Value2)
    V1 = Dec2Bin(Value1, Len(V2))
  End If
  Ans = String$(Len(V1), "0")
  For X = 1 To Len(V1)
    If Mid$(V1, X, 1) = "1" And Mid$(V2, X, 1) = "1" Then
      Mid$(Ans, X) = "1"
    End If
  Next
  BigAND = Bin2Dec(Ans)
End Function

Function Dec2Bin(ByVal DecimalIn As Variant, _
              Optional NumberOfBits As Variant = 0) As String
    Dec2Bin = ""
    DecimalIn = Int(CDec(DecimalIn))
    Do While DecimalIn <> 0
        Dec2Bin = Trim$(Str$(DecimalIn - _
                  2 * Int(DecimalIn / 2))) & Dec2Bin
        DecimalIn = Int(DecimalIn / 2)
    Loop
    If NumberOfBits > 0 Then
       If Len(Dec2Bin) > NumberOfBits Then
          Dec2Bin = "Error - Number exceeds specified bit size"
       Else
          Dec2Bin = Right$(String$(NumberOfBits, _
                    "0") & Dec2Bin, NumberOfBits)
       End If
    End If
End Function

Function Bin2Dec(BinaryString As String) As Variant
    Dim X As Integer
    Const TwoToThe48 As Variant = 281474976710656#
    For X = 0 To Len(BinaryString) - 1
      If X > 48 Then
        Bin2Dec = CDec(Bin2Dec) + Val(Mid(BinaryString, _
                  Len(BinaryString) - X, 1)) * _
                  TwoToThe48 * CDec(2 ^ (X - 48))
      Else
        Bin2Dec = CDec(Bin2Dec) + Val(Mid(BinaryString, _
                  Len(BinaryString) - X, 1)) * CDec(2 ^ X)
      End If
    Next
End Function
Author
24 Mar 2006 5:41 PM
Robert Comer
That's pretty much what I thought of last night too.

--
Bob Comer



Show quoteHide quote
"Bob O`Bob" <filter***@yahoogroups.com> wrote in message
news:%23tTUP1uTGHA.4864@TK2MSFTNGP12.phx.gbl...
> Robert Comer wrote:
>>> 'This operation would response: 18.976
>>> curNewTemp = (curValue AND 65535@)
>>> ... but gives me the overflow error.
>>
>> Okay, I understand now.  I don't really see a way to get it to work yet,
>> but I'll think about it some more. (or hopefully someone else will come
>> up with something...)
>>
>
> so far, I've given it only the most rudimentary of testing, but you're
> welcome to it:
>
>     Option Explicit
>
>     Public Type CurrAsRecord
>         Curr As Currency
>     End Type
>
>     Public Type TwoLongAsRecord
>         a As Long
>         b As Long
>     End Type
>
>     Public Function CurrAnd(a As Currency, b As Currency) As Currency
>     Dim a1 As CurrAsRecord, a2 As TwoLongAsRecord
>     Dim b1 As CurrAsRecord, b2 As TwoLongAsRecord
>     Dim c1 As CurrAsRecord, c2 As TwoLongAsRecord
>         a1.Curr = a
>         b1.Curr = b
>         LSet a2 = a1
>         LSet b2 = b1
>         c2.a = a2.a And b2.a
>         c2.b = a2.b And b2.b
>         LSet c1 = c2
>         CurrAnd = c1.Curr
>     End Function
>
>
>
>
> Bob
> --