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

nOpe

[VB 6] Carregar e salvar texbox

5 mensagens neste tópico

Gostaria de saber o codigo para carregar e salvar ficheiros INI a partir duma simples textbox em vb6...

Ja soube fazer uma vez mas davame smp erro no salvar... =\

Por favor ajudem  :wallbash:

Cumps [[ ]]

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Para o que tu queres um ficheiro .ini não passa de um simples ficheiro de texto como um .txt :P

Cumps

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Por acaso sso tambem me dava muito jeito a mim.

Ninguem pode por ai o codigo disso?  :-[

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

O VB6 tem uma API para isso mesmo, que foi removida no .NET

já agora para os .NET que queiram operar com INI's aqui fica uma class

Class by  Karl Moore

Public Class IniFile
' API functions
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 System.Text.StringBuilder, _
   ByVal nSize 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 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 FlushPrivateProfileString _
   Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
   (ByVal lpApplicationName As Integer, _
   ByVal lpKeyName As Integer, ByVal lpString As Integer, _
   ByVal lpFileName As String) As Integer
Dim strFilename As String

' Constructor, accepting a filename
Public Sub New(ByVal Filename As String)
   strFilename = Filename
End Sub

' Read-only filename property
ReadOnly Property FileName() As String
   Get
       Return strFilename
   End Get
End Property

Public Function GetString(ByVal Section As String, _
   ByVal Key As String, ByVal [Default] As String) As String
   ' Returns a string from your INI file
   Dim intCharCount As Integer
   Dim objResult As New System.Text.StringBuilder(256)
   intCharCount = GetPrivateProfileString(Section, Key, _
      [Default], objResult, objResult.Capacity, strFilename)
   If intCharCount > 0 Then GetString = _
      Left(objResult.ToString, intCharCount)
End Function

Public Function GetInteger(ByVal Section As String, _
   ByVal Key As String, ByVal [Default] As Integer) As Integer
   ' Returns an integer from your INI file
   Return GetPrivateProfileInt(Section, Key, _
      [Default], strFilename)
End Function

Public Function GetBoolean(ByVal Section As String, _
   ByVal Key As String, ByVal [Default] As Boolean) As Boolean
   ' Returns a boolean from your INI file
   Return (GetPrivateProfileInt(Section, Key, _
      CInt([Default]), strFilename) = 1)
End Function

Public Sub WriteString(ByVal Section As String, _
   ByVal Key As String, ByVal Value As String)
   ' Writes a string to your INI file
   WritePrivateProfileString(Section, Key, Value, strFilename)
   Flush()
End Sub

Public Sub WriteInteger(ByVal Section As String, _
   ByVal Key As String, ByVal Value As Integer)
   ' Writes an integer to your INI file
   WriteString(Section, Key, CStr(Value))
   Flush()
End Sub

Public Sub WriteBoolean(ByVal Section As String, _
   ByVal Key As String, ByVal Value As Boolean)
   ' Writes a boolean to your INI file
   WriteString(Section, Key, CStr(CInt(Value)))
   Flush()
End Sub

Private Sub Flush()
   ' Stores all the cached changes to your INI file
   FlushPrivateProfileString(0, 0, 0, strFilename)
End Sub

End Class

Modo de usar:

Depois de adicionar essa class

Dim objIniFile As New IniFile("c:\data.ini")
objIniFile.WriteString("Settings", "ClockTime", "12:59")
Dim strData As String = _
    objIniFile.GetString("Settings", "ClockTime", "(none)")

Keyword's para procuras: ini vb.net ficheiro

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Crie uma conta ou ligue-se para comentar

Só membros podem comentar

Criar nova conta

Registe para ter uma conta na nossa comunidade. É fácil!


Registar nova conta

Entra

Já tem conta? Inicie sessão aqui.


Entrar Agora