Illegal characters in filename

HMG en Español

Moderator: Rathinagiri

edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Illegal characters in filename

Post by edk »

serge_girard wrote: Thu Nov 18, 2021 8:12 am Thanks Jimmy,

That's the solution ! Because of the nature of my program the 'USE' is in a loop from a DIR function
and my USE is this construction:

Code: Select all

IF lOpenMode                                              
    if cNew = 'NEW'                                       
       USE ( cDatabase ) EXCLUSIVE  NEW ALIAS cALIAS      
    ELSE                                                  
       USE ( cDatabase ) EXCLUSIVE ALIAS cALIAS           
    ENDIF                                                 
ELSE                                                      
    if cNew = 'NEW'                                       
       USE ( cDatabase ) SHARED NEW ALIAS cALIAS          
    ELSE                                                  
       USE ( cDatabase ) SHARED ALIAS cALIAS              
    ENDIF                                                 
ENDIF                                                     
                                                          
IF !NETERR()                                              
   RETURN ( TRUE )                          
ENDIF                                                   
This now works perfect! Thanks again!

Serge
In case you want to open several DBFs with an unusual name in different areas this might be helpful:

Code: Select all

#include "hmg.ch"

Function Main

Local cDBF := "6. März - Wöchentliche Backup-Datei.dbf", i

IF !FILE(cDBF)

	DBCREATE(cDBF, { {'ID','N',10,0} , {'NAME','C',30,0}, {'FLAG','C',3,0} } )
	USE (cDBF) ALIAS (ValidAliasName (cDBF))
	FOR i := 1 TO 2000
		APPEND BLANK
		REPLACE id WITH i
		REPLACE name WITH "Name #" + AllTrim(Str(i))
		REPLACE flag WITH IF (i % 3 = 0, "C", IF ( i % 2 = 0, "B", "A" ) )
	NEXT i
	
	CLOSE
	
ENDIF
	
USE (cDBF) ALIAS (ValidAliasName (cDBF)) SHARED
	
EDIT EXTENDED

Return

********************************************************
Function ValidAliasName ( cAliasName )
Local i, cValidAliasName := ""
cAliasName := hb_FNameName( cAliasName )
cAliasName := IF ( .NOT. IsAlpha( cAliasName ), "X", "") + cAliasName		//alias must begins alpha
FOR i := 1 TO Len ( cAliasName )
	cValidAliasName += IF ( Lower(SubStr( cAliasName, i, 1)) $ "abcdefghijklmnopqrstuvwxyz1234567890_", SubStr( cAliasName, i, 1), "_" )   
NEXT i
RETURN cValidAliasName
*********************************************
User avatar
serge_girard
Posts: 3342
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Illegal characters in filename

Post by serge_girard »

Thanks Edward and Jimme,

Great solutions!

Serge
There's nothing you can do that can't be done...
Post Reply