Foros del Web » Programación para mayores de 30 ;) » .NET »

Ayuda Con Este Codigo Please

Estas en el tema de Ayuda Con Este Codigo Please en el foro de .NET en Foros del Web. HOLA MIRAD TENGO ESTE CODIGO PARA LEER *.INI ES UN MODULO PARA VB.NET: Imports System Imports System.Text Imports System.Collections Imports System.Runtime.InteropServices Imports Microsoft.VisualBasic Namespace Org.Mentalis.Files ...
  #1 (permalink)  
Antiguo 20/01/2004, 14:52
 
Fecha de Ingreso: agosto-2003
Mensajes: 398
Antigüedad: 20 años, 8 meses
Puntos: 0
Pregunta Ayuda Con Este Codigo Please

HOLA MIRAD TENGO ESTE CODIGO PARA LEER *.INI

ES UN MODULO PARA VB.NET:


Imports System
Imports System.Text
Imports System.Collections
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic


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



Y QUIERO DESDE UN FORM ACCEDER A LAS FUNCIONES PARA LEER UN INI Y LUEGO LEER SUS SECCIONES:

¿COMO LO HAGO?
POR FAVOR PONENME UN EJEMPLO DE COMO DESDE UN FORM1 ACCEDER A LAS FUNCIONES DEL MODULO Y LEER UNA SECCION DE UN FICHERO INI Y QUE ME LO PONGA EN UN TXTBOX.


GRACIAS POR VUESTRA AYUDA AMIGOS.

SALUDOS A TODOS
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:16.