Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Access > Contribuez
Contribuez Access : Vos contributions. Postez ici vos codes sources, conseils, astuces et autres propositions. Ce forum n'est pas un forum technique mais destiné aux contributions pour www.developpez.com
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 11/08/2006, 15h50   #1
Expert Confirmé Sénior

 
Avatar de cafeine
 
Inscription : juin 2002
Messages : 3 882
Détails du profil
Informations forums :
Inscription : juin 2002
Messages : 3 882
Points : 4 500
Points : 4 500
Par défaut [FAQ] Obtenir un chemin relatif

Hello, voici une petite fonction pour obtenir un chemin relatif.

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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

' par défaut on considère que c'est relatif par rapport au chemin courant de la base


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
    ' on recherche la partie commune aux deux chemins


    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
        ' c'est un sous répertoire


        For iIndex = i + 1 To UBound(tmpP)
            GetRelativePath = GetRelativePath & tmpP(iIndex) & "\"
        Next iIndex
        GetRelativePath = Left(GetRelativePath, Len(GetRelativePath) - 1)
    Else
        ' il faut remonter de UBound(tmpCurr) - i


        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
    ' deux lecteurs différents


    GetRelativePath = strPath
End If

End Function
Pour l'utiliser, un exemple
Code :
1
2
?getrelativepath("c:\toto\tata\prout.xls","c:\tintin")
..\toto\tata\prout.xls
__________________
Ne mettez pas "Problème" dans vos titres, par définition derrière toute question se cache un problème

Développez une application de gestion des comptes bancaires dans Access de A à Z
Déjà 12 tutoriels, le dernier en date : Comment faire un TextBox auto-extensible dans un formulaire ?


cafeine est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/08/2006, 09h55   #2
Membre Expert
 
Inscription : avril 2006
Messages : 1 318
Détails du profil
Informations forums :
Inscription : avril 2006
Messages : 1 318
Points : 1 586
Points : 1 586
Bonjour,

je me demande si la fonction <IsMissing> ne fonctionne qu'avec un type variant et non avec un type simple type string ?

Amicalement,

Philippe
philben est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/08/2006, 20h59   #3
Rédacteur

 
Avatar de Tofalu
 
Christophe Warin
Inscription : octobre 2004
Messages : 8 635
Détails du profil
Informations personnelles :
Nom : Christophe Warin
Âge : 28

Informations forums :
Inscription : octobre 2004
Messages : 8 635
Points : 13 718
Points : 13 718
Je dirais comme toi philben Il me semble que IsMissing fonctionne comme IsEmpty

Pour moi, impossible de faire un IsMissing sur une chaine de caractère.

J'aurais tendance à faire :

Citation:
Function GetRelativePath(ByVal strPath As String, Optional ByVal strPathCurrent As String="")

if strPathCurrent ="" then ...
Tofalu est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 05h09.


 
 
 
 
Partenaires

Hébergement Web