Solved

Easy ini

Posted on 1998-08-27
6
239 Views
Last Modified: 2010-04-30
I have been looking at various was to store information in an ini file and cannot seem to get it. I hae VB5 pro and need to store information like so.
INI file name will be Myapp.ini

[Your_Name}
No1=Bob
No2=Joe

and so on. I need to read back who is located in No1. ANy help and/or code will be rewarded.

-S
0
Comment
Question by:smurray
  • 4
6 Comments
 

Author Comment

by:smurray
ID: 1431355
Edited text of question
0
 

Author Comment

by:smurray
ID: 1431356
Edited text of question
0
 

Author Comment

by:smurray
ID: 1431357
Edited text of question
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:clifABB
ID: 1431358
Ini files are no longer the preferred way of storing data.  The preferred way is with the registry.
You can store and retrieve data to the registry with SaveSetting() and GetSetting().  Look in the help file for information on the usage.
0
 
LVL 9

Accepted Solution

by:
Dalin earned 120 total points
ID: 1431359
smurray,
Try this:

' Declare
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

'Function
Public Function fGetFromIni(SectionHeader$, VarName$, filename$) As String
'   Name:       fGetFromIni
'   Author:     Dalin Nie
'   Written:    3/14/95
'   Purpose:
'       This function returns the value of the variable
'       that is stored in the ini file.
'
'   Called procedures and functions:
'       GetPrivateProfileString
'
'   Input:
'       SectionHeader     Name of section in ini file
'       VarName           Name of variable in ini file
'       FileName          Filename of the ini file
'
'   Output:
'       The value of the VarName variable contained
'       in the SectionHeader section in the FileName
'       ini file.
'
'   Note: This function requires to declare an API function GetPrivateProfilestring


   Dim lReqStr As String

   On Error GoTo fGetFromIniErrHandler

   lReqStr = String(255, Chr(0))
  'Get Requested Information
   fGetFromIni = Left(lReqStr, GetPrivateProfilestring(SectionHeader$, ByVal VarName$, "", lReqStr, Len(lReqStr), filename$))
   Exit Function

fGetFromIniErrHandler:
   fGetFromIni = "ERROR"

End Function

When you need your data:

Dim myData as String

MyData = fGetFromINI("Your_Name", "No1", "MyApp")
'Mydata should be Bob.
0
 

Author Comment

by:smurray
ID: 1431360
Thanks, I will give it a go
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

914 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

14 Experts available now in Live!

Get 1:1 Help Now