Page 1 of 1

Checking for valid fieldname

Posted: Thu Nov 22, 2007 6:56 am
by Marc Vanzegbroeck
Hi,

My program import data from an other system. These files include a parameter and info about this parameter. When I import it I create a fieldname with the same name as the parameter from the imported file. Till now I had no problem but a client wanted to import a file that contains wrong info. My program wanted to create a fieldname containing '*' and other strange characters. Is there a way to chech if a fieldname is correct?

Thanks,
Marc

Posted: Thu Nov 22, 2007 7:35 am
by Otto
Maybe this func could help you.
Regards,
Otto

func f_isOK(cTest)
local cReturn:=""
local i:=0

FOR I := 1 TO len(cTestl)

IF ASC(substr(cTest,i,1)) >= 33 .and. ASC(substr(cTest,i,1)) <= 90
cReturn:=cReturn+substr(cTest,i,1)

elseif ASC(substr(cTest,i,1)) >= 97 .and. ASC(substr(cTest,i,1)) <= 122
cReturn:=cReturn+substr(cTest,i,1)

elseif ...

ENDIF
NEXT
return (cReturn)

Posted: Thu Nov 22, 2007 8:08 am
by demont frank
Using charonly :

Code: Select all

LOCAL CharAllowed := "" , i , lOk
FOR i := 65 TO 90
  CharAllowed += CHR(i) + CHR(i+32)
NEXT
// Are numbers allowed in fieldnames ? If yes add the range 48-57
lOk := ( LEN(CharOnly(CharAllowed,cString) == LEN(cString) )
RETURN lOk   // Or CharOnly(CharAllowed,cString) 

Posted: Thu Nov 22, 2007 11:06 am
by Marc Vanzegbroeck
Otto, Frank,

Thanks for the info. I will try it.

Marc