Solved

Easy ini

Posted on 1998-08-27
6
243 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel VBA combine two working workbooks 8 55
How to debug this code 7 62
Set email body to html using vbscript 6 42
Automatic Email Reminder 4 38
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

831 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