KeyFC欢迎致辞,点击播放
资源、介绍、历史、Q群等新人必读
KeyFC 社区总索引
如果你找到这个笔记本,请把它邮寄给我们的回忆
KeyFC 漂流瓶传递活动 Since 2011
 

请问一道简单的VB题……

[ 7795 查看 / 25 回复 ]

回复: 请问一道简单的VB题……

原帖由 王二 于 2007-9-25 19:02:00 发表
Dim a As Single, b As Single, c As Single, d As Single

Private Sub Command1_Click()
a = Text1.Text
b = Text2.Text
c = Text3.Text
d = (a + b + c) / 3
Text4.Text = d
End Sub

Private Sub C......

Form_Load那些都沒有效果的, 可以略過...
又不是被其他Form call出來的dialog, 反正a,b,c,d的初始值也是 0 嘛...

==

Dim a As Single, b As Single, c As Single, d As Single

Private Sub Command1_Click()
a = Text1.Text
b = Text2.Text
c = Text3.Text
d = (a + b + c) / 3
Text4.Text = d
End Sub

==

然後在把Text1到Text4拉到Form上時, 把Text屬性設成"0"就好.
TOP

回复: 请问一道简单的VB题……

Dim a As Single, b As Single, c As Single, d As Single

Private Sub Command1_Click()
a = Text1.Text
b = Text2.Text
c = Text3.Text
d = (a + b + c) / 3
Text4.Text = d
End Sub



那个……运行的时候会提示  实时错误“424” 要求对象




还有如果某个text里不输入任何数字的话会提示  实时错误“13” 类型不匹配 怎么解决呢?
期待新作~
TOP

回复: 请问一道简单的VB题……

原帖由 helenzhu 于 2007-9-25 22:54:00 发表
那个……运行的时候会提示  实时错误“424” 要求对象

你.. 不會是不記得把Text1至Text4和Command1拉到Form上吧...

原帖由 helenzhu 于 2007-9-25 22:54:00 发表
还有如果某个text里不输入任何数字的话会提示  实时错误“13” 类型不匹配 怎么解决呢?

把 a = Text1.Text 改成

If (Len(Text1.Text) > 0) Then
    a = Text1.Text
End If

其他兩個TextBox比照辦理...

EDIT: 想一想還是多做一些比較好, 不然第二次計算結果就可能不對了:

If (Len(Text1.Text) > 0) Then
    a = Text1.Text
Else
    a = 0
    Text1.Text = 0
End If
最后编辑cheong00 最后编辑于 2007-09-25 23:13:59
TOP

回复: 请问一道简单的VB题……

把Text1至Text4和Command1拉到Form上


就是建立控件?有的啊……
期待新作~
TOP

回复:请问一道简单的VB题……

你在 "a = Text1.Text" 那行設一個breakpoint(中斷點), 在按command1時就會停在那行上了.

之後慢慢按F8 step(逐行執行), 看在那一行出錯吧...
TOP

回复: 请问一道简单的VB题……

原帖由 cheong00 于 2007-9-25 23:34:00 发表
你在 "a = Text1.Text" 那行設一個breakpoint(中斷點), 在按command1時就會停在那行上了.

之後慢慢按F8 step(逐行執行), 看在那一行出錯吧...



a = Text1.Text  就有错误……
最后编辑helenzhu 最后编辑于 2007-09-25 23:59:21
期待新作~
TOP

回复: 请问一道简单的VB题……

原帖由 helenzhu 于 2007-9-25 23:58:00 发表
a = Text1.Text  就有错误……


我剛剛做的... 你就自己看著照做一次吧...

======
上傳不了JPG...  才113KB也說太大了... :(

以下是Form1.frm的內容 (可以用Notepad開啟)...

======

VERSION 5.00
Begin VB.Form Form1
  Caption        =  "Form1"
  ClientHeight    =  3090
  ClientLeft      =  60
  ClientTop      =  450
  ClientWidth    =  4680
  LinkTopic      =  "Form1"
  ScaleHeight    =  3090
  ScaleWidth      =  4680
  StartUpPosition =  3  'Windows Default
  Begin VB.CommandButton Command1
      Caption        =  "Command1"
      Height          =  375
      Left            =  2400
      TabIndex        =  4
      Top            =  600
      Width          =  1335
  End
  Begin VB.TextBox Text4
      Height          =  375
      Left            =  50
      TabIndex        =  3
      Text            =  "0"
      Top            =  2040
      Width          =  2000
  End
  Begin VB.TextBox Text3
      Height          =  375
      Left            =  50
      TabIndex        =  2
      Text            =  "0"
      Top            =  1440
      Width          =  2000
  End
  Begin VB.TextBox Text2
      Height          =  375
      Left            =  50
      TabIndex        =  1
      Text            =  "0"
      Top            =  840
      Width          =  2000
  End
  Begin VB.TextBox Text1
      Height          =  375
      Left            =  50
      TabIndex        =  0
      Text            =  "0"
      Top            =  360
      Width          =  2000
  End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim a As Single, b As Single, c As Single, d As Single
Private Sub Command1_Click()
    If (Len(Text1.Text) > 0) Then
        a = CSng(Text1.Text)
    Else
        Text1.Text = "0"
        a = 0
    End If
    If (Len(Text2.Text) > 0) Then
        b = CSng(Text2.Text)
    Else
        Textb.Text = "0"
        b = 0
    End If
    If (Len(Text3.Text) > 0) Then
        c = CSng(Text3.Text)
    Else
        Text3.Text = "0"
        c = 0
    End If
    d = (a + b + c) / 3
    Text4.Text = d
End Sub
最后编辑cheong00 最后编辑于 2007-09-26 00:18:06
TOP

回复: 请问一道简单的VB题……

If (Len(Text2.Text) > 0) Then
        b = CSng(Text2.Text)
    Else
        Textb.Text = "0"
        b = 0
    End If


这里红色部分

我改过来运行终于成功啦^_^


谢谢
斑鳩君和理昌君^_^
最后编辑helenzhu 最后编辑于 2007-09-26 00:26:21
期待新作~
TOP

回复:请问一道简单的VB题……

这样就可以了。前提是在你的Form上有Text1~Text4、Command1、Command2这六个控件。

Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single, d As Single

a = val(Text1.Text )
b = val(Text2.Text )
c = val(Text3.Text )

d = (a + b + c) / 3

Text4.Text = d
End Sub

Private Sub Command2_Click()
End
End Sub
TOP

回复: 请问一道简单的VB题……

原帖由 helenzhu 于 2007-9-26 0:23:00 发表
If (Len(Text2.Text) > 0) Then
        b = CSng(Text2.Text)
    Else
        Textb.Text = "0"
        b = 0
    End If


这里红色部分

我改过来......

Emmm... 這樣說其他部份也要做相應的改變才對...

If (Len(Textb.Text) > 0) Then
        b = CSng(Textb.Text)
    Else
        Textb.Text = "0"
        b = 0
    End If
TOP