Clique abaixo para nos ajudar
Conectar-se

Esqueci minha senha

Estamos no Facebook
Buscar
 
 

Resultados por:
 


Rechercher Busca avançada

Quem está conectado
10 usuários online :: Nenhum usuário registrado, Nenhum Invisível e 10 Visitantes :: 2 Motores de busca

Nenhum

[ Ver toda a lista ]


O recorde de usuários online foi de 468 em 1/3/2012, 10:43
Erro de compatibilidade de cores

28/3/2017, 10:59 por Clebervfp

Boa dia, estou com um problema com vfp9, se alguém poder me ajudar fico agradecido!

Tenho um …

Comentários: 0

Espessura do cursor intermitente

7/3/2017, 09:08 por Jefferson Matakas

Bom dia a todos !!

Existe uma opcao no windows que pode ser acessada atraves da 'central da …

Comentários: 0

DESENVOLVIMENTO EM REDES

4/3/2017, 18:45 por AJC

Pessoal tem ou conhece livros ou material para programação em
redes usando banco de dados nativo …

Comentários: 0

USAR REPORT FORM

30/12/2016, 09:06 por AJC

Pessoal bom dia,
Estou com um grande problema, já pesquisei muita coisa sobre report form, mas o …

Comentários: 4

Como preencher campos vazios

9/2/2017, 11:55 por Linghston

Pessoal boa tarde,

É o seguinte, eu preciso preencher os campos de uma coluna da tabela DBF que …

Comentários: 2

Estatísticas
Temos 7039 usuários registrados
O último usuário registrado atende pelo nome de missias

Os nossos membros postaram um total de 32 mensagens em 18 assuntos

Arquivo INI

Ver o tópico anterior Ver o tópico seguinte Ir em baixo

Anexo Arquivo INI

Mensagem por Marcos Guedes em 28/8/2009, 14:05

Encontrei uma ótima rotina para leitura de arquivo .ini no seguinte link:
[Você precisa estar registrado e conectado para ver este link.]

Espero que seja útil aos colegas:
Código:
Imports System
Imports System.Text
Imports System.Collections
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic

