Tuesday, May 22nd 2012, 12:53am UTC+2

You are not logged in.

  • Login
  • Register

hru

Beginner

1

Tuesday, May 24th 2011, 2:02pm

Val function incompatible with VB6

Hi,

Unexpected behaviour in Jabaco compared to VB6:

The Val function is returning 0.0 if the argument is a decimal number (has a dot in the string)

Cheers

A1880

Intermediate

Posts: 500

Location: Hanover, Germany

Occupation: Software Engineer

2

Wednesday, May 25th 2011, 4:52pm

Val() is a Jabaco framework function implemented in "Conversion.java".

You are right, it mostly/always returns 0.0
There seems to be a bug in the framework implementation.
I've tried to trace it down. It seems to be in VBVariant.doubleValue(), but I'm not sure.

For the time being, you could use CDbl() to circumvent the problem.

Add a new Module to your project with the following content:

Jabaco Source

1
2
3
4
5
Option Explicit

Public Function Val(expression As String)
   Val = CDbl(expression)
End Function


This re-defines Val() and seems to work, at least for me ...

Greetings

A1880

A1880

Intermediate

Posts: 500

Location: Hanover, Germany

Occupation: Software Engineer

3

Thursday, May 26th 2011, 9:14am

I've done the following experiment:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Option Explicit

Public Sub Command1_Click()
   t "1,234"
   t "1.234"
   t "1,234.56"
End Sub

Private Sub t(s As String)
   Dim a As New VBVariant(s) 
   Dim x As Double = a.doubleValue()
   
   Debug.Print s & " = " & x
End Sub


The debugging output:

Source code

1
2
3
4
...
1,234 = 0.0
1.234 = 1.234
1,234.56 = 0.0


My suspicion is that Val() constructs a string using the local decimal separator (in Germany the comma).
This string is then converted to double by using CDbl(). However, CDbl() is calling VBVariant.doubleValue().
And there every string with comma separator is mapped to 0.0

Any volunteers to fix this in the framework?

Greetings

A1880

Rate this thread
WoltLab Burning Board