MSulchan Darmawan a écrit : > Dear sir, > > I have the following code : > > DIM sRain AS String > DIM iRain AS Integer > DIM iPos AS Integer > DIM iYear AS String > DIM iMonth AS String > > modMain.Connect > hRes = modMain.$Con.Exec("SELECT * FROM table") > > FOR EACH hRes > > iPos = hRes!id > iYear = hRes!yr > iMonth = hRes!mn > sRain = hRes!r1 > > ' PRINT iPos, iYear, iMonth, sRain > iRain = CInt(sRain) > IF iRain > 100 THEN PRINT iPos, iYear, iMonth > > NEXT > > on this line : iRain = CInt(sRain) > I got the type mismatch error. > This is my first try to program on gambas. > So why the error happened ? Any suggestion to fix are welcome.
Because you don't feed CInt() with an integer > FYI, the database connected successfully, hRes!r1 is a string, sRain is > a string, and I'd like to get the integer value of sRain. > The possible value of sRain is : "0", "1", "2", "x", "-", NULL. ^^^^^^^^^^^^^^ Those aren't integer! May be you're trying to convert an ASCCI to its DECIMAL value in the ASCII table: Asc("x") You can't ask a converter to convert "x" or "-" to a number: they are not, so it is not possible. And once for all, NULL is NOT a value: it is... NULL, so it need a separate processing: IsNull("something") SELECT CASE iRain CASE IsNull(iRain) ' Do something CASE IsAscii(iRain) ' Do another thing ... END SELECT JY -- ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user