' The Org.Mentalis.Files contains a number of classes that read from or write to special files.
Namespace Org.Mentalis.Files

    Public Class IniReader
        Private Declare Ansi Function GetPrivateProfileInt Lib "kernel32.dll" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Integer, ByVal lpFileName As String) As Integer
        Private Declare Ansi Function WritePrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
        Private Declare Ansi Function GetPrivateProfileString Lib "kernel32.dll" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
        Private Declare Ansi Function GetPrivateProfileSectionNames Lib "kernel32" Alias "GetPrivateProfileSectionNamesA" (ByVal lpszReturnBuffer() As Byte, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
        Private Declare Ansi Function WritePrivateProfileSection Lib "kernel32.dll" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
        Public Sub New(ByVal file As String)
            Filename = file
        End Sub
        Public Property Filename() As String
            Get
                Return m_Filename
            End Get
            Set(ByVal Value As String)
                m_Filename = Value
            End Set
        End Property
        Public Property Section() As String
            Get
                Return m_Section
            End Get
            Set(ByVal Value As String)
                m_Section = Value
            End Set
        End Property
        Public Function ReadInteger(ByVal section As String, ByVal key As String, ByVal defVal As Integer) As Integer
            Return GetPrivateProfileInt(section, key, defVal, Filename)
        End Function
        Public Function ReadInteger(ByVal section As String, ByVal key As String) As Integer
            Return ReadInteger(section, key, 0)
        End Function
        Public Function ReadInteger(ByVal key As String, ByVal defVal As Integer) As Integer
            Return ReadInteger(Section, key, defVal)
        End Function
        Public Function ReadInteger(ByVal key As String) As Integer
            Return ReadInteger(key, 0)
        End Function
        Public Function ReadString(ByVal section As String, ByVal key As String, ByVal defVal As String) As String
            Dim sb As New StringBuilder(MAX_ENTRY)
            Dim Ret As Integer = GetPrivateProfileString(section, key, defVal, sb, MAX_ENTRY, Filename)
            Return sb.ToString()
        End Function
        Public Function ReadString(ByVal section As String, ByVal key As String) As String
            Return ReadString(section, key, "")
        End Function
        Public Function ReadString(ByVal key As String) As String
            Return ReadString(Section, key)
        End Function
        Public Function ReadLong(ByVal section As String, ByVal key As String, ByVal defVal As Long) As Long
            Return Long.Parse(ReadString(section, key, defVal.ToString()))
        End Function
        Public Function ReadLong(ByVal section As String, ByVal key As String) As Long
            Return ReadLong(section, key, 0)
        End Function
        Public Function ReadLong(ByVal key As String, ByVal defVal As Long) As Long
            Return ReadLong(Section, key, defVal)
        End Function
        Public Function ReadLong(ByVal key As String) As Long
            Return ReadLong(key, 0)
        End Function
        Public Function ReadByteArray(ByVal section As String, ByVal key As String) As Byte()
            Try
                Return Convert.FromBase64String(ReadString(section, key))
            Catch
            End Try
            Return Nothing
        End Function
        Public Function ReadByteArray(ByVal key As String) As Byte()
            Return ReadByteArray(Section, key)
        End Function
        Public Function ReadBoolean(ByVal section As String, ByVal key As String, ByVal defVal As Boolean) As Boolean
            Return Boolean.Parse(ReadString(section, key, defVal.ToString()))
        End Function
        Public Function ReadBoolean(ByVal section As String, ByVal key As String) As Boolean
            Return ReadBoolean(section, key, False)
        End Function
        Public Function ReadBoolean(ByVal key As String, ByVal defVal As Boolean) As Boolean
            Return ReadBoolean(Section, key, defVal)
        End Function
        Public Function ReadBoolean(ByVal key As String) As Boolean
            Return ReadBoolean(Section, key)
        End Function
        Public Function Write(ByVal section As String, ByVal key As String, ByVal value As Integer) As Boolean
            Return Write(Section, key, value.ToString())
        End Function
        Public Function Write(ByVal key As String, ByVal value As Integer) As Boolean
            Return Write(Section, key, value)
        End Function
        Public Function Write(ByVal section As String, ByVal key As String, ByVal value As String) As Boolean
            Return (WritePrivateProfileString(section, key, value, Filename) <> 0)
        End Function
        Public Function Write(ByVal key As String, ByVal value As String) As Boolean
            Return Write(Section, key, value)
        End Function
        Public Function Write(ByVal section As String, ByVal key As String, ByVal value As Long) As Boolean
            Return Write(section, key, value.ToString())
        End Function
        Public Function Write(ByVal key As String, ByVal value As Long) As Boolean
            Return Write(Section, key, value)
        End Function
        Public Function Write(ByVal section As String, ByVal key As String, ByVal value() As Byte) As Boolean
            If value Is Nothing Then
                Return Write(section, key, CType(Nothing, String))
            Else
                Return Write(section, key, value, 0, value.Length)
            End If
        End Function
        Public Function Write(ByVal key As String, ByVal value() As Byte) As Boolean
            Return Write(Section, key, value)
        End Function
        Public Function Write(ByVal section As String, ByVal key As String, ByVal value() As Byte, ByVal offset As Integer, ByVal length As Integer) As Boolean
            If value Is Nothing Then
                Return Write(section, key, CType(Nothing, String))
            Else
                Return Write(section, key, Convert.ToBase64String(value, offset, length))
            End If
        End Function
        Public Function Write(ByVal section As String, ByVal key As String, ByVal value As Boolean) As Boolean
            Return Write(section, key, value.ToString())
        End Function
        Public Function Write(ByVal key As String, ByVal value As Boolean) As Boolean
            Return Write(Section, key, value)
        End Function
        Public Function DeleteKey(ByVal section As String, ByVal key As String) As Boolean
            Return (WritePrivateProfileString(Section, key, Nothing, Filename) <> 0)
        End Function
        Public Function DeleteKey(ByVal key As String) As Boolean
            Return (WritePrivateProfileString(Section, key, Nothing, Filename) <> 0)
        End Function
        Public Function DeleteSection(ByVal section As String) As Boolean
            Return WritePrivateProfileSection(section, Nothing, Filename) <> 0
        End Function
        Public Function GetSectionNames() As ArrayList
            Try
                Dim buffer(MAX_ENTRY) As Byte
                GetPrivateProfileSectionNames(buffer, MAX_ENTRY, Filename)
                Dim parts() As String = Encoding.ASCII.GetString(buffer).Trim(ControlChars.NullChar).Split(ControlChars.NullChar)
                Return New ArrayList(parts)
            Catch
            End Try
            Return Nothing
        End Function
        Private m_Filename As String
        Private m_Section As String
        Private Const MAX_ENTRY As Integer = 32768
    End Class
End Namespace

Obs: Precisei retirar a documentação pois o conteúdo estava grande para postar.
Não deixe de baixar o arquivo original:
[Você precisa estar registrado e conectado para ver este link.]

_________________
Marcos Guedes - Programador e desenvolvedor Web.


Visite o nosso portal:
[Você precisa estar registrado e conectado para ver este link.]

Marcos Guedes
Webmaster
Webmaster


Voltar ao Topo Ir em baixo

Anexo Re: Arquivo INI

Mensagem por Marcos Guedes em 28/8/2009, 14:05

Segue um exemplo de como utilizar a rotina:
Código:
Imports System
Imports System.Collections
Imports Org.Mentalis.Files

Public Class TestApp
    Public Shared Sub Main()
        Dim ini As New IniReader("c:\test.ini")
        ini.Write("Section1", "KeyString", "MyString")
        ini.Write("Section1", "KeyInt", 5)
        ini.Write("Section2", "KeyBool", True)
        ini.Write("Section2", "KeyBytes", New Byte() {0, 123, 255})
        ini.Write("Section3", "KeyLong", CType(123456789101112, Long))
        ini.Section = "Section1"
        Console.WriteLine("String: " + ini.ReadString("KeyString"))
        Console.WriteLine("Int: " + ini.ReadInteger("KeyInt", 0).ToString())
        Console.WriteLine("Bool: " + ini.ReadBoolean("Section2", "KeyBool", False).ToString())
        Console.WriteLine("Long: " + ini.ReadLong("Section3", "KeyLong", 0).ToString())
        Console.WriteLine("Byte 1 in byte array: " + (ini.ReadByteArray("Section2", "KeyBytes")(1)).ToString())
        ini.DeleteKey("Section2", "KeyBytes")
        ini.DeleteSection("Section3")
        Dim e As IEnumerator = ini.GetSectionNames().GetEnumerator()
        While e.MoveNext()
            Console.WriteLine(e.Current)
        End While
        Console.WriteLine("Press enter to continue...")
        Console.ReadLine()
    End Sub
End Class
Obs: Este exemplo foi retirado do próprio arquivo contido no seguinte link:
[Você precisa estar registrado e conectado para ver este link.]

_________________
Marcos Guedes - Programador e desenvolvedor Web.


Visite o nosso portal:
[Você precisa estar registrado e conectado para ver este link.]

Marcos Guedes
Webmaster
Webmaster


Voltar ao Topo Ir em baixo

Ver o tópico anterior Ver o tópico seguinte Voltar ao Topo


 
Permissão deste fórum:
Você não pode responder aos tópicos neste fórum