公路监理员日志范本:VB中的问题 急!

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 10:37:36
在VB中的text1中输入一个数,例如789,然后点击command1,使得在text2中显示一个数,这个数是text1中的数的各个位上的数的和,也就是24(7+8+9),那么command1的指令应该怎么写?

dim S as string, L as int, L1 as integer
dim R as long
S=text1.text
L=len(S)
if L=0 or (not isnumeric(S)) then exit sub
R=0
for L1=1 to L
R=cint(mid(S,L1,1))+R
next L
text2.text=cstr(R)