renocmoa
Messages postés134Date d'inscriptionmardi 7 septembre 2004StatutMembreDernière intervention10 mai 2012 6 déc. 2007 à 19:26
A y est
<System.Runtime.InteropServices.DllImport("shlwapi")> Public Function StrFormatByteSize64(ByVal qdw As Int64, <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.VBByRefStr)> ByRef pszBuf As String, ByVal cchBuf As Integer) As IntPtr
End Function
int64 marche et resultat garanti jusqu'au Po !!! (aprés To lui même aprés Go)
renocmoa
Messages postés134Date d'inscriptionmardi 7 septembre 2004StatutMembreDernière intervention10 mai 2012 6 déc. 2007 à 18:59
en fait marche pas elle donne le resultat en Ko....!
je cherche
renocmoa
Messages postés134Date d'inscriptionmardi 7 septembre 2004StatutMembreDernière intervention10 mai 2012 6 déc. 2007 à 18:21
j'ai donc utilisé
<System.Runtime.InteropServices.DllImport("shlwapi")> Public Function StrFormatKBSize(ByVal qdw As Int64, <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.VBByRefStr)> ByRef pszBuf As String, ByVal cchBuf As Integer) As IntPtr
End Function
en divisant par 1000 ma valeur
et là Int64 ok
renocmoa
Messages postés134Date d'inscriptionmardi 7 septembre 2004StatutMembreDernière intervention10 mai 2012 6 déc. 2007 à 17:59
Help
dépassement de capacité avec Uinteger...??? et marche pas avec Int64
Jonny Bee@ oui mais l'avantage de l'api est qu'il fait dans les bonnes normes mais aussi en fonction de la culture. Par exemple, j'ai un système us, j'ai KB, MB, GB au lieu de Ko, Mo, Go. Avec ta méthode, il faudrait récupéré par api la bonne unité.
__
Kenji
Jonny Bee
Messages postés16Date d'inscriptionmardi 10 octobre 2006StatutMembreDernière intervention 2 décembre 2007 2 déc. 2007 à 14:23
Tu peux récupérer ces infos via la Classe FileInfo, l'affichage du résultat
peut être formaté à ta guise!
Sub InfoFile(MonFichier)
'Récupération et affichage des infos relatives au fichier en cours.
'Le résultat est affiché dans un label de la Status Bar.
'Conversion de la longueur en Ko, Mo, Go, selon le cas.
Dim Fi As FileInfo = New FileInfo(MonFichier)
Dim sfiLength As Single = Fi.Length
Pour le ByRef, on peut passer par un StringBuilder :
<System.Runtime.InteropServices.DllImport("shlwapi")> _
Public Function StrFormatByteSizeA(ByVal dw As UInteger, _
ByVal pszBuf As System.Text.StringBuilder, _
ByVal cchBuf As Integer) As System.IntPtr
End Function
Public Function TailleFichier(ByVal TailleEnOctets As UInteger) As String
Dim mem As New System.Text.StringBuilder(256)
If StrFormatByteSizeA(TailleEnOctets, mem, mem.Capacity) <> System.IntPtr.Zero Then
Return mem.ToString()
Else
Return Nothing
End If
End Function
__
Kenji
UInt pour la simple raison que sinon tu peux pas mettre des taille allant au GO
2400000000 va provoquer une erreur de dépassement de capacité.
__
Kenji
renocmoa
Messages postés134Date d'inscriptionmardi 7 septembre 2004StatutMembreDernière intervention10 mai 2012 2 déc. 2007 à 08:57
merci des commentaire pourquoi Uint32 ? j'ai pas mal bataillé pour arriver à faire marcher cette api justement à cause du typage et en fouillant par recoupement suis arrivé là bizzarement les api sont en général donnée avec des variable ByVal quand elles doivent être en ByRef ...? donc en fouinant j'ai trouvé VBByRefStr . Je ne suis que bricoleur...
Attention, au typage. Utilise UInt32 plutot que des Int32.
Attention aussi aux anciennes fonction vb6.
<System.Runtime.InteropServices.DllImport("shlwapi")> _
Public Shared Function StrFormatByteSizeA(ByVal dw As UInteger, _
<Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.VBByRefStr)> ByRef pszBuf As String, _
ByVal cchBuf As Integer) As IntPtr
End Function
Public Function TailleFichier(ByVal TailleEnOctets As UInteger) As String
Dim mem As String = New String(" "c, 256)
If StrFormatByteSizeA(TailleEnOctets, mem, mem.Length) <> 0 Then
Return mem.Trim()
Else
Return Nothing
End If
End Function
__
Kenji
renocmoa
Messages postés134Date d'inscriptionmardi 7 septembre 2004StatutMembreDernière intervention10 mai 2012 1 déc. 2007 à 22:23
désolé oublié de cocher la case et codyx je m'en occupe
ghuysmans99
Messages postés2496Date d'inscriptionjeudi 14 juillet 2005StatutContributeurDernière intervention 5 juin 20161 1 déc. 2007 à 22:05
C'est un code .NET et pas un code VB ...
Et en + ça devrait être sur Codyx.org !!
6 déc. 2007 à 19:26
<System.Runtime.InteropServices.DllImport("shlwapi")> Public Function StrFormatByteSize64(ByVal qdw As Int64, <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.VBByRefStr)> ByRef pszBuf As String, ByVal cchBuf As Integer) As IntPtr
End Function
int64 marche et resultat garanti jusqu'au Po !!! (aprés To lui même aprés Go)
6 déc. 2007 à 18:59
je cherche
6 déc. 2007 à 18:21
<System.Runtime.InteropServices.DllImport("shlwapi")> Public Function StrFormatKBSize(ByVal qdw As Int64, <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.VBByRefStr)> ByRef pszBuf As String, ByVal cchBuf As Integer) As IntPtr
End Function
en divisant par 1000 ma valeur
et là Int64 ok
6 déc. 2007 à 17:59
dépassement de capacité avec Uinteger...??? et marche pas avec Int64
environ 100Go
2 déc. 2007 à 14:32
__
Kenji
2 déc. 2007 à 14:23
peut être formaté à ta guise!
Sub InfoFile(MonFichier)
'Récupération et affichage des infos relatives au fichier en cours.
'Le résultat est affiché dans un label de la Status Bar.
'Conversion de la longueur en Ko, Mo, Go, selon le cas.
Dim Fi As FileInfo = New FileInfo(MonFichier)
Dim sfiLength As Single = Fi.Length
If sfiLength <= 999999 Then
Me.StatBarLength.Text = " Longueur : " & _
String.Format("{0:N2}", (sfiLength / 1024)).ToString & " Ko"
ElseIf sfiLength >= 1000000 AndAlso sfiLength <= 999999999 Then
Me.StatBarLength.Text = " Longueur : " & _
String.Format("{0:N2}", (sfiLength / 1024 ^ 2)).ToString & " Mo"
Else
Me.StatBarLength.Text = " Longueur : " & _
String.Format("{0:N2}", (sfiLength / 1024 ^ 3)).ToString & " Go"
End If
End Sub
2 déc. 2007 à 09:52
<System.Runtime.InteropServices.DllImport("shlwapi")> _
Public Function StrFormatByteSizeA(ByVal dw As UInteger, _
ByVal pszBuf As System.Text.StringBuilder, _
ByVal cchBuf As Integer) As System.IntPtr
End Function
Public Function TailleFichier(ByVal TailleEnOctets As UInteger) As String
Dim mem As New System.Text.StringBuilder(256)
If StrFormatByteSizeA(TailleEnOctets, mem, mem.Capacity) <> System.IntPtr.Zero Then
Return mem.ToString()
Else
Return Nothing
End If
End Function
__
Kenji
2 déc. 2007 à 09:35
2400000000 va provoquer une erreur de dépassement de capacité.
__
Kenji
2 déc. 2007 à 08:57
1 déc. 2007 à 23:27
Attention aussi aux anciennes fonction vb6.
<System.Runtime.InteropServices.DllImport("shlwapi")> _
Public Shared Function StrFormatByteSizeA(ByVal dw As UInteger, _
<Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.VBByRefStr)> ByRef pszBuf As String, _
ByVal cchBuf As Integer) As IntPtr
End Function
Public Function TailleFichier(ByVal TailleEnOctets As UInteger) As String
Dim mem As String = New String(" "c, 256)
If StrFormatByteSizeA(TailleEnOctets, mem, mem.Length) <> 0 Then
Return mem.Trim()
Else
Return Nothing
End If
End Function
__
Kenji
1 déc. 2007 à 22:23
1 déc. 2007 à 22:05
Et en + ça devrait être sur Codyx.org !!