Solved

INI files

Posted on 1997-05-18
4
250 Views
Last Modified: 2006-11-17
I want to use INI files with VB5. In running VB under Windows NT 4.0 WS so when I use the getsetting and savesetting functions, I write down my data in the registry.

How can I still write the data to INI files ?
0
Comment
Question by:marcel051897
  • 3
4 Comments
 
LVL 5

Accepted Solution

by:
y96andha earned 100 total points
ID: 1426385
Use the API functions WritePrivateProfileString, GetPrivateProfileString and GetPrivateProfileInt.
0
 
LVL 5

Expert Comment

by:y96andha
ID: 1426386
API declarations:

Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long

0
 

Author Comment

by:marcel051897
ID: 1426387
I tried it with these functions, but I get a compile error.

Can you send some sample code for these functions?
0
 
LVL 5

Expert Comment

by:y96andha
ID: 1426388
This is a copy of my test form. Save it as a file with extension .frm and load it into VB.

VERSION 4.00
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   4230
   ClientLeft      =   1140
   ClientTop       =   1515
   ClientWidth     =   6195
   Height          =   4635
   Left            =   1080
   LinkTopic       =   "Form1"
   ScaleHeight     =   4230
   ScaleWidth      =   6195
   Top             =   1170
   Width           =   6315
   Begin VB.TextBox value
      Height          =   285
      Left            =   2400
      TabIndex        =   9
      Text            =   "Text4"
      Top             =   2880
      Width           =   3495
   End
   Begin VB.CommandButton cmdwrite
      Caption         =   "Write"
      Height          =   375
      Left            =   4680
      TabIndex        =   4
      Top             =   3480
      Width           =   1215
   End
   Begin VB.CommandButton cmdread
      Caption         =   "Read"
      Height          =   375
      Left            =   2400
      TabIndex        =   3
      Top             =   3480
      Width           =   1215
   End
   Begin VB.TextBox valuename
      Height          =   285
      Left            =   2400
      TabIndex        =   2
      Text            =   "Text3"
      Top             =   2400
      Width           =   3495
   End
   Begin VB.TextBox section
      Height          =   285
      Left            =   2400
      TabIndex        =   1
      Text            =   "Text2"
      Top             =   1920
      Width           =   3495
   End
   Begin VB.TextBox filename
      Height          =   285
      Left            =   2400
      TabIndex        =   0
      Text            =   "Text1"
      Top             =   1440
      Width           =   3495
   End
   Begin VB.Label Label4
      Caption         =   "Value"
      Height          =   255
      Left            =   600
      TabIndex        =   8
      Top             =   2880
      Width           =   1335
   End
   Begin VB.Label Label3
      Caption         =   "Value name"
      Height          =   255
      Left            =   600
      TabIndex        =   7
      Top             =   2400
      Width           =   1455
   End
   Begin VB.Label Label2
      Caption         =   "Section"
      Height          =   255
      Left            =   600
      TabIndex        =   6
      Top             =   1920
      Width           =   1335
   End
   Begin VB.Label Label1
      Caption         =   "Ini file name"
      Height          =   255
      Left            =   600
      TabIndex        =   5
      Top             =   1440
      Width           =   1335
   End
End
Attribute VB_Name = "Form1"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long




Private Sub cmdread_Click()
    Dim str As String
    str = String(256, 0)
    GetPrivateProfileString section.Text, valuename.Text, "<value not found>", str, 255, filename.Text
    If InStr(str, Chr(0)) Then
        str = Left$(str, InStr(str, Chr(0)) - 1)
    End If
    value.Text = str
End Sub

Private Sub cmdwrite_Click()
    WritePrivateProfileString section.Text, valuename.Text, value.Text, filename.Text
End Sub

0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question