| auteur : Romain Puyfoulhoux | Ajoutez la librairie Microsoft Scripting Runtime. Le fichier correspondant se nomme scrrun.dll
|
lien : FAQ VB
|
| auteurs : Romain Puyfoulhoux, Lou Pitchoun | La lecture d'un fichier XML se fait à l'aide d'un parseur. Dans les références du projet, ajoutez Microsoft XML.
Voici un exemple qui affiche dans la fenêtre de débogage la liste des balises contenues dans un document xml. Private Sub BrowseChildNodes (root_node As IXMLDOMNode)
Dim i As Long
For i = 0 To root_node. childNodes . length - 1
If root_node. childNodes . Item (i). nodeType < > 3 Then Debug. Print root_node. childNodes . Item (i). baseName
BrowseChildNodes root_node. childNodes (i)
Next
End Sub
Private Sub BrowseXMLDocument (ByVal filename As String )
Dim xmlDoc As DOMDocument, root As IXMLDOMElement
Set xmlDoc = New DOMDocument
xmlDoc. async = False
xmlDoc. Load filename
Set root = xmlDoc. documentElement
If Not root Is Nothing Then
Debug. Print root. baseName
BrowseChildNodes root
End If
End Sub
|
Appelez simplement la procédure BrowseXMLDocument en passant en paramètre le chemin du fichier. Cette procédure ouvre
le fichier puis appelle la procédure BrowseChildNodes qui parcoure l'ensemble des balises de façon récursive.
------------------------------------------------------------------------------------------------
Pour modifier une valeur : root_node. childNodes . Item (i). Text = " Lou Pitchoun "
|
Pour sauvegarder : xmlDoc. Save " Chemin + nom fichier "
|
Ce code donne le nom de la balise : Debug. Print root_node. childNodes . Item (i). baseName
|
|
lien : FAQ VB
lien : Repousser les limites d'Access - récupérer un fil RSS
lien : Visual Basic 6.0 et le format XML
|
| auteur : Maxence HUBICHE | On a souvent parlé des images en disant qu'il valait mieux éviter de les stocker dans la base de données. Ceci est valide pour tous les objets OLE.
Un OS (Système d'Exploitation) est prévu pour gérer les fichiers. Les stocker à l'extérieur de la base de données pour ne stocker dans la base que le chemin d'accès donnera souvent de bien meilleurs résultats.
Exemple d'utilisation du chemin stocké grâce à une API : Private Declare Function ShellExecute Lib " shell32.dll " Alias " ShellExecuteA " _
(ByVal hWnd As Long, ByVal lpOperation As String , ByVal lpFile As String , ByVal lpParameters As String , _
ByVal lpDirectory As String , ByVal nShowCmd As Long) As Long
|
puis dans le code on l'appelle ainsi : ShellExecute Me. hWnd , vbNullString , CheminduFichier, " " , vbNullString , 1
|
|
lien : Comment ouvrir un fichier HTML, Word, PDF ou autre en utilisant l'exécutable associé ?
lien : Que faire quand l'API ShellExecute ne fonctionne pas ?
|
| auteur : Maxence HUBICHE |
Lire un fichier :
Function LireFichier (ByVal sPath As String ) As String ()
Dim fso As FileSystemObject
Dim fFile As File
Dim ts As TextStream
Dim result As String
Set fso = CreateObject (" Scripting.FileSystemObject " )
Set fFile = fso. GetFile (sPath)
Set ts = fFile. OpenAsTextStream (ForReading)
result = ts. ReadAll
LireFichier = Split (result, vbCrLf )
ts. Close
Set ts = Nothing
Set fFile = Nothing
Set fso = Nothing
End Function
|
Créer un fichier :
Function CreerFichier (ByVal sPath As String )
Dim fso As FileSystemObject
Set fso = CreateObject (" Scripting.FileSystemObject " )
fso. CreateTextFile sPath
Set fso = Nothing
End Function
|
Ajouter une ligne :
Function AjoutLigneDansFichier (ByVal sPath As String , ByVal sTexte As String )
Dim fso As FileSystemObject
Dim fFile As File
Dim ts As TextStream
Set fso = CreateObject (" Scripting.FileSystemObject " )
Set fFile = fso. GetFile (sPath)
Set ts = fFile. OpenAsTextStream (ForAppending)
ts. WriteLine sTexte
ts. Close
Set ts = Nothing
Set fFile = Nothing
Set fso = Nothing
End Function
|
|
lien : Comment créer et écrire dans un fichier texte ?
|
| auteur : Cafeine |
C'est faisable grâce aux RegExp, pensez à ajouter la référence Microsoft Regular Expressions 5.5 :
Function CountMatches (ByVal strFic As String , ByVal strSearch As String ) As Long
Dim reg As VBScript_RegExp_55. RegExp
Dim Matches As VBScript_RegExp_55. MatchCollection
Dim Fic As Integer
Dim strBuff As String * 20000
Dim strBorder As String
Set reg = New VBScript_RegExp_55. RegExp
reg. Global = True
reg. IgnoreCase = True
reg. Multiline = True
reg. Pattern = " ( " & strSearch & " ) "
Reset
Fic = FreeFile
Open strFic For Binary Access Read As #Fic
Do While Not EOF (Fic)
strBorder = Right (strBuff, Len (strSearch) - 1 )
Get #Fic, , strBuff
strBorder = strBorder & strBuff
Set Matches = reg. Execute (strBorder)
CountMatches = CountMatches + Matches. Count
Loop
Close #Fic
Set reg = Nothing
Set Matches = Nothing
End Function
|
Exemple :
?countmatches (" c:\temp\long.txt " ," " )
7500
|
|
lien : Les Expressions Rationnelles et Access par la pratique
|
| auteurs : Cafeine, Tofalu |
Pour obtenir le chemin relatif d'un fichier par rapport à un répertoire, vous pouvez utiliser la fonction suivante :
Function GetRelativePath (ByVal strPath As String , Optional ByVal strPathCurrent As String )
Dim tmpCurr () As String
Dim tmpP () As String
Dim i As Integer
Dim iIndex As Integer
If strPathCurrent = " " Then strPathCurrent = CurrentProject. Path
If Right (strPathCurrent, 1 ) = " \ " Then strPathCurrent = Left (strPathCurrent, Len (strPathCurrent) - 1 )
If Left (strPath, 1 ) = Left (strPathCurrent, 1 ) Then
tmpP = VBA. Split (strPath, " \ " )
tmpCurr = VBA. Split (strPathCurrent, " \ " )
For iIndex = 0 To IIf (UBound (tmpP) > UBound (tmpCurr), UBound (tmpCurr), UBound (tmpP))
If tmpP (iIndex) < > tmpCurr (iIndex) Then
Exit For
Else
i = iIndex
End If
Next iIndex
If i = UBound (tmpCurr) Then
For iIndex = i + 1 To UBound (tmpP)
GetRelativePath = GetRelativePath & tmpP (iIndex) & " \ "
Next iIndex
GetRelativePath = Left (GetRelativePath, Len (GetRelativePath) - 1 )
Else
For iIndex = 1 To UBound (tmpCurr) - i
GetRelativePath = GetRelativePath & " ..\ "
Next iIndex
For iIndex = i + 1 To UBound (tmpP)
GetRelativePath = GetRelativePath & tmpP (iIndex) & " \ "
Next iIndex
GetRelativePath = Left (GetRelativePath, Len (GetRelativePath) - 1 )
End If
Else
GetRelativePath = strPath
End If
End Function
|
Le premier paramètre correspond au chemin du fichier ou du dossier, le second correspond au chemin courant.
Exemple :
?getrelativepath (" c:\toto\tata\test.xls " ," c:\tintin " )
. . \ toto\ tata\ test. xls
?getrelativepath (" c:\toto\tata\test.xls " ," c:\toto\tata " )
\ test. xls
|
|
| auteur : vodiem | Cette fonction permet de tester l'existence d'un fichier, elle renvoie True si le fichier existe : Function existeFileFSO (ByVal fichier As String ) As Boolean
Set fs = CreateObject (" Scripting.FileSystemObject " )
existeFileFSO = fs. FileExists (fichier)
Set fs = Nothing
End Function
|
Autre méthode en passant par les APIs :
Declare Function SearchPath Lib " kernel32 " Alias " SearchPathA " (ByVal lpPath As String , ByVal lpFileName As String , ByVal lpExtension As String , ByVal nBufferLength As Long, ByVal lpBuffer As String , ByVal lpFilePart As String ) As Long
Function existeFileSearchPath (ByVal chemin, fichier As String ) As Boolean
Dim ResultFileName As String
Dim pFilePart As Long
existeFileSearchPath = SearchPath (chemin, fichier, vbNullString , 1 , ResultFileName, pFilePart) > 0
End Function
|
|
lien : http://warin.developpez.com/access/fichiers/
|
Consultez les autres F.A.Q's
Les sources présentés sur cette pages sont libre de droits,
et vous pouvez les utiliser à votre convenance. Par contre cette page de présentation de ces sources constitue une oeuvre intellectuelle protégée par les droits d'auteurs.
Copyright ©2004
Developpez LLC. Tout droits réservés Developpez LLC.
Aucune reproduction, même partielle, ne peut être faite de ce site et de
l'ensemble de son contenu : textes, documents et images sans l'autorisation
expresse de Developpez LLC. Sinon vous encourez selon la loi jusqu'à 3 ans
de prison et jusqu'à 300 000 E de dommages et intérets.
Cette page est déposée à la SACD.
|