can you make an array of properties?
-
this is my first post... im kinda new to VS.net, so take it easy ;P. i have only worked with the vb console apps to date. i was just wondering if there is a way to make an array out of a property procedure? i mean, i declare my property procedure named Score, which is a variable to store a test score, as a percentage. I want to have 3 test scores, and make an array so its easier later in the code when working with them. the reason i want a property method is so i can prevent scores > 100 and < 0. before using properties, i simply made a variable array named Score, storing 3 values of test scores. i want to do this exact same thing, but limiting input, using properties. this is what i have so far: Property Score() As single Get Return tempScore End Get Set(ByVal Value As String) If Value < 0 Then Console.WriteLine("Score average cannot be less than 0%.") tempScore = 0 ElseIf Value > 100 Then Console.WriteLine("Score average cannot be greater than 100%.") tempScore = 100 Else tempScore = Value End If End Set End Property ANY HELP is SINCERLY appreciated. sorry if its unclear, as im not used to this. Thank you. Jordan. III
-
this is my first post... im kinda new to VS.net, so take it easy ;P. i have only worked with the vb console apps to date. i was just wondering if there is a way to make an array out of a property procedure? i mean, i declare my property procedure named Score, which is a variable to store a test score, as a percentage. I want to have 3 test scores, and make an array so its easier later in the code when working with them. the reason i want a property method is so i can prevent scores > 100 and < 0. before using properties, i simply made a variable array named Score, storing 3 values of test scores. i want to do this exact same thing, but limiting input, using properties. this is what i have so far: Property Score() As single Get Return tempScore End Get Set(ByVal Value As String) If Value < 0 Then Console.WriteLine("Score average cannot be less than 0%.") tempScore = 0 ElseIf Value > 100 Then Console.WriteLine("Score average cannot be greater than 100%.") tempScore = 100 Else tempScore = Value End If End Set End Property ANY HELP is SINCERLY appreciated. sorry if its unclear, as im not used to this. Thank you. Jordan. III
ok.. i guess i got it working. here it is, if anyone cares: Private tempScore(3) As Integer Property score(ByVal i As Byte) As String Get Return tempScore(i) End Get Set(ByVal Value As String) If Value < 0 Then Console.WriteLine("Score average cannot be less than 0%.") tempScore(i) = 0 ElseIf Value > 100 Then Console.WriteLine("Score average cannot be greater than 100%.") tempScore(i) = 100 Else tempScore(i) = Value End If End Set End Property Jordan. III