473,410 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Reading all keys from an ini file section

Hi,

I am using the inireader class from mentalis.org but this does not provide a
function for retrieving all the key values of a particular section. Anyone
has developed such a function? I tried using the GetPrivateProfileString
function but to no avail.

TIA.
Nov 21 '05 #1
3 13429
On Mon, 16 Aug 2004 18:46:47 -0400, Atchoum wrote:
Hi,

I am using the inireader class from mentalis.org but this does not provide a
function for retrieving all the key values of a particular section. Anyone
has developed such a function? I tried using the GetPrivateProfileString
function but to no avail.

TIA.


What problems did you have with GetPrivateProfileString? Can you post your
attempted code?

--
Tom Shelton [MVP]
Nov 21 '05 #2
Tom,

Thanks for responding.

In VB6, I had a class which used GetPrivateProfileString to get all keys
from a section using 0 as the second parameter as in:
GetPrivateProfileStringKeys(sSection, 0, "", sKeyList, Max_Entry, sFile)
This would return all keys of the sSection Section.

I have tried the same with VB.NET (although the second parameter is a
string):

Private Declare Ansi Function GetPrivateProfileString Lib "kernel32.dll"
Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As
StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As
Integer

dim ret as integer= GetPrivateProfileString(Section, "" , defVal, sb,
MAX_ENTRY, Filename)

I tried several options in lieu of "" but nothing seemed to work.

Atchoum
Nov 21 '05 #3
In article <Yr*********************@wagner.videotron.net>, Atchoum wrote:
Tom,

Thanks for responding.

In VB6, I had a class which used GetPrivateProfileString to get all keys
from a section using 0 as the second parameter as in:
GetPrivateProfileStringKeys(sSection, 0, "", sKeyList, Max_Entry, sFile)
This would return all keys of the sSection Section.

I have tried the same with VB.NET (although the second parameter is a
string):

Private Declare Ansi Function GetPrivateProfileString Lib "kernel32.dll"
Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As
StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As
Integer

dim ret as integer= GetPrivateProfileString(Section, "" , defVal, sb,
MAX_ENTRY, Filename)

I tried several options in lieu of "" but nothing seemed to work.

Atchoum


here is a quick and dirty sample:

Option Strict On
Option Explicit On

Imports System
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.Collections.Specialized

Module Module1

Declare Auto Function GetPrivateProfileString Lib "kernel32" _
(ByVal lpAppName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString() As Char, _
ByVal nSize As Integer, _
ByVal lpFileName As String) As Integer

Sub Main()

Dim keyBuffer(2047) As Char
Dim copyBuffer As New StringBuilder
Dim keys As New StringCollection
Dim nullCount As Integer = 0

Dim charsCopied As Integer = _
GetPrivateProfileString(_
"Application Control", _
Nothing, _
"", _
keyBuffer, _
keyBuffer.Length, _
"VIC4.INI")

For i As Integer = 0 To charsCopied
If keyBuffer(i) <> vbNullChar Then
nullCount = 0
copyBuffer.Append(keyBuffer(i))
Else
keys.Add(copyBuffer.ToString())
copyBuffer.Length = 0
nullCount += 1
If nullCount > 1 Then
Exit For
End If
End If
Next

For Each key As String In keys
Console.WriteLine(key)
Next
End Sub

End Module

--
Tom Shelton [MVP]
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nijazi Halimaji | last post by:
Hi I know that what I am asking for is very simple, but as a newbie in VB.NET i have following 2 questions: Eigentlich ist das ja etwas ganz einfaches, aber für mich als VB.NET-Neuling doch...
4
by: News | last post by:
Hi Everyone, The attached code creates client connections to websphere queue managers and then processes an inquiry against them. The program functions when it gets options from the command...
1
by: Suresh | last post by:
Hi All, I am using DB2 UDB 8.1 on linux platform. I want to import or read .asc file from DB2 stored procedure. This file contains encryption and decryption key in multiple lines. I have...
7
by: cmfvulcanius | last post by:
I am using a script with a single file containing all data in multiple sections. Each section begins with "#VS:CMD:command:START" and ends with "#VS:CMD:command:STOP". There is a blank line in...
0
by: sarahgrace | last post by:
Hello everyone! I am doing some project in VB .NET in which there are duplicate keys but different data values in a INI file. I would like to the value of the value of the last key/data pair of...
6
by: Lang Murphy | last post by:
I'm baaaaack... some of you answered a question I had last week. Only problem is: I'm a dope who doesn't understand most of what y'all posted. Raw noob when it comes to .Net and C#. So I'm going...
0
by: Lucky | last post by:
Hi guys, I've got a problem under reading settlings from App.config file. I've used System.Configuration to reach to the "User Settings" and "Application Settings" sections. the problem is now...
0
by: Gary | last post by:
I'm having trouble entering Additional Registry Keys into my Package Solution that will deploy the Access 2007 runtime. (Client machine is running XP with Office 2007 Standard.) The Package...
5
by: ShadowLocke | last post by:
This class makes use of System.Collections.Hashtable to enumerate all the settings in an INI file for easy access. Its very simplistic, and completely re-useable. Solid addition for any app that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.