Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey, I've been bothering a little with this can't see to find a simple solution, all my codes get too messy.

So I want to hear you out for help.

I have a settings file with different catogorys like this:
[CATOGORY1]
settings here.
[CATOGORY2]
settings here.
[CATOGORY3]
settings here.
[CATOGORY4]
settings here.


I want to sperate them into 4 strings when reading the file like:
Dim catogory1 as String =
Dim catogory2 as String =
Dim catogory3 as String =
Dim catogory4 as String =

Can any help me with this?
Posted

Have a look at this: INI Reader / Writer Class for C#, VB.NET, and VBScript[^] It provides fuctions to read the section names ("CATOGORY1", etc. in your example), and to read all the keys within a section.

Read the section names, read all the keys, and you can build your strings with any separator or format you want!
 
Share this answer
 
Comments
Bebser 29-Mar-14 6:11am    
Looks nice, but it's way to advanced for what I want. I jsut want like a simple function
being like.
Function GetSection(ByVal As String)
'code here
Return Section
End Function

so you call call it like Dim catogory1 as string = GetSection(CATOGORY1)
OriginalGriff 29-Mar-14 6:21am    
It's because it's quite a complex function to do: using the library makes it a lot simpler than writing it from scratch.
Found this solution so simple:

VB
<DllImport("kernel32")> _
Private Shared Function GetPrivateProfileString(ByVal Section As String, ByVal Key As String, ByVal [Default] As String, ByVal RetVal As StringBuilder, ByVal Size As Integer, ByVal FilePath As String) As Integer
End Function
Public Function Read(ByVal Key As String, Optional ByVal Section As String = Nothing) As String
    Dim RetVal = New StringBuilder(255)
        GetPrivateProfileString(Section, Key, "", RetVal, 255, Path)
    Return RetVal.ToString()
End Function
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900