bug with stringgrid ?

In this category you can exchange your programming questions and solutions.
Post Reply
azarus
Posts: 5
Joined: Tue Nov 08, 2005 3:00 pm

bug with stringgrid ?

Post: # 491Post azarus
Fri Aug 14, 2009 9:02 pm

i give a example:
y1=380-val(grid.cell(j,1))*uv    has a wrong result (uv and y1 are double,j is byte)
y1=380-(val(grid.cell(j,1))*uv)  has the good result
With a string variable at the place of grid.cell(j,1) the result is good in the first case

fred
Posts: 54
Joined: Thu Apr 23, 2009 10:08 am

bug with stringgrid ?

Post: # 492Post fred
Sat Aug 15, 2009 9:41 am

Did some tests in a little program:

dim uv as double
dim y1 as double
dim j as byte

dim grid as Stringgrid

j = 1
grid.Cell(1,1)="10"

uv=2

y1=380-val("10")*uv                  `380 - 10 * 2
showmessage Str$(y1)               ` 360 <- ok

y1=380 - val(grid.cell(j,1)) * uv  ` 380 - 10 * 2
showmessage Str$(y1)               ` 740 <- wrong result, is evaluated as (380 - 10) * 2

y1=(380-val(grid.cell(j,1)))*uv    ` (380 - 10)  *  2
showmessage Str$(y1)               ` 740 <- ok

y1=380-(val(grid.cell(j,1))*uv)    ` 380 - (10 * 2)
showmessage Str$(y1)               ` 360 <- ok


I don`t think the grid has a bug but the expression is not properly evaluated and has the bug.
Perhaps thats the reason i always use () so i don`t have to think i which order an expression is being evaluated.

Post Reply