Click here to Skip to main content
15,844,152 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm writing a code which get value from configuration settings file (*.ini)

Here are the sample of item that I have in the *.ini:


I will retrieve this value using this code:

m_strMerch1 = m_IniMainObj.GetStrVal(INI_MERCHANT_1_KEY, String.Empty)
m_strMerch2 = m_IniMainObj.GetStrVal(INI_MERCHANT_2_KEY, String.Empty)
m_strMerch3 = m_IniMainObj.GetStrVal(INI_MERCHANT_3_KEY, String.Empty)

The value is current set into m_strXXXXX as string. But I want to read the string an want to separated the value with this:


so I can hold the value whether it is True or False for 1st comma, ID for 2nd comma and description for 3rd comma and I want to save it in a declaration

Dim bVisible as Boolean 'To hold 1st comma value (Boolean)
Dim strID as String 'To hold 2nd comma value (String)
Dim strDesc as String 'To hold 3r comma value (String)

Can someone please help me? I'm sorry if my question is quite messy but if you have some clearance, I will explain..

1 solution

Ok I think I understand what your asking about.

You have already got the information from your ini file, but want to store this info to do what you will with later?

Public Class Merchant
    Public bVisible As Boolean 'To hold 1st comma value (Boolean)
    Public strID As String 'To hold 2nd comma value (String)
    Public strDesc As String

    Public Sub New(ByVal p_visible As Boolean, ByVal p_id As String, ByVal p_desc As String)
        bVisible = p_visible
        strID = p_id
        strDesc = p_desc
    End Sub

End Class

That is a simple class to hold the details of a single merchant.

You could use a dictionary of merchants as below.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim merchants As Dictionary(Of String, Merchant)

       merchants = New Dictionary(Of String, Merchant)()

       merchants.Add("MERCH1", New Merchant(True, "P", "PAYMENT")) 'MERCH1=1,P,PAYMENT
       merchants.Add("MERCH2", New Merchant(False, "R", "ROADTAX")) 'MERCH2=0,R,ROADTAX
       merchants.Add("MERCH3", New Merchant(True, "S", "SUMMON")) 'MERCH3=1,S,SUMMON

       Dim merch3 As Merchant = merchants("MERCH3")

   End Sub

You can see that way you just need to tell the Dictionary of Merchants which Merchant you want to deal with.

Hope this helps!
Share this answer
Luiey Ichigo 24-Nov-12 4:00am    
Hey man,

Thank..btw I've just got another option for this..

Mybe someone will refer to this as well as yours.

Private Sub SetMerchantValue()
Dim strArr(2) As String
Dim strSplitter As Char = ","

strArr = objScreenSetting.Merchant1.Split(strSplitter)
clsGlobVars.strucMerchant.bMerch1 = strArr(0)
clsGlobVars.strucMerchant.strMerchID1 = strArr(1)
clsGlobVars.strucMerchant.strMerchName1 = strArr(2)

strArr = objScreenSetting.Merchant2.Split(strSplitter)
clsGlobVars.strucMerchant.bMerch2 = strArr(0)
clsGlobVars.strucMerchant.strMerchID2 = strArr(1)
clsGlobVars.strucMerchant.strMerchName2 = strArr(2)

strArr = objScreenSetting.Merchant3.Split(strSplitter)
clsGlobVars.strucMerchant.bMerch3 = strArr(0)
clsGlobVars.strucMerchant.strMerchID3 = strArr(1)
clsGlobVars.strucMerchant.strMerchName3 = strArr(2)

strArr = objScreenSetting.Merchant4.Split(strSplitter)
clsGlobVars.strucMerchant.bMerch4 = strArr(0)
clsGlobVars.strucMerchant.strMerchID4 = strArr(1)
clsGlobVars.strucMerchant.strMerchName4 = strArr(2)

strArr = objScreenSetting.Merchant5.Split(strSplitter)
clsGlobVars.strucMerchant.bMerch5 = strArr(0)
clsGlobVars.strucMerchant.strMerchID5 = strArr(1)
clsGlobVars.strucMerchant.strMerchName5 = strArr(2)

strArr = objScreenSetting.Merchant6.Split(strSplitter)
clsGlobVars.strucMerchant.bMerch6 = strArr(0)
clsGlobVars.strucMerchant.strMerchID6 = strArr(1)
clsGlobVars.strucMerchant.strMerchName6 = strArr(2)

strArr = objScreenSetting.Merchant7.Split(strSplitter)
clsGlobVars.strucMerchant.bMerch7 = strArr(0)
clsGlobVars.strucMerchant.strMerchID7 = strArr(1)
clsGlobVars.strucMerchant.strMerchName7 = strArr(2)

strArr = objScreenSetting.Merchant8.Split(strSplitter)
clsGlobVars.strucMerchant.bMerch8 = strArr(0)
clsGlobVars.strucMerchant.strMerchID8 = strArr(1)
clsGlobVars.strucMerchant.strMerchName8 = strArr(2)
Catch ex As Exception

End Try
End Sub

Thank again for helping me Rob

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