how to pass application setting by value to a public procedure or function?

ridhwaans

Active member
Joined
Jun 1, 2012
Messages
34
Programming Experience
3-5
Suppose I have an application setting of type System.Collections.Specialized.StringCollection called listA.
What ByVal type is needed for declaring it? (i.e. public sub saveData (byVal list as ____?)

VB.net doesnt allow a particular or certain application setting to be passed or received as arguments?
It only seems to have MySettings or My.MySettings which pass all settings but not individual application setting?
 
As you said yourself, type is System.Collections.Specialized.StringCollection.
 
Hi John
Thanks for replying, the parameter type is correct
But now the error is that in the public procedure, I cannot seem to save it to my.settings

this is the code

Public Sub saveListData(ByVal listData As System.Collections.Specialized.StringCollection)
My.Settings.listData.Clear() <------error listdata is not a member of myproject.my.mysettings

For Each item In lstProjects.Items
My.Settings.listData.Add(item.SubItems(0).Text & "," & item.SubItems(1).Text)
Next

For Each item In lstReportingProjects.Items
My.Settings.listData.Add(item.SubItems(0).Text & "," & item.SubItems(1).Text)
Next

My.Settings.Save()
end sub

I know why the error occurs, because I have got five lists (list1,list2...list5) and each have their own System.Collections.Specialized.StringCollection setting
but when I receive the argument as name 'listdata' in the saveListData procedure, its not a member (its not defined in application settings)

What to do? please advise

thanks
 
If you're going to pass that list, then use that list in procedure also.
VB.NET:
Public Sub saveListData(ByVal [COLOR="#00FF00"]theList[/COLOR] As System.Collections.Specialized.StringCollection)
    [COLOR="#00FF00"]theList[/COLOR].Clear()

    For Each item In lstProjects.Items
        [COLOR="#00FF00"]theList[/COLOR].Add(item.SubItems(0).Text & "," & item.SubItems(1).Text)
    Next
...
The only thing that reference can't do is to call My.Settings.Save, but default project settings for application framework has "Save My.Settings on Shutdown" by default so that should not be necessary. If it was you could call My.Settings.Save explicitly yourself before shutdown.
 
Back
Top