Author Topic: Howto change text to number  (Read 11838 times)

jurg1505

  • Newbie
  • *
  • Posts: 10
  • I'm a llama!
    • View Profile
Howto change text to number
« on: May 10, 2015, 11:46:27 PM »
How to change the month into a number ?
See attachement

10 MAY 2015 22:02:21 CEST
I have to change MAY to 05
IF VAL(MID$ (A$,  4, 3)) = ??

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Howto change text to number
« Reply #1 on: May 11, 2015, 08:15:01 PM »
Try something like the following. You can put this into a custom function and everytime you get the calendar string assign it to D$ and then call this function:

D$ = "10 MAY 2015 22:02:21 CEST"

IF LEN(D$) = 25  ' response with standard format of 25 characters
  SETLCD 1,1,D$
  DATE[3] = VAL(MID$(D$,1,2))
  C$ = MID$(D$,4,3)
  IF STRCMP(C$,"JAN")=0 DATE[2] = 1
  ELSEIF STRCMP(C$,"FEB")=0 DATE[2] = 2
  ELSEIF STRCMP(C$,"MAR")=0 DATE[2] = 3
  ELSEIF STRCMP(C$,"APR")=0 DATE[2] = 4
  ELSEIF STRCMP(C$,"MAY")=0 DATE[2] = 5
  ELSEIF STRCMP(C$,"JUN")=0 DATE[2] = 6
  ELSEIF STRCMP(C$,"JUL")=0 DATE[2] = 7
  ELSEIF STRCMP(C$,"AUG")=0 DATE[2] = 8
  ELSEIF STRCMP(C$,"SEP")=0 DATE[2] = 9
  ELSEIF STRCMP(C$,"OCT")=0 DATE[2] = 10
  ELSEIF STRCMP(C$,"NOV")=0 DATE[2] = 11
  ELSEIF STRCMP(C$,"DEC")=0 DATE[2] = 12
  ENDIF  
 
  DATE[1] = VAL(MID$(D$,8,4))   ' Get the Year

  TIME[1] = VAL(MID$(D$,13,2))   '
  TIME[2] = VAL(MID$(D$,16,2))
  TIME[3] = VAL(MID$(D$,19,2))
  SETLCD 4,1, "RTC Updated"
ELSE
  SETLCD 4,1, "Fail to update RTC"
ENDIF

ENDIF
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

jurg1505

  • Newbie
  • *
  • Posts: 10
  • I'm a llama!
    • View Profile
Re:Howto change text to number
« Reply #2 on: May 12, 2015, 11:40:00 PM »
Thanks for your quick replay.

WORKS