visual studio - Label text not displaying correctly -
private sub btnfind_click(sender object, e eventargs) handles btnfind.click lblnumber.text = "" strlttrinput = inputbox("please enter letter or phrase:", "find corrresponding number letter(s)") strlttrinput .tolower() .trim() end intphraseindx = strlttrinput.length - 1 dim strword(intphraseindx) string dim stroutput string = string.empty intcount = 0 intphraseindx strword(intcount) = strlttrinput.substring(intcount) next intcount = 0 intphraseindx select case strword(intcount) case "a", "b", "c" lblnumber.text = lblnumber.text & "2" case "d", "e", "f" lblnumber.text = lblnumber.text & "3" case "g", "h", "i" lblnumber.text = lblnumber.text & "4" case "j", "k", "l" lblnumber.text = lblnumber.text & "5" case "m", "n", "o" lblnumber.text = lblnumber.text & "6" case "p", "r", "s" lblnumber.text = lblnumber.text & "7" case "t", "u", "v" lblnumber.text = lblnumber.text & "8" case "w", "x", "y" lblnumber.text = lblnumber.text & "9" end select if strword(intcount) = "q" lblnumber.text = lblnumber.text & "q" end if if strword(intcount) = "z" lblnumber.text = lblnumber.text & "z" end if next end sub
for example, when enter "adgj", label's text should "2345", when run it, label's text "2"
the reason why code failing, because on substring, not limiting length 1. means contents of strword be:
strword(0) = adgj strword(1) = dgj strword(2) = gj strword(3) = j
you can fix specifying length substring:
strword(intcount) = strlttrinput.substring(intcount, 1)
as sidenote, there no need loop twice , store letters, this:
for intcount = 0 intphraseindx select case strlttrinput.substring(intcount, 1) ... end select next
Comments
Post a Comment