[Gambas-user] Maybe a bug with val functiun

ron ronstk at ...239...
Tue Nov 11 00:44:22 CET 2003


> >
> > May be if you try RETURN (Cstr("")) instead of RETURN ("")
> >
> > I found a same problem when i fill a array with "" (emty strings)
> > arr=3D["","","",""]   'all entries are 'Null' 
> > must corected to
> > arr=3D[Cstr(""),"","",""] all entries are now gb.String  (v0.65)
> >
> > Gambas sees a variable preset with "" as Null in relational compares as
> >
> > anemtystring=3D""
> > IF anemptystring =3D "" THEN
> >  print "this is empty"
> > ELSE
> >  print "this is NULL"
> > ENDIF
>
> In Gambas, NULL and "" must be exactly the same thing. If you can make a=20
> difference, THIS is a bug !

I think this is the case and so it's true but there can be an exception.

>
> I will check all comparison functions so that they behave as I wanted !
>
> Regards,
>
> =2D-=20
> Benoit Minisini
> mailto:gambas at ...1...
>

Hi Benoit,
It is a mess with those html/=3D stuff.

I need a array preset with "" like arr=["","","",""] and this was not posible.
The array arr is a String[] and will add later to a Variant[] array.

As in the help about arrays you say the first element determines the type of 
the following entries.
In the case of the first element was a "" wich is equal as Null my array was 
all with Null. I asume all entries are then gb.Null
Changing the first element to use CStr("") resolves the problem and all 
elements in the array are default type of gb.String with a content of Null.
In the program there are string operations with these cells and they didn't 
accept it at the time i used 0.63 and giving me typecast errors.  

Putting something in the first string instead of CStr("") did work too.
Note:
  I just removed the work around and tried again.
  In v0.71 i get "program returned 1' and aborts for the arr=["","",""] case. 
  Not given a clue where it aborts. See below at end.

----
Sample program for test in v071:

PUBLIC SUB Main()
'for exmpl1
  DIM sTxt AS String 

'for exmpl2
  DIM avR AS Variant[]  ' rows for the table
  DIM asC AS String[]  'columns for the table
  avR=NEW Variant[]

'exmpl1
  sTxt=""
  IF sTxt = "" THEN
    PRINT "is null"
  ELSE
    PRINT "isempty"
  ENDIF
'This follows your rule and should be Ok. 

'exmple2
  PRINT "++++++++++"

'  asC=["","",""]   ' abort program with mesage "program returned value 1" 
' the above line did pass in 0.65 and sets all entries to Null
  asC=["p","",""] 'this goes ok
  avR.add ( asC, 0 )

  asC=[CStr(""),"",""]
  avR.add ( asC, 1 )

  asC=[CStr(""),NULL,NULL]
  avR.add ( asC, 2 )

  show( avR[0] )
  show( avR[1] )
  show( avR[2] )

END

PUBLIC SUB show (arr AS Variant)
  DIM x AS Integer
  PRINT "-----------------"
  FOR x=0 TO 2
    PRINT x ,"#" & arr[x] & "#", TypeOf(arr[x]) ' returns '15' for last 2
  NEXT
END

Resulting in 
'8=gb.String, 10= gb.Variant, 15=gb.Null, 16=gb.Object

-----------------
0	#p#	8
1	##	15
2	##	15
-----------------
0	##	15
1	##	15
2	##	15
-----------------
0	##	15
1	##	15
2	##	15

Second proof it is true.

For the Val() function I did a test as follows in the console:
? val("2e3") is 2000
? val("&h20") is 32
? 2^4 is 16
? typeof(2^4) is 6 gb.Float
? typeof("2^4") is 8 gb.String
? val("2^4") is Null

Is this correct, how to give a number to power as i.e. 2^4 ?
If &H as prefix for hexadecimal radix works maybe this should work too.

? typeof( cstr("") ) is Null should be gb.String as I asked for with CStr() ?

? typeof(clng(8))
Type mismatch: wanted Long, got Integer instead
? clng(8)
Type mismatch: wanted Long, got Integer instead
So Long is known here

  DIM lNum AS Long
  DIM iNum AS Integer
  iNum=8
  lNum= CLng(iNum)
Type mismatch: wanted Long, got Integer instead

Oops, looking in the help CLng is gone? 
The Editor knows about it and adjust the case. 
In the console Long is also known.
I had to use Float but the DIM gives also no error.
DIM var as Long and CLng exist in editor 

For the note above here the code from real program

PUBLIC arrGrid Variant[]

PUBLIC SUB Grid_AddCol()
  DIM argdat AS  String[]
  DIM y AS Integer
 y=0 '*** here I set the breakpoint for stepping
  argdat =["","","","","","","",""]  '*** I get 'program returned 1' mesage
'  argdat =[CStr(""),"","","","","","",""] ' *** this is my work around

  FOR y = argdat.count TO rowhead.count-1      'range can be 8...16 rows
    argdat.add("") ' add row cell    *** is now acepted in 0.71, not in 0.65?
'    argdat.add(CStr("")) ' make row data *** workaround
  NEXT

  argdat[enVIS]="Yes" 
  arrGrid.Add(argdat) 'add to column variant[] 
END

And here is the exception maybe.

In both cases "" and CStr("") the TypeOf() are gb.Null but setting the argdat 
does not acept the first one. As far I remember in 0.65 there was a error 
mesage and now in 0.71 the 'return 1' mesage.

My Gambas version during this test was 0.71

Hope this give some support back about it,
grts Ron (wikiron)














More information about the User mailing list