OVH Cloud OVH Cloud

Pb affichage d'un string

4 réponses
Avatar
Franck
Bonjour à tous

Est ce que quelqu'un sait comment faire pour afficher dans un label les
éléments essentiels d'un path
Je m'explique
avoir qqch du genre: c:\...\...\GGDN\mon_fichier.exe plutot que
c:\rep1\rep2\G

Merci

4 réponses

Avatar
Jean-Marc
"Franck" a écrit dans le message de
news:
Bonjour à tous

Est ce que quelqu'un sait comment faire pour afficher dans un label les
éléments essentiels d'un path
Je m'explique
avoir qqch du genre: c:......GGDNmon_fichier.exe plutot que
c:rep1rep2G



Hello,

un peu de programmation en VB devrait le faire non?
Allez, une petite fonction comme ça:

Function GetReducedPath(CompletePath as string, MaxSubDirBeforeFileName as
integer)

Qui retournera la chemin réduit sous la forme:
C:..SUBDIR1SUBDIR2filename.fic

avec SUBDIR1, SUBDIR2, etc dépendant de la valeur de MaxSubDirBeforeFileName
(ici = 2).

Bonne prog!

Jean-marc
Avatar
ng
Salut,

Essaye ceci :

'//Form1

Option Explicit

Private Sub Form_Load()
MsgBox GetReducedPath("c:Mon Dossier1Mon Dossier Enfant2Encore un
petit n'EnfantMon Fichier.ext", 32)
End Sub

Public Function GetReducedPath(ByRef strPath As String, ByRef intMaxLength
As Integer) As String
Dim tblRep() As String, i As Integer
Dim intTot As Integer
If Len(strPath) > intMaxLength Then
tblRep = Split(strPath, "")
For i = UBound(tblRep) - 1 To 1 Step -1
intTot = intTot + Len(tblRep(i))
If intTot > intMaxLength Then tblRep(i) = "..."
Next
GetReducedPath = Join(tblRep, "")
Erase tblRep
Else
GetReducedPath = strPath
End If
End Function


--
Nicolas G.
FAQ VB : http://faq.vb.free.fr
API Guide : http://www.allapi.net
Google Groups : http://groups.google.fr/
MZ-Tools : http://www.mztools.com/
http://apisvb.europe.webmatrixhosting.net/



Jean-Marc a écrit :

"Franck" a écrit dans le message de
news:
Bonjour à tous

Est ce que quelqu'un sait comment faire pour afficher dans un label
les éléments essentiels d'un path
Je m'explique
avoir qqch du genre: c:......GGDNmon_fichier.exe plutot que
c:rep1rep2G



Hello,

un peu de programmation en VB devrait le faire non?
Allez, une petite fonction comme ça:

Function GetReducedPath(CompletePath as string,
MaxSubDirBeforeFileName as integer)

Qui retournera la chemin réduit sous la forme:
C:..SUBDIR1SUBDIR2filename.fic

avec SUBDIR1, SUBDIR2, etc dépendant de la valeur de
MaxSubDirBeforeFileName (ici = 2).

Bonne prog!

Jean-marc


Avatar
François Picalausa
Hello,

(désolé si ce message apparait deux fois)

tu peux utiliser l'API DrawText à la place d'un label:

'***
Option Explicit

Private Const DT_PATH_ELLIPSIS As Long = &H4000
Private Const DT_MODIFYSTRING As Long = &H10000

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function DrawText _
Lib "user32" _
Alias "DrawTextA" _
( _
ByVal hdc As Long, _
ByVal lpStr As String, _
ByVal nCount As Long, _
lpRect As RECT, _
ByVal wFormat As Long _
) _
As Long

Private Sub Form_Load()
lblPlaceHolder.Visible = False
lblPlaceHolder.Caption = "C:un nom de dossier très
longtototitimonfichier.test"
Me.ScaleMode = 3
End Sub

Private Sub PaintLabel()
Dim PHRect As RECT
Dim OldScaleMode As Long

PHRect.Left = lblPlaceHolder.Left
PHRect.Top = lblPlaceHolder.Top
PHRect.Right = lblPlaceHolder.Left + lblPlaceHolder.Width
PHRect.Bottom = lblPlaceHolder.Top + lblPlaceHolder.Height

DrawText Me.hdc, lblPlaceHolder.Caption, _
Len(lblPlaceHolder.Caption), PHRect, _
DT_PATH_ELLIPSIS Or DT_MODIFYSTRING
End Sub

Private Sub Form_Paint()
PaintLabel
End Sub

'***

On peut aussi le faire en connaissant le nombre de caractères cible:

'***
Option Explicit

Private Declare Function PathCompactPathEx _
Lib "shlwapi" _
Alias "PathCompactPathExA" _
( _
ByVal pszOut As String, _
ByVal pszSrc As String, _
ByVal cchMax As Long, _
ByVal dwFlags As Long _
) _
As Long

Private Sub Form_Load()
Dim strBuffer As String
Const OriginalText As String = "E:Program
filestesttototitimytest.tiff"

strBuffer = String$(40, vbNullChar) '39 caractères
If PathCompactPathEx(strBuffer, OriginalText, 40, 0) Then
lblPath.Caption = Left$(strBuffer, 39)
End If
End Sub
'***

--
François Picalausa (MVP VB)
http://faq.vb.free.fr --- http://msdn.microsoft.com
http://apisvb.europe.webmatrixhosting.net

"Franck" a écrit dans le message de
news:
Est ce que quelqu'un sait comment faire pour afficher dans un label
les éléments essentiels d'un path


Avatar
Franck
Merci à tous pour vos réponses qui sont bien intéressantes

Merci.

"Franck" a écrit dans le message de
news:
Bonjour à tous

Est ce que quelqu'un sait comment faire pour afficher dans un label les
éléments essentiels d'un path
Je m'explique
avoir qqch du genre: c:......GGDNmon_fichier.exe plutot que
c:rep1rep2G

Merci