• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

VB.NET Property Value

I have to load some values from a sql table into my application and reuse them often. I have seen it before and was wondering how I would go about it. What I am looking to do is store my values and call them the following ways

for each sensor blah blah blah
     msgbox(sensors.field1)
     msgbox(sensors.field2)
     msgbox(sensors.field3)
next
0
jimseiwert
Asked:
jimseiwert
  • 2
  • 2
1 Solution
 
jpaulinoCommented:
You can create a class for that with the properties you need. Then you can create a new list(generics) of that class and use that way
0
 
jimseiwertAuthor Commented:
Can you show me an example please?
0
 
jpaulinoCommented:
Sure ... heres a generic example
Public Class Form1
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim myList As New List(Of myInformation)
 
        Dim item1 As New myInformation
        item1.Field1 = "jpaulino"
        item1.Field2 = 1
        myList.Add(item1)
 
        Dim item2 As New myInformation With {.Field1 = "Another method", .Field2 = 2}
        myList.Add(item2)
 
        For Each item As myInformation In myList
            Debug.WriteLine(item.Field1 & " - " & item.Field2)
        Next
 
    End Sub
 
End Class
 
 
' The Class
Class myInformation
 
    Private m_Field1 As String
    Public Property Field1() As String
        Get
            Return m_Field1
        End Get
        Set(ByVal value As String)
            m_Field1 = value
        End Set
    End Property
 
    Private m_Field2 As Integer
    Public Property Field2() As Integer
        Get
            Return m_Field2
        End Get
        Set(ByVal value As Integer)
            m_Field2 = value
        End Set
    End Property
 
End Class

Open in new window

0
 
jimseiwertAuthor Commented:
Just what I was looking for, Thanks !!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now