永发信息网

关于VB程序解释一下

答案:3  悬赏:10  手机版
解决时间 2021-04-25 19:39
  • 提问者网友:情歌越听越心酸
  • 2021-04-25 05:39
Option Explicit
Private Sub command1_click()
Dim i As Integer, s As String, sum As Integer, x As Integer
s = Text1
Do
i = InStr(s, ",")
x = Left(s, i - 1)
If x Mod 2 = 0 Then
sum = sum + x
End If
s = Mid(s, i + 1, Len(s) - i)

Loop While i <> 0
Text2 = sum
End Sub
和下面的 为什么是下面的对的呢Option Explicit
Private Sub command1_click()
Dim i As Integer, s As String, sum As Integer, x As Integer
s = Text1
i = InStr(s, ",")
Do
x = Left(s, i - 1)
If x Mod 2 = 0 Then
sum = sum + x
End If
s = Mid(s, i + 1, Len(s) - i)
i = InStr(s, ",")
Loop While i <> 0
Text2 = sum
End Sub
最佳答案
  • 五星知识达人网友:掌灯师
  • 2021-04-25 06:38

Option Explicit '强制声明
Private Sub command1_click()
Dim i As Integer, s As String, sum As Integer, x As Integer '声明变量
s = Text1.Text 's定义text
i = InStr(s, ",") 'InStr文本查找,i=查找s里的,
Do ' do循环语句
x = Left(s, i + 1) '这句我把i-1改成i+1因为没办法-了只能+,不然出错
If x Mod 2 = 0 Then '判断 x除2余数是不是0
sum = sum + x '是则sum加x
End If '退出循环
s = Mid(s, i + 1, Len(s) - i) 'mid替换的意思,s等于,s内容中查找i+1后的数,显示Len(s) - i,的位数
i = InStr(s, ",") 'i等于查找s文本里的,号
Loop While i <> 0 '循环i
Text2 = sum '最后得出sunm
End Sub


这样子。我做出来的。希望满意


全部回答
  • 1楼网友:千夜
  • 2021-04-25 07:54
Option Explicit ‘声明 Private Sub command1_click() ’command1按钮被单击 Dim i As Integer, s As String, sum As Integer, x As Integer ‘定义变量 s = Text1 ’text1是什么意思看不懂,如果是文本框的内容的话,改为text1.text
  • 2楼网友:平生事
  • 2021-04-25 07:37

Option Explicit 这个是强制声明变量,不加的话可以不用声明变量

因为Text1是string所以text1=sum 肯定是错的

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