• Revista PROGRAMAR: Já está disponível a edição #53 da revista programar. Faz já o download aqui!

Sign in to follow this  
Followers 0

[VB6] Modulo de leitura de Ficheiros INI

1 post in this topic

Dim a
Dim texto As String
Dim asd
Public Function readini(filedir As String, fileline As Byte) As String

On Error Resume Next
If FileExist(filedir) Then
    If fileline = 0 Then
        MsgBox "Impossivel ler linha 0"
        readini = "ERRO"
        a = FreeFile
        Open filedir For Input As a
            If fileline = 1 Then
                Input #a, texto
                Close #a
                For i = 1 To fileline
                    Input #a, texto
                    Next i
                Close #a
            End If
    asd = InStrRev(texto, "=")
    readini = Right(texto, Len(texto) - asd)

    End If
MsgBox "Ficheiro nao encontrado"
readini = "ERRO"

End If
If readini = "" Then readini = "ERRO"
End Function
Public Function FileExist(asPath As String) As Boolean

If UCase(Dir(asPath)) = UCase(TrimPath(asPath)) Then
FileExist = True
FileExist = False
End If
End Function
Public Function TrimPath(ByVal asPath As String) As String

If Len(asPath) = 0 Then Exit Function
Dim x As Integer

x = InStr(asPath, "\")
If x = 0 Then Exit Do
asPath = Right(asPath, Len(asPath) - x)
TrimPath = asPath
End Function

Para o utilizarem :

variavel = Readini(”C:\config.ini”, 3)

“C:\config.ini” é a localização do ficheiro a ler e o "3" é a linha a lêr.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0