• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Easy ini

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
smurray
Asked:
smurray
  • 4
1 Solution
 
smurrayAuthor Commented:
Edited text of question
0
 
smurrayAuthor Commented:
Edited text of question
0
 
smurrayAuthor Commented:
Edited text of question
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
clifABBCommented:
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
 
DalinCommented:
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
 
smurrayAuthor Commented:
Thanks, I will give it a go
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now