tags:

views:

56

answers:

5

I've got a situation where an ini file is in memory (in a string variable) and I'd like to read values out of it without writing the ini file data to disk.

UPDATE:This is data that I do not want to write to the HD. I'm downloading it from a web server into memory and then getting some data.

Is there any way to do that in VB6? Maybe with a Win API call?

A: 

The ini file is to be stored on hard disk. If you want to save in registry instead (this should be added to the registry file too), you can use these functions:

SaveSetting
GetSetting
Sarfraz
A: 

If you don't want to save it on disk I think it might be difficult to use any specific API calls. But if it's an ini file it should be in a structured format, why not just loop through it until the section you want and then read the values you want from it.

It's been a long time but it should be something like this I think:

Just Split it on newlines to get an array of lines, then each section should start in a certain format and for each line in there you check if it contains an = I think, and if so everything to the left of the first = is the name of the value and everything to the right of it is the value.

ho1
+2  A: 

Clay,

Check out this article at DevX.com

Read/Write INI without using API

This should get you pointed in a good direction. The modules are a bit dirty and do, at this point, require a path for the INI to be stored. Instead simply modify the modules to use your string directly and you should receive the desired result. Let me know how this works out for you.

Jeff
A: 

Declare the two Windows API function imports

Public Declare Function GetPrivateProfileStringA Lib "kernel32.dll" (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 

Public Declare Function WritePrivateProfileStringA Lib "kernel32.dll" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long 

For reading

sReturn = Space(255)
sReturn = Left(sReturn, GetPrivateProfileStringA(header, key, defaultReturn, sReturn, 255, filePath))

For writting

WritePrivateProfileStringA header, key, Datum, filePath

Remember the structure of an INI file is

[header]
key=data 
Carlos Loth
Carolos, those read/write from/to FILES not from internal strings.
Clay Nichols
A: 

Yes, almost anything is possible in VB6. But I don't think there is any windows API to do it.

If you can't find a library to do it, you will have to code it your self. If you have to code it your self, see if you can find some existing code that works with ini files so you know how to work with ini files.

Echo
There is two windows api functions for dealing with INI files, GetPrivateProfileStringA and WritePrivateProfileStringA.
Carlos Loth
Those require a file though.
Echo