Properties not being assigned, unable to return values from Private as they are all zero (0) - vb.net

Not all properties are being assigned correctly. Yet two properties are working. Now, I am aware of the Public ReadOnly auto correction, but I prefer the old get/set method because it helps me to understand more thoroughly. I have in a separate file, another class BusinessLogic:
Public Class BusinessLogic
Private _totalPiecesOfAllUsers As Integer
Private _totalCountOfUsers As Integer
Private _totalEarningsOfAllUsers As Decimal
Private _totalAverageOfAllUsers As Decimal
Private _name As String
Private _pieces As String
Private _individualEarning As Decimal
Public Property TotalPiecesOfAllUsers() As Integer
Get
Return _totalPiecesOfAllUsers
End Get
Set
_totalPiecesOfAllUsers += _pieces
End Set
End Property
Public Property TotalCountOfUsers() As Integer
Get
Return _totalCountOfUsers
End Get
Set
_totalCountOfUsers = value
End Set
End Property
Public Property TotalEarningsOfAllUsers() As Decimal
Get
Return _totalEarningsOfAllUsers
End Get
Set(ByVal value As Decimal)
_totalEarningsOfAllUsers = value
End Set
End Property
Public Property TotalAverageOfAllUsers() As Decimal
Get
Return _totalAverageOfAllUsers
End Get
Set(ByVal value As Decimal)
_totalAverageOfAllUsers = value
End Set
End Property
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Property Pieces() As Integer
Get
Return _pieces
End Get
Set(ByVal value As Integer)
_pieces = value
End Set
End Property
Public Property IndividualEarning() As Decimal
Get
Return _individualEarning
End Get
Set(ByVal value As Decimal)
_individualEarning = value
End Set
End Property
End Class
And then my Form1
Private Sub CalcPayToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CalcPayToolStripMenuItem.Click
Try
' Create Object
Dim blog As New BusinessLogic
If tbName.Text <> String.Empty And tbPieces.Text <> String.Empty Then
' Get Transactions Per User
blog.Name = tbName.Text
blog.Pieces = Integer.Parse(tbPieces.Text)
blog.IndividualEarning = CalculatePieces(blog.Pieces)
' Counter Per User
blog.TotalCountOfUsers += 1
' Get Total of all users
blog.TotalPiecesOfAllUsers += blog.Pieces
blog.TotalEarningsOfAllUsers += blog.IndividualEarning
blog.TotalAverageOfAllUsers += (blog.TotalEarningsOfAllUsers / blog.TotalCountOfUsers)
Else
' SHow error if field is empty
MsgBox("Name and/or Piece count required")
End If
' Assign asmount earned txtbox the calculated value
lblAmountEarned.Text = FormatCurrency(blog.IndividualEarning)
Catch exc As Exception
' Show error if triggered
MsgBox("Error processing data, values may be empty or incorrect.")
End Try
End Sub
Public Function CalculatePieces(ByVal p As Decimal) As Decimal
' For piece claculation
Dim earningsByPiece As Decimal = 0D
' If pieces fall within range 1-199
If p >= 1 And p <= 199 Then
earningsByPiece = p * 0.5
' If pieces fall within range 200-399
ElseIf p >= 200 And p <= 399 Then
earningsByPiece = p * 0.55
' If pieces fall within range 100-599
ElseIf p >= 400 And p <= 599 Then
earningsByPiece = p * 0.6
' If pieces fall out of 600 range
ElseIf p >= 600 Then
earningsByPiece = p * 0.65
End If
Return earningsByPiece
End Function
Somehow it returns the IndividualEarning, but when I set a break in the BusinessLogic, none of the vraiables are holding anything.

