[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stange things


I think IIF evaluates both options, before assigning the value to the
iDigitVal. Thus the byte is overflown (it cannot take negative values).
Use integer type, or do not use IIF.


Jussi

On Wed, Sep 11, 2024 at 5:04 PM Fabien Bodard <gambas.fr@xxxxxxxxx> wrote:

> Hi,
>
>
> with this function :
>
> Public Sub Base34Decoder(Value As String) As Long
>
>   Dim lResult As Long
>   Dim iDigitVal, i As Integer
>   Dim aNum As Byte[] = Byte[].FromString(UCase(Value)).Reverse()
>
>   For i = 0 To aNum.Max
>     iDigitVal = IIf(aNum[i] >= Asc("2") And aNum[i] <= Asc("9"), aNum[i] -
> 50, aNum[i] - 57)
>     lResult += iDigitVal * (34 ^ i)
>   Next
>
>   Return lResult
>
> End
>
> Public sub Main()
>   Print Utils.Base34Decoder("3BG73G")
> end
>
> I get "Dépassement de Capacité" on the line <iDigitVal = IIf(aNum[i] >=
> Asc("2") And aNum[i] <= Asc("9"), aNum[i] - 50, aNum[i] - 57)>
>
>
> Why ???
>
> Thank you for your help :-)
>
>
>
> --
> Fabien Bodard
>

References:
Stange thingsFabien Bodard <gambas.fr@xxxxxxxxx>