Solved

Easy ini

Posted on 1998-08-27
6
234 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

760 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

20 Experts available now in Live!

Get 1:1 Help Now