Solved

INI files

Posted on 1997-05-18
4
252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

739 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