Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

INI files

Posted on 1997-05-18
4
Medium Priority
?
254 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 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

722 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