You have started on the wrong foot. Reworking this code, I would start with a class called User. I added a custom constructor so you can add a new user in a single line of code. Then I added back the default constructor.
Public Class User
Public Property Name() As String
Public Property Pieces() As Integer
Public Property IndividualEarning() As Decimal
Public Sub New()
End Sub
Public Sub New(nme As String, pcs As Integer, earnings As Decimal)
Name = nme
Pieces = pcs
IndividualEarning = earnings
End Sub
End Class
Then I created a business logic class to hold the rest of the information. The properties are Shared so they are the same whenever the class is referenced. There is no need to create an instance when you are accessing shared members. Just refer to them with the class name.
Public Class BL
Public Shared Property TotalPiecesOfAllUsers() As Integer
Public Shared Property TotalCountOfUsers() As Integer
Public Shared Property TotalEarningsOfAllUsers() As Decimal
Public Shared Property TotalAverageOfAllUsers() As Decimal
End Class
Then in the Form I created a List(Of User) to hold your User objects.
Now, when you create a User, even though the u will fall out of scope, the user is safely tucked away in the list with the .Add method.
Every time you adjust the contents of the list you call CalculateTotalsAndAverage to keep your BL class up to date.
Dim lst As New List(Of User)
Private Sub CalcPayToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CalcPayToolStripMenuItem.Click
'Validate input
If tbName.Text = "" Then
MessageBox.Show("Please enter a name")
Exit Sub
End If
Dim pcs As Integer
If Not Integer.TryParse(tbPieces.Text, pcs) Then
MessageBox.Show("Please enter a valid number of pieces")
Exit Sub
End If
Dim u As New User
u.Name = tbName.Text
u.Pieces = pcs
u.IndividualEarning = CalculatePieces(pcs)
lst.Add(u)
CalculateTotalsAndAverage()
lblAmountEarned.Text = FormatCurrency(u.IndividualEarning)
End Sub
Public Function CalculatePieces(ByVal p As Integer) As Decimal
Dim earnings As Decimal = 0D
Select Case p
Case 1 To 199
earnings = p * 0.5D
Case 200 To 399
earnings = p * 0.55D
Case 400 To 599
earnings = p * 0.6D
Case Else
earnings = p * 0.65D
End Select
Return earnings
End Function
Private Sub CalculateTotalsAndAverage()
BL.TotalAverageOfAllUsers = lst.Average(Function(u) u.IndividualEarning)
BL.TotalPiecesOfAllUsers = lst.Sum(Function(u) u.Pieces)
BL.TotalCountOfUsers = lst.Count
BL.TotalEarningsOfAllUsers = lst.Sum(Function(u) u.IndividualEarning)
Debug.Print($"Average {BL.TotalAverageOfAllUsers} Total Pieces {BL.TotalPiecesOfAllUsers} Total Earnings {BL.TotalEarningsOfAllUsers}")
End Sub

Related

How to use GetType and GetFields?

