Solved

VB.NET Property Value

Posted on 2009-04-07
4
148 Views
Last Modified: 2012-05-06
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
Comment
Question by:jimseiwert
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 24090362
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
 
LVL 2

Author Comment

by:jimseiwert
ID: 24090384
Can you show me an example please?
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 24090701
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
 
LVL 2

Author Closing Comment

by:jimseiwert
ID: 31567642
Just what I was looking for, Thanks !!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question