Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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:
 
[MERCHANT]
SPLITTER=,
MERCH1=1,P,PAYMENT
MERCH2=0,R,ROADTAX
MERCH3=1,S,SUMMON
 
I will retrieve this value using this code:
 
m_IniMainObj.CurrentSection = INI_SCREENCFG_SECT_MERCHANT
m_strSplitter=m_IniMainObj.GetStrVal(INI_SPLITTER_KEY,"-")
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:
 
(1,P,PAYMENT)
(Boolean,String,String)
 
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..
Posted 12-Nov-12 3:12am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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")
       MsgBox(merch3.strDesc)
 
   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!
  Permalink  
Comments
Luiey Ichigo at 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 = ","
 
Try
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)

  Print Answers RSS
0 mhegazy94 460
1 Sergey Alexandrovich Kryukov 400
2 Kornfeld Eliyahu Peter 315
3 Gihan Liyanage 147
4 Sibeesh KV 145
0 Sergey Alexandrovich Kryukov 6,890
1 OriginalGriff 6,761
2 CPallini 5,350
3 George Jonsson 3,609
4 Gihan Liyanage 2,797


Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100