Test Foro de elhacker.net SMF 2.1

Programación => .NET (C#, VB.NET, ASP) => Programación General => Programación Visual Basic => Mensaje iniciado por: Mi4night en 2 Mayo 2010, 02:54 AM

Título: [VB6]mFileSize
Publicado por: Mi4night en 2 Mayo 2010, 02:54 AM
Bueno esto es sólo una función sencilla de determinar el tamaño de archivo de un archivo.

Option Explicit
'---------------------------------------------------------------------------------------
' Module      : mFileSize
' DateTime    : 25/12/09 02:19
' Author      : Mi4night
' Mail        : mi4night@hotmail.com
' Usage       : At your own risk.
' Purpose     : Get the size of a file
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce
'               or publish this code on any web site,
'               online service, or distribute as source
'               on any media without express permission.
'---------------------------------------------------------------------------------------
Private Declare Function GetCompressedFileSize _
                Lib "kernel32" _
                Alias "GetCompressedFileSizeA" (ByVal lpFileName As String, _
                                                lpFileSizeHigh As Long) As Long

Public Function GetFileSize(FilePath As String) As String
    'Variable Declaration
    Dim FSize As Double
   
    'Verify that the FilePath is given
    If Len(FilePath) <> 0 Then
       
        'Getting FileSize in bit
        FSize = GetCompressedFileSize(FilePath, ByVal 0&)

        If FSize < "1024" Then
            GetFileSize = FSize & " Bytes"
        ElseIf FSize >= "1024" And FSize < "1048576" Then
            GetFileSize = Round(FSize / 1024, 2) & " KB"
        ElseIf FSize >= "1048576" Then
            GetFileSize = Round(FSize / 1048576, 2) & " MB"
        End If

    Else
        Exit Function
    End If

End Function


Título: Re: [VB6]mFileSize
Publicado por: BlackZeroX en 2 Mayo 2010, 08:13 AM

[Valor Double] < [Texto Numerico]

Es = a mas de tiempo.

lo recomendable seria dejar los números sin comillas...

Yo uso personalmente: GetFileSize().. para esto en vb6.

y en lugar de usar Round() usa FormatNumber() y asi no concatenas bueno seria una alternativa...!¡.

Sangriento Infierno Lunar!¡.
Título: Re: [VB6]mFileSize
Publicado por: Psyke1 en 2 Mayo 2010, 13:36 PM
Hola, tengo una duda muy tonta:
xk utilizar una funcion si con FileLen(Path) obtenemos (yo creo) el mismo resultado?? :huh:
No estoy criticando la funcion ni mucho menos, solo es una duda...
Disculpen mi ignorancia... :laugh:

Gracias! ;D
Título: Re: [VB6]mFileSize
Publicado por: Mi4night en 2 Mayo 2010, 15:55 PM
BlackZeroX yeah you are right about the qoutes i use, it's a bad habbit of mine.
@*PsYkE1* Yeah you get the same when using filelen then you need then only to do the calculation as i did.:P But i love API
Título: Re: [VB6]mFileSize
Publicado por: Psyke1 en 2 Mayo 2010, 16:57 PM
Ok, thanks for the answer men, good job! ;D