ASP and vbs

Associate
Joined
29 Dec 2004
Posts
159
Hi guys,

Im having problems checking textbox values, what i am trying to do is check the value in one textbox with another or maybe a label, then depending on the comparison change the backcolor and forecolor of the textbox. My apologies if you require more info its late and im tired hehe.

Code Below:


Private Sub myTextHandlerHole1(ByVal sender As Object, ByVal e As EventArgs)

Dim StrSender As Object
Dim strParName As Integer
Dim valPar As Integer
Dim strSenderText As Object

StrSender = sender.ID
StrSenderText = sender.ID & ".text"
valPar = Right(StrSender, 1)

strParName = (valPar)

Response.Write(strParName & " " & StrSender)


If strSenderText = (strParName) Then

StrSender.BackColor = Drawing.Color.Green
StrSender.ForeColor = Drawing.Color.White

ElseIf strSenderText = (strParName - 1) Then

StrSender.BackColor = Drawing.Color.LightBlue
StrSender.ForeColor = Drawing.Color.White

ElseIf strSenderText = (strParName + 1) Then

StrSender.BackColor = Drawing.Color.Black
StrSender.ForeColor = Drawing.Color.White

ElseIf strSenderText = (strParName - 2) Then

StrSender.BackColor = Drawing.Color.Yellow
StrSender.ForeColor = Drawing.Color.Black

End If

End Sub
 
You're assigning a string to an object reference and then compare it to an integer?

StrSenderText = sender.ID & ".text" assigns a string ending in ".text", which will never be equal to strParName (an integer). If you want to get the text property of sender, then you'll have to cast it to a type that has a text property and access it directly. Id you expect it to be numeric, then you should parse it as an integer.

First step should be to clean up the types there (get rid of object, use numeric types for numeric values and string for string values.) Then, if you set option strict on and option implicit off, so you'll get compiler warnings when you do silly things, like comparing a number to a string.
 
Last edited:
Thanks for the help, i ended up using a select case statement and depending on the value of sender modifying the properties of a different object not sure if this is the best way but it works.
 
Back
Top Bottom