I'm updating a program and there is about 40 classes. I need to create a function that takes two lists of type object as parameters. Both lists only have one item in them (A version of the item BEFORE any changes were made, and AFTER the changes happened). I'm using these objects to create a single object to implement an UNDO button. With these parameters I need to get the type of each and make sure they match, if not then something went wrong. Next I'll need to read in the fields/properties/members (Not sure what to choose) and then compare them to each other and find what changed so I can set that as the item description. I don't want to trace the whole code and add specific functions for each and I know there has got to be a way to do this generically. I have created this small mock-up program that semi works for what I am trying to do. I can get the class type out of the object in list, but i have no idea how to get fields or whatever.
I'm using a large database with entity framework.
Also Using VB.NET!
Thanks for the help!
Here's code for generic program:
Imports System.Reflection
Module Module1
Sub Main()
Dim Myself As New Human("Matthew", "Cucco", Now, "Blonde", 19, False)
Dim NotMe As New Human("Jake", "Cucco", Now, "Blonde", 19, False)
Dim Him As New Employee("Matt", "Cucco", Now, "Blonde", 19, False, 215, "LuK", True)
Dim Her As New Customer("Jessie", "Keller", Now, "Blonde", 19, True, 25, "Cereal", "me#gmail.com")
Dim ListofPeople As IList(Of Object) = {Myself, NotMe, Him, Her}
Dim ListofPeople2 As IList(Of Object) = {Myself, NotMe, Him, Her}
ObjectsAreSameClass(ListofPeople, ListofPeople2)
Console.ReadKey()
End Sub
Private Function ObjectsAreSameClass(object1 As IList(Of Object), object2 As IList(Of Object)) As Boolean
Dim ObjectType As Type = object1.First.GetType()
Dim AreSameClass As Boolean = Nothing
Console.WriteLine(ObjectType.ToString)
If (object1.First.GetType() = object2.First.GetType()) Then
AreSameClass = True
Console.WriteLine("Object1 is of type: " + object1.First.GetType().Name)
Console.WriteLine("Object2 is of type: " + object2.First.GetType().Name)
If (object1.First.GetType().Name = "Human") Then
Console.WriteLine("Yep this works")
End If
Else
AreSameClass = False
Console.WriteLine("Object1 is of type: " + object1.First.GetType().Name)
Console.WriteLine("Object2 is of type: " + object2.First.GetType().Name)
If (object1.First.GetType().Name = "Human") Then
Console.WriteLine("Yep this works")
Console.WriteLine(object1.First.GetType().GetFields().ToString)
End If
End If
Dim MyField As PropertyInfo() = ObjectType.GetProperties()
Dim i As Integer
For i = 0 To MyField.Length - 1
Console.WriteLine(MyField(i).ToString)
Next i
Console.WriteLine("Objects are equal? t/f : " + AreSameClass.ToString)
Return AreSameClass
End Function
Public Class Human
Public FirstName As String
Public LastName As String
Public Birthdate As Date
Public HairColor As String
Public Age As Integer
Public Gender As Boolean 'False for male, true for female
Public Sub New()
FirstName = ""
LastName = ""
Birthdate = Now
HairColor = ""
Age = 0
Gender = False
End Sub
Public Sub New(f As String, l As String, b As Date, h As String, a As Integer, g As Boolean)
FirstName = f
LastName = l
Birthdate = b
HairColor = h
Age = a
Gender = g
End Sub
End Class
Public Class Employee
Inherits Human
Dim EmployeeId As Integer
Dim PlaceOfEmployment As String
Dim IsManager As Boolean
Public Sub New()
MyBase.New()
EmployeeId = 0
PlaceOfEmployment = ""
IsManager = False
End Sub
Public Sub New(f As String, l As String, b As Date, h As String, a As Integer, g As Boolean, i As Integer, p As String, m As Boolean)
MyBase.New(f, l, b, h, a, g)
EmployeeId = i
PlaceOfEmployment = p
IsManager = m
End Sub
End Class
Public Class Customer
Inherits Human
'used for testing
Dim IdNumber As Integer
Dim FavoriteItem As String
Dim email As String
Public Sub New()
MyBase.New()
IdNumber = 0
FavoriteItem = ""
email = ""
End Sub
Public Sub New(f As String, l As String, b As Date, h As String, a As Integer, g As Boolean, i As Integer, fav As String, e As String)
MyBase.New(f, l, b, h, a, g)
IdNumber = i
FavoriteItem = fav
email = e
End Sub
End Class
End Module
This Currently displays this:
TestProject.Module1+Human
Object1 is of type: Human
Object2 is of type: Human
Yep this works
Objects are equal? t/f : True
Also for reference, here is my main program that I will be implementing this into:
Function NewItem(Before As IEnumerable(Of Object), After As IEnumerable(Of Object), ObjectType As String)
ObjectsAreSameClass(Before, After, ObjectType) 'Check if objects are same class
Dim BeforeFields() As FieldInfo = GetFieldData(Before) 'gets all field info, saves to an array
Dim AfterFields() As FieldInfo = GetFieldData(After)
'Now check and make sure the objects are not the same
Dim ThisChanged As FieldInfo
If (ObjectValuesAreEqual(BeforeFields, AfterFields) = True) Then
'These objects did not not change
ThisChanged = Nothing
Else
'Change occured, find out where
ThisChanged = FindWhatChanged(BeforeFields, AfterFields)
End If
'Create a new UndoRedo item and give it these values
Dim UndoRedoNow As New ClsUndoRedo
UndoRedoNow.BeforeObject = Before.Single
UndoRedoNow.AfterObject = After.Single
UndoRedoNow.ObjectCounter += 1
UndoRedoNow.WhatChanged = ThisChanged
If WhatGroupChanged.isDeleted Then
UndoRedoNow.WhatAction = Before.Single.GetType().ToString + " item was Deleted"
ElseIf WhatGroupChanged.isNew Then
UndoRedoNow.WhatAction = After.Single.GetType().ToString + " item was created"
ElseIf WhatGroupChanged.isChanged Then
UndoRedoNow.WhatAction = After.Single.GetType().ToString + " item was changed"
End If
UndoRedoNow.WhatGroupChanged.isRedo = False 'Make sure it is not a redo object
'Now add object to list
ChangeLog.Add(UndoRedoNow)
Return Nothing
End Function
Private Function ObjectsAreSameClass(before As IEnumerable(Of Object), after As IEnumerable(Of Object), WhatType As String) As Boolean
Dim AreSameClass As Boolean = False
Try
If (before.Single.GetType() = after.Single.GetType() Or (before Is Nothing) Or (after Is Nothing)) Then
'Objects are of the same class or nothing
If before Is Nothing Then
WhatGroupChanged.isNew = True 'New item
ElseIf after Is Nothing Then
WhatGroupChanged.isDeleted = True 'Deleted item
Else
WhatGroupChanged.isChanged = True 'item was changed
End If
AreSameClass = True
End If
Catch
'Need to raise error
End Try
Return AreSameClass
End Function
''' <summary>
''' This function will return all of the fields for a certain class as well as the data stored in them
''' </summary>
''' <param name="list"></param>
''' <returns></returns>
Public Shared Function GetFieldData(ByVal list As IList(Of Object)) As FieldInfo()
Dim fields() As FieldInfo = list.Single.GetType().GetFields()
Return fields
End Function
''' <summary>
''' This function will check that the values in the datafields are not equal
''' </summary>
''' <param name="Before"></param>
''' <param name="After"></param>
''' <returns></returns>
Private Function ObjectValuesAreEqual(Before() As FieldInfo, After() As FieldInfo) As Boolean
Dim isEqual As Boolean = New Boolean 'This will keep track of if the elements are equal or not
For index As Integer = 0 To (Before.Count - 1)
If Before.ElementAt(index).GetValue(Before.ElementAt(index)).Equals(After.ElementAt(index).GetValue(After.ElementAt(index))) Then
'They are equal so set to true
isEqual = True
Else
'They are not equal so set to false and return
isEqual = False
Return isEqual
End If
Next
Return isEqual
End Function
Private Function FindWhatChanged(Before() As FieldInfo, After() As FieldInfo) As FieldInfo
Dim ThisIsChange As FieldInfo
For index As Integer = 0 To (Before.Count - 1)
If Before.ElementAt(index).GetValue(Before.ElementAt(index)).Equals(After.ElementAt(index).GetValue(After.ElementAt(index))) Then
ThisIsChange = After.ElementAt(index)
Return ThisIsChange
Else
'Raise error
End If
Next
End Function
The proper way to preserve type information when working with unknown types is to write a generic function (and if necessary generic classes, structures, etc.).
Using GetType, in a perfect world, should never be needed.
Generic functions look like this:
Public Function MyGenericFunction(Of T)(myArg as T) as Integer
' do something with myArg1, myArg2 ... without knowing their exact type
Return 0
End Function
' or with multiple types
Public Function MyGenericFunction2(Of T1, T2, ... )(myArg1 as T1, myArg2 as T2, ...) as T1()
' do something with myArg1, myArg2 ... without knowing their exact type
Return { myArg1 }
End Function
When you call these functions, the generic types are usually automatically deduced from the arguments you passed. If they can't be guessed, you will need to explicitly annotate the types, like this:
Dim x = MyGenericFunction(Of SomeClass1)(foo)
Dim x = MyGenericFunction(Of SomeClass2)(foo)
A full guide here: https://msdn.microsoft.com/en-us/library/w256ka79.aspx
However, if you need to handle specific types with the same function, then what you want to do use is a more narrow tool: overloading, or more technically parametric polymorphism.
What that means is, you will need to provide two (or more) different definitions of the same function ( = having the same name), that accept parameters of different types.
A simple example:
Public Class MyClass1
Public Foo1 As String = "foo1"
End Class
Public Class MyClass2
Public Foo2 As String = "foo2"
End Class
Public Sub MyFunction(arg as MyClass1)
Console.WriteLine(arg.Foo1)
End Sub
Public Sub MyFunction(arg as MyClass2)
Console.WriteLine(arg.Foo2)
End Sub
Dim x as Object
' let's give x a random value of either MyClass1 or MyClass2,
' and we don't know in advance which one
If DateTime.Today.DayOfWeek = DayOfWeek.Tuesday Then
x = new MyClass1
Else
x = new MyClass2
End If
' the program will automatically invoke the correct function based on x's value, and print either "foo1" or "foo2"
MyFunction(x)

Arrays with Stringand integer

I want to print the array - filetable 1. I have used a class to define 'Data'
can somebody help with the syntax to print this array in a text file Tx
Dim filetable1 As New List(Of Data)
For x = 0 To (lineCount1 - 2)
'''''c = 1
Array.Sort(file1items)
If file1items(x) = file1items(x + 1) Then
c = c + 1
Else
c = 1
filetable1.Add(New Data(file1items(x), c))
End If
Next
Public Class Data
Public PN As String
Public Count As Integer
Public Property Name() As String
Get
' Gets the property value.
Return PN
End Get
Set(ByVal Value As String)
' Sets the property value.
PN = Value
End Set
End Property
Public Property ct() As Integer
Get
' Gets the property value.
Return Count
End Get
Set(ByVal Value As Integer)
' Sets the property value.
Count = Value
End Set
End Property
Public Sub Capitalize()
' Capitalize the value of the property.
PN = UCase(PN)
Count = UCase(Count)
End Sub
Public Sub New(PName As String, ct1 As Integer)
Name = PName
ct = ct1
End Sub
End Class

