How to convert string to integer

General discussion on mikroBasic.
Post Reply
Author
Message
AliceInWonderland
Posts: 2
Joined: 28 May 2011 14:14

How to convert string to integer

#1 Post by AliceInWonderland » 01 Aug 2011 10:20

Hello, I haven't find anything like this, so I'm posting you a question. Please help me, I'm desprate.

I'm working with PIC18F452 and RTC Philips PCP8583P.
I'm trying to get date form like this: 2804034 which means that today is 28.04.2034 (the year doesn't matter), to me, most important is the date. Of course I get it on my lcd display, but when I try to convert it to integer the value is 0 (zero). Variable txt is declared as string [6] - like in microbasic help.

The last if loop is just some kind of check for me.

Code: Select all


'    output values to LCD display
   txt[0] = (TimeRead.day div 10) + 48
   txt[1] = (TimeRead.day mod 10) + 48
'   txt[2] = "/"
   txt[2] = (TimeRead.months div 10) + 48
   txt[3] = (TimeRead.months mod 10) + 48
'   txt[5] = "/"
'   txt[6] = "2"
   txt[4] = (TimeRead.year div 100) + 48
   txt[5] = ((TimeRead.year mod 100) div 10) + 48
   txt[6] = (TimeRead.year mod 10)  + 48
'   txt[10] = 0  ' null to terminate the string
   Lcd_Out(1,7,txt)
   txt_int = strtoint (txt)
   
   if txt_int = $00 then
   lcd_out(2,1, "equal")
   delay_ms(2000)
   else
   lcd_out (2,1, "not")
   delay_ms(2000)
   end if


Post Reply

Return to “mikroBasic General”