这个问题不知道有没有难度,高手请进。急啊。

lylhj 2004-07-22 04:54:34
问题如下:
回数:( ) <--这是个imText控件
金额:( ) <--这是个imText控件
总金额:< > <-- 这是个label

只要回数和金额有值(0也可以),,当光标无论是在回数还是在金额imText里面,总金额label总能及时自动根据回数和金额里面的值算出总金额是多少,当回数和金额其中任何一个没有值时,则总金额里面的值是空。
具体怎么实现请大家帮忙看看,具体用到什么事件方法请帮忙写写看,最好有代码。急。
...全文
184 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
warlord 2004-07-27
  • 打赏
  • 举报
回复
over
落伍者 2004-07-23
  • 打赏
  • 举报
回复
楼上的程序有一个问题,就是如果输入负数时不能成功,
或者如 .123必须按0.123输入。
chuting1 2004-07-23
  • 打赏
  • 举报
回复
if a1<>"" and a2<>"" then
b1=...
label1.caption=b1
endif
northwolves 2004-07-23
  • 打赏
  • 举报
回复
应该不会
射天狼 2004-07-23
  • 打赏
  • 举报
回复
Private Sub Text1_Change()
Label1.Caption = Val(Text1.Text) * Val(Text2.Text)
End Sub

Private Sub Text2_Change()
Label1.Caption = Val(Text1.Text) * Val(Text2.Text)
End Sub
northwolves 2004-07-22
  • 打赏
  • 举报
回复
呵呵,简化一下:
Sub diag()
On Error Resume Next
Label1.Caption = IIf(Trim(Text1 & Text2) = "" Or (Not IsNumeric(Text1 & Text2)), "", Val(Text1) * Val(Text2))
End Sub

Private Sub Text1_Change()
diag
End Sub

Private Sub Text2_Change()
diag
End Sub
熊孩子开学喽 2004-07-22
  • 打赏
  • 举报
回复
如果楼主使用控件数组:
回数:( ) Text1(0)
金额:( ) Text1(1)
总金额:< > label1

sub text1_change(Index as integer)
if not isnumeric(text1(index).text) then text1(Index).text=""
If trim(text1(0).text)<>"" and trim(text1(1).text)<>"" then
label1.caption=val(text1(0).text) + val(text1(1).text)
endif
end sub

就这样可以了。
熊孩子开学喽 2004-07-22
  • 打赏
  • 举报
回复
回数:( ) Text1
金额:( ) Text2
总金额:< > label1

sub text1_change()
if not isnumeric(text1.text) then text1.text=""
If trim(text1.text)<>"" and trim(text2.text)<>"" then
label1.caption=val(text1.text) + val(text2.text)
endif
end sub

sub text2_change()
if not isnumeric(text2.text) then text2.text=""
If trim(text1.text)<>"" and trim(text2.text)<>"" then
label1.caption=val(text1.text) + val(text2.text)
endif
end sub

就这样可以了。
TechnoFantasy 2004-07-22
  • 打赏
  • 举报
回复
isnumeric就是判断是否是数字的函数!
饮水需思源 2004-07-22
  • 打赏
  • 举报
回复
isnumeric()判断是否为数值型数据的函数
xntm 2004-07-22
  • 打赏
  • 举报
回复
问一下!
isnumeric 和 cdbl 是什么函数?
程序写的不错,当我认为要对Change()事件判断输入是否为数字!
饮水需思源 2004-07-22
  • 打赏
  • 举报
回复
可用textbox控件的change控件来实现:
'写一个自动计算的过程
private sub AutoCal()
if trim(text1.text)<>"" and trim(text2.text)<>"" then
if isnumeric(text1.text) and isnumeric(text2.text) then
label1.caption=cdbl(text1.text)*cdbl(text2.text)
else
label1.caption=""
end if
else
label1.caption=""
end if
end sub

private sub text1_change()
call autocal
end sub
private sub text2_change()
call autocal
end sub
daisy8675 2004-07-22
  • 打赏
  • 举报
回复
晕闷,能继续说清楚,或者抓图上来么imtext是你自己的控件?

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