Checking for valid fieldname

Checking for valid fieldname

Postby Marc Vanzegbroeck » Thu Nov 22, 2007 6:56 am

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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Postby Otto » Thu Nov 22, 2007 7:35 am

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)
User avatar
Otto
 
Posts: 6327
Joined: Fri Oct 07, 2005 7:07 pm

Postby demont frank » Thu Nov 22, 2007 8:08 am

Using charonly :

Code: Select all  Expand view
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)
demont frank
 
Posts: 167
Joined: Thu Mar 22, 2007 11:24 am

Postby Marc Vanzegbroeck » Thu Nov 22, 2007 11:06 am

Otto, Frank,

Thanks for the info. I will try it.

Marc
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], Willi Quintana and 116 guests