Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 [RESOLVED] Structure And Lists of Structures

$
0
0
Hi There

A project ive been working on recently is using a MySql Database, The host of which is fairly slow, its not unusable but its not as quick as id like. to that end i have decided to shed as many calls to the database as i can. The first way i can do that is by localising my user settings as the program is loading.

Code:


'I have set up this structure in a separate module

Public Structure UserSetting
        Public User As Integer
        Public SettingId As Integer
        Public Str As String
        Public Bool As Integer
End Structure

'I then publicly declare a new instance of a list of these structures on the same module

Public UserSettings As New List(Of UserSetting)

That list is then populated in the MyApplication startup event

Code:

      Private Sub mGetSettings()
            Dim dt As New DataTable
            DtSelect(dt, "SELECT * FROM Properties", "Settings")
            For Each dr As DataRow In dt.Rows
                Dim Us As New UserSetting

                Us.SettingId = dr("PropertyId")
                Dim vStr As String
                If IsDBNull(dr("StrValue")) Then
                    vStr = ""
                Else
                    vStr = dr("StrValue")
                End If
                Us.Str = vStr
                Dim vBool As Integer
                If IsDBNull(dr("BooValue")) Then
                    vBool = -1
                Else
                    vBool = dr("BooValue")
                End If
                Us.Bool = vBool
                UserSettings.Add(Us)
            Next
        End Sub

Obviously when the user changes a setting it needs to be saved to the list of user setting not the database, re syncing with the database occurs when the program is exited (BTW User settings here are more like how the user is filtering a certain set of results or how the results of that filter should look on a form)

Code:

Public Sub Save_UserSetting(ByVal SId As Integer, ByVal Setting As String, ByVal Type As String, Optional ByVal User As Integer = 0)
        Dim Found As Boolean = False
        For Each us As UserSetting In UserSettings
            If us.SettingId = SId Then
                Found = True
                us.User = User
                If Type <> "STR" Then
                    us.Bool = Setting
                    us.Str = ""
                Else
                    us.Str = Setting
                    us.Bool = -1
                End If
                If Found Then Exit For
            End If
        Next
        If Found = False Then
            Dim nUs As New UserSetting
            nUs.SettingId = SId
            nUs.User = User
            If Type <> "STR" Then
                nUs.Bool = Setting
                nUs.Str = ""
            Else
                nUs.Str = Setting
                nUs.Bool = -1
            End If
            UserSettings.Add(nUs)
        End If
    End Sub

the problem is on this method it doesn't commit any changes to the actual list, am i missing something fundamental here or is this is in fact not possible? i would have thought this would have been as easy as i had assumed

Well many thanks if you got this far i hope you can help :)

Ian

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>