Late binding problem

i have a problem about late binding. highlighted in red. anyway what is late binding?

Private Sub IP_input_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_IPinput1.TextChanged, txt_IPinput4.TextChanged, txt_IPinput3.TextChanged, txt_IPinput2.TextChanged

Dim control As TextBox = CType(sender, TextBox)


' if length is 3 then focus next control
Ifsender.Text.Length = 3 Then
Call focusNext()
End If

End Sub
[1685 byte] By [IceAngel89] at [2007-12-28]
# 1

Hi,

Checks to see if 3 characters have been entered in each textbox and if TRUE sets the focus to the next control in the hierachy.

By the nature of the Sub name above it is allowing 3 characters to be entered at the most as in inputting an IP address into separate textboxes without the dots.

However it doesn't check if the input is a mixture of letters and numbers or just letters

i.e. non-numeric or whether the value entered exceeds 255.

Private Sub IP_input_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) _

Handles txt_IPinput1.TextChanged, txt_IPinput2.TextChanged, _

txt_IPinput3.TextChanged, txt_IPinput4.TextChanged



Dim myControl As TextBox = CType(sender, TextBox)



' If length is 3 then focus next control

If isnumeric(myControl.text)=True And _

Cint(myControl.text)>=0 And _

Cint(myControl.text)<=255 And _

myControl.text.Length = 3 Then

Call focusNext()

Else

CintMsgBox("Please enter a number as a string as only between 000 & 255")


End If


End Sub

The above modified code should work better for IP input.

Regards,

S_DS.

Spidermans_DarkSide at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

Although the above will improve your code it doesn't sort out your problem which arises because you have Option Strict On (which isn't a problem!) and you are implicitly making a narrowing conversion (which Option Strict On prevents) when you write the bit "sender.text"

If you change sender.text to control.text which you have already declared at the start of the sub you should find the problem goes away.

Dave299 at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

Hi,

Thanks Dave i didn't spot that, i was amending the original post code.

Been in work last night, not had much sleep. Zzzzz.

I'll edit my post now. :-)

All the best to you for 2007.

Regards,

S_DS

Spidermans_DarkSide at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4

thanks everyone & Happy New Year
That improved my code

i wanted to bring my code further so i tried to select all in the text box so that the user can edit it but it seems that it always selects the last 2 numbers only. i used:

Else
MessageBox.Show("An Error has Occurred!" ...)
control.SelectAll()
...

IceAngel89 at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5

That ought to work.

Looking at the code posted above again I've noticed a couple of problems with it. 1. it produces the messagebox after each number entered; 2. it generates an exception if you enter anything other than numbers.

The following works for me:

Private Sub IP_input_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_IPinput1.TextChanged, txt_IPinput2.TextChanged, txt_IPinput3.TextChanged, txt_IPinput4.TextChanged
Dim control As TextBox = CType(sender, TextBox)
If control.Text.Length = 3 Then
If IsNumeric(control.Text) = True AndAlso CInt(control.Text) >= 0 AndAlso CInt(control.Text) <= 255 Then
SelectNextControl(control, True, True, True, False)
Else
MsgBox("Please enter a number between 000 & 255")
control.SelectAll()
End If
End If
End Sub

Dave299 at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 6
Mmm... maybe its a bug on my computer, I'll try it on another computer if possible. thank you. i also thought it ought to work, strange it only selects the last 2 digits
IceAngel89 at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 8

As I could assume from the code, you try to get an IP address from user.

Instead of all this code, you can use just a MaskedTextBox to do all this work on its own.

Vano at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 9
ya i used a masked text box. but since i used a mask of 990, is this right?, user can enter like 300 and its still allowed. also, anyone knows of any site or where i can get a list of characters like 9, 0, # ... i can use for my mask. i tried MSDN library but could not find it. and i am thinking of changing the data type to Byte from int since a byte range from 0 - 255 (IP range)
IceAngel89 at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...