vb.net - Auto split text the numbers -
i'm trying past ip in 1 textbox
, when press ok must split in 4 pieces like:
123.123.123.123
and split in textbox1
,2,3,4 [123] [123] [123] [123]
ok if set more numbers 123.123.123.123.123.123.123 errors.
dim str string = textbox1.text dim splitstr string() = str.split(".") textbox1.text = splitstr(0).tostring() textbox2.text = splitstr(1).tostring() textbox3.text = splitstr(2).tostring() textbox4.text = splitstr(3).tostring()
this covers input errors:
private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click textbox2.text = "" textbox3.text = "" textbox4.text = "" dim str string = textbox1.text str = str.trim dim splitstrs string() = str.split("."c) if splitstrs.length <> 4 msgbox("not valid ip format") exit sub end if each value string in splitstrs if value.length < 1 orelse value.length > 3 msgbox("not valid ip format") exit sub end if if not integer.tryparse(value, 0) msgbox("not valid ip format") exit sub end if if value.contains(" ") msgbox("not valid ip format") exit sub end if next textbox1.text = splitstrs(0).tostring() textbox2.text = splitstrs(1).tostring() textbox3.text = splitstrs(2).tostring() textbox4.text = splitstrs(3).tostring() end sub
vb.net textbox
No comments:
Post a Comment