"Expression of type "" is not queryable" error

I'm attempting to get an assignment done for class and have hit this error:
Error 1 Expression of type 'Homework_Code_Examples.Form1.State' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider. D:\Users\Stryke\Documents\Visual Studio 2013\Projects\Homework Code Examples\Homework Code Examples\Form1.vb 11 32 Homework Code Examples
I've never encountered this before and searching via Google, MSDN and these forums all tell me that I must target the correct .NET framework for my program, however I am completely lost as to which framework I should target as the recommended answers all give the same error upon being recompiled. Currently, I am using .NET Framework 4.5 in Visual Studio 2013.
I don't know if it helps at all or not, but here is my code so that you may see what it is I'm trying to achieve...
Public Class Form1
Dim states As State
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
states = New State()
Dim query = From st In states
Let name = states.Name
Let density = states.Density()
Order By density Descending
Select name, density
End Sub
Private Sub stateInfo_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles stateInfo.CellContentClick
End Sub
Class State
Private m_name, m_abbr, m_date As String
Private m_area, m_pop As Integer
Public Property Name()
Get
Return m_name
End Get
Set(value)
m_name = value
End Set
End Property
Public Property Abbreviation()
Get
Return m_abbr
End Get
Set(value)
m_abbr = value
End Set
End Property
Public Property joinDate()
Get
Return m_date
End Get
Set(value)
m_date = value
End Set
End Property
Public Property landArea
Get
Return m_area
End Get
Set(value)
m_area = value
End Set
End Property
Public Property Population
Get
Return m_pop
End Get
Set(value)
m_pop = value
End Set
End Property
Public Function Density()
Dim popDensity As Integer
popDensity = Population / landArea
Return popDensity
End Function
End Class
End Class
Linq needs to iterate through multiple objects. In your case, it can be list or collection of State class.
Example with List(Of Type)
Change line
Dim states As State
to
Dim states As List(Of State)
and
states = New State()
into
states = New List(Of State)
Example with array
Change line
Dim states As State
to
Dim states() As State
and
states = New State()
into
ReDim states(10) 'or use a variable inside
Here's a sample of how to populate your data. I also fix some error in your query. Compare your query to mine to see what I changed.
' initialize a list with some values
Dim states = New List(Of State) From {
New State With {.Name = "Ohio", .Population = 10000, .landArea = 10},
New State With {.Name = "Texas", .Population = 20000, .landArea = 300},
New State With {.Name = "Florida", .Population = 5000, .landArea = 1000}
}
' query the list
Dim query = From st In states
Let name = st.Name
Let density = st.Density()
Order By density Descending
Select name, density
I also improve your State class to use proper data type instead of object.
Class State
Private m_name, m_abbr, m_date As String
Private m_area, m_pop As Integer
Public Property Name As String
Get
Return m_name
End Get
Set (value As String)
m_name = value
End Set
End Property
Public Property Abbreviation As String
Get
Return m_abbr
End Get
Set(value As String)
m_abbr = value
End Set
End Property
Public Property joinDate As String
Get
Return m_date
End Get
Set(value As String)
m_date = value
End Set
End Property
Public Property landArea As Integer
Get
Return m_area
End Get
Set(value As Integer)
m_area = value
End Set
End Property
Public Property Population As Integer
Get
Return m_pop
End Get
Set(value As Integer)
m_pop = value
End Set
End Property
Public Function Density() As Double
Dim popDensity As Double
popDensity = Population / landArea
Return popDensity
End Function
End Class

How to access class properties outside the constructor

I'm trying to retrieve my other football attributes (crossing, dribbling, finishing, ball control) that haven't been requested as arguments in the constructor- reportID, playerID and comments are all that are required.
There are over 20 football attributes, so I've just included the first few for readability.
Report Class:
Public Class Report
Public Sub New(ByVal reportID As Integer, ByVal playerID As Integer, ByVal comments As String)
_ReportID = reportID
_PlayerID = playerID
_Comments = comments
End Sub
Private _ReportID As Integer = 0
Private _PlayerID As Integer = 0
Private _Comments As String = ""
Private _Crossing As Integer = 0
Private _Dribbling As Integer = 0
Private _Finishing As Integer = 0
Private _BallControl As Integer = 0
Public Property ReportID() As Integer
Get
Return _ReportID
End Get
Set(ByVal value As Integer)
_ReportID = value
End Set
End Property
Public Property PlayerID() As Integer
Get
Return _PlayerID
End Get
Set(ByVal value As Integer)
_PlayerID = value
End Set
End Property
Public Property Comments() As String
Get
Return _Comments
End Get
Set(ByVal value As String)
_Comments = value
End Set
End Property
Public Property Crossing() As Integer
Get
Return _Crossing
End Get
Set(ByVal value As Integer)
_Crossing = value
End Set
End Property
Public Property Dribbling() As Integer
Get
Return _Dribbling
End Get
Set(ByVal value As Integer)
_Dribbling = value
End Set
End Property
Public Property Finishing() As Integer
Get
Return _Finishing
End Get
Set(ByVal value As Integer)
_Finishing = value
End Set
End Property
Public Property BallControl() As Integer
Get
Return _BallControl
End Get
Set(ByVal value As Integer)
_BallControl = value
End Set
End Property
End Class
Below I realise I'm only adding reportID, playerID and comments to my typeList, which is why I'm getting all 0's for my other attributes. How do access the attributes as well?
Retrieving the data:
Private Function retrieveReport() As List(Of Report)
Dim typeList As New List(Of Report)
Dim Str As String = "SELECT * FROM Report ORDER BY PlayerID"
Try
Using conn As New SqlClient.SqlConnection(DBConnection)
conn.Open()
Using cmdQuery As New SqlClient.SqlCommand(Str, conn)
Using drResult As SqlClient.SqlDataReader = cmdQuery.ExecuteReader()
While drResult.Read
typeList.Add(New Report(drResult("ReportID"), drResult("PlayerID"), drResult("Comments")))
End While
End Using 'Automatically closes connection
End Using
End Using
Catch ex As Exception
MsgBox("Report Exception: " & ex.Message & vbNewLine & Str)
End Try
Return typeList
End Function
Private Sub setReport()
For Each rpt As Report In retrieveReport()
'*****General Information
UC_Menu_Scout1.txtComments.Text = rpt.Comments
'*****Technical
UC_Menu_Scout1.UcAttributes1.lblXCrossing.Text = rpt.Crossing
UC_Menu_Scout1.UcAttributes1.lblXDribbling.Text = rpt.Dribbling
UC_Menu_Scout1.UcAttributes1.lblXFinishing.Text = rpt.Finishing
UC_Menu_Scout1.UcAttributes1.lblXBallControl.Text = rpt.BallControl
UC_Menu_Scout1.UcAttributes1.lblXPassing.Text = rpt.Passing
UC_Menu_Scout1.UcAttributes1.lblXHeadingAccuracy.Text = rpt.HeadingAccuracy
UC_Menu_Scout1.UcAttributes1.lblXMarking.Text = rpt.Marking
UC_Menu_Scout1.UcAttributes1.lblXTackling.Text = rpt.Tackling
'*****Mental
UC_Menu_Scout1.UcAttributes1.lblXAggression.Text = rpt.Aggression
UC_Menu_Scout1.UcAttributes1.lblXPositioning.Text = rpt.Positioning
UC_Menu_Scout1.UcAttributes1.lblXAnticipation.Text = rpt.Anticipation
UC_Menu_Scout1.UcAttributes1.lblXComposure.Text = rpt.Composure
UC_Menu_Scout1.UcAttributes1.lblXVision.Text = rpt.Vision
UC_Menu_Scout1.UcAttributes1.lblXTeamwork.Text = rpt.Teamwork
UC_Menu_Scout1.UcAttributes1.lblXWorkRate.Text = rpt.WorkRate
'*****Physical
UC_Menu_Scout1.UcAttributes1.lblXPace.Text = rpt.Pace
UC_Menu_Scout1.UcAttributes1.lblXBalance.Text = rpt.Balance
UC_Menu_Scout1.UcAttributes1.lblXJumping.Text = rpt.Jumping
UC_Menu_Scout1.UcAttributes1.lblXStrength.Text = rpt.Strength
UC_Menu_Scout1.UcAttributes1.lblXStamina.Text = rpt.Stamina
Next
End Sub
I imagine it's not that hard, so any help would be appreciated please!
To add values to the properties, use With:
typeList.Add(New Report(drResult("ReportID"), drResult("PlayerID"), drResult("Comments")) With {.BallControl = drResult("BallControl"), .Dribbling = drResult("Dribbling")})
You need to assign the property values that you aren't providing to the constructor as arguments, or you can add arguments to the constructor. Try this -- instead of calling the constructor like this:
typeList.Add(New Report(drResult("ReportID"), drResult("PlayerID"), drResult("Comments")))
instead, do this:
dim rep = New Report(drResult("ReportID"), drResult("PlayerID"), drResult("Comments"))
.Crossing = drResult("Crossing")
'additional property assignments
With rep
End With
typeList.Add(rep)

Error says x is not a member of y, but it is

I have a sp that I added to my linq designer, which generated the result class:
Partial Public Class web_GetTweetsByUserIDResult
Private _userid As Integer
Private _tweetid As Integer
Private _TweeterFeed As String
Public Sub New()
MyBase.New
End Sub
<Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_userid", DbType:="Int NOT NULL")> _
Public Property userid() As Integer
Get
Return Me._userid
End Get
Set
If ((Me._userid = value) _
= false) Then
Me._userid = value
End If
End Set
End Property
<Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_tweetid", DbType:="Int NOT NULL")> _
Public Property tweetid() As Integer
Get
Return Me._tweetid
End Get
Set
If ((Me._tweetid = value) _
= false) Then
Me._tweetid = value
End If
End Set
End Property
<Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_TweeterFeed", DbType:="NVarChar(100)")> _
Public Property TweeterFeed() As String
Get
Return Me._TweeterFeed
End Get
Set
If (String.Equals(Me._TweeterFeed, value) = false) Then
Me._TweeterFeed = value
End If
End Set
End Property
End Class
However, in this one section of code where I am trying to use the "TweeterFeed" member of the result class I am getting the error, "Error 4 'TweeterFeed' is not a member of 'System.Data.Linq.ISingleResult(Of web_GetTweetsByUserIDResult)'."
My code in this section is, :
<WebMethod()> _
Public Function GetTweetsByUserID(ByVal userID As Integer) As List(Of SimpleTweet)
Dim result As New List(Of SimpleTweet)
Dim urlTwitter As String = "https://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name={0}&count=20"
Dim lq As New lqDFDataContext
Dim var = lq.web_GetTweetsByUserID(userID).ToList()
If Not var Is Nothing Then
For Each twitterfeed In var
Dim listURL As String = String.Format(urlTwitter, var.TweeterFeed)
Dim tweetXML As XmlDocument = utils.GetXMLForURL(listURL)
Dim tweetnodelist As XmlNodeList = tweetXML.ChildNodes(1).ChildNodes
For Each node As XmlNode In tweetnodelist
Dim tweet As New SimpleTweet
tweet.CreatedAt = node.SelectSingleNode("created_at").InnerText
tweet.HTMLText = utils.ReturnTextWithHRefLink(node.SelectSingleNode("text").InnerText)
tweet.ID = node.SelectSingleNode("id").InnerText
tweet.Name = node.SelectSingleNode("user/name").InnerText
tweet.ScreenName = node.SelectSingleNode("user/screen_name").InnerText
tweet.Text = node.SelectSingleNode("text").InnerText
tweet.UserID = node.SelectSingleNode("user/id").InnerText
tweet.ProfileImageURL = node.SelectSingleNode("user/profile_image_url_https").InnerText
result.Add(tweet)
Next
Next
End If
Return result
End Function
Does anyone have any idea what is going on? As far as I see "TweeterFeed" is clearly a member of the class, I can't figure out why I would be getting this error.
You're using var.TweeterFeed when you should be using twitterFeed.TweeterFeed. twitterFeed is a result extracted from var which is a sequence of results.
Using a more descriptive variable name than var would probably have made this clearer to you :)
I have this class
Public Class Tamano
Private pWidth As Integer
Private pHeight As Integer
Public Property Width As Integer
Public Property Height As Integer
End Class
I got the compilation error message 'Height' is not a member of 'TamaƱo' in IIS
To fix it, add Set and Get to the properties and it compiles.
Public Class Tamano
Private pWidth As Integer
Private pHeight As Integer
Public Property Width As Integer
Get
Return pWidth
End Get
Set(value As Integer)
pWidth = value
End Set
End Property
Public Property Height As Integer
Get
Return pHeight
End Get
Set(value As Integer)
pHeight = value
End Set
End Property
End Class
This might not be directly related to your question but It might help someone else.