Solved

INI files

Posted on 1997-05-18
4
247 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now