永发信息网

vb中的一些问题

答案:3  悬赏:30  手机版
解决时间 2021-06-02 04:06
  • 提问者网友:遮云壑
  • 2021-06-01 04:55

4、在窗体上画1个名称为Command1的命令按钮和2个名称分别为Text1、Text2的文本框,如图所示,然后编写如下程序:

Function Fun(x As Integer,ByVal y As Integer) As Integer
x=x+y
If x<0 Then
Fun=x
Else
Fun=y
End If
End Function
Private Sub Command1_Click()
Dim a As Integer,b As Integer
a=-10:b=5
Text1.Text=Fun(a,b)
Text2.Text=Fun(a,b)
End Sub

程序运行后,单击按钮,Text1和Text2文本框显示的内容分别是 和 。

看看这个题目,有错误吗?有错的话在哪里?没错的话请解答!谢谢!

最佳答案
  • 五星知识达人网友:不甚了了
  • 2021-06-01 05:35

你的代码是在正确的,只是你的标点符号写成中文的逗号了,改成英文即可、


把:


Text1.Text=Fun(a,b)
Text2.Text=Fun(a,b)
改成:


Text1.Text=Fun(a,b)
Text2.Text=Fun(a,b)

全部回答
  • 1楼网友:我住北渡口
  • 2021-06-01 07:18

出错的应该是这三句

a=-10:b=5 Text1.Text=Fun(a,b) Text2.Text=Fun(a,b)

改成:

a=-10:b=5 Text1.Text=Fun(a,b) Text2.Text=Fun(a,b)

写代码的时候切记要切换为英文半角状态写,这样可以防止这种简单的语法错误!

  • 2楼网友:青尢
  • 2021-06-01 06:31
Function Fun(x As Integer, ByVal y As Integer) As Integer x = x + y If x < 0 Then Fun = x Else Fun = y End If End Function Private Sub Command1_Click() Dim a As Integer, b As Integer a = -10 b = 5 Text1.Text = Fun(a, b) Text2.Text = Fun(a, b) End Sub 我这个帮你调试了一下是可以运行的,你试一试
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