来个VB高手!!!!!急!!!!!谢谢!
有如下10个数:-2,73,82,-76,-1,24,321,-25,89,-20编写一程序,打印出其中的每个负数,分别计算并输出正数及负数的和。要求:用for循环用wh...
有如下10个数:
-2,73,82,-76,-1,24,321,-25,89,-20
编写一程序,打印出其中的每个负数,分别计算并输出正数及负数的和。
要求:
用for循环
用while循环
用do …loop循环 展开
-2,73,82,-76,-1,24,321,-25,89,-20
编写一程序,打印出其中的每个负数,分别计算并输出正数及负数的和。
要求:
用for循环
用while循环
用do …loop循环 展开
展开全部
Private Sub Command1_Click() '用while ....wend循环实现。
Dim Sdata As String
Dim Vdata As Variant
Dim Ncount As Integer
Dim Zsum As Double
Dim Fsum As Double
Dim i As Integer
i = 0
Sdata = "-2,73,82,-76,-1,24,321,-25,89,-20"
Vdata = Split(Sdata, ",")
Ncount = UBound(Vdata)
While i < Ncount
If Vdata(i) < 0 Then
Print "负数:" & Vdata(i)
Fsum = Fsum + Val(Vdata(i))
Else
Print "正数:" & Vdata(i)
Zsum = Zsum + Val(Vdata(i))
End If
i = i + 1
Wend
Print "正数和=" & Zsum
Print "负数和=" & Fsum
End Sub
Private Sub Command2_Click() '用 do.....loop循环实现
Dim Sdata As String
Dim Vdata As Variant
Dim Ncount As Integer
Dim Zsum As Double
Dim Fsum As Double
Dim i As Integer
i = 0
Sdata = "-2,73,82,-76,-1,24,321,-25,89,-20"
Vdata = Split(Sdata, ",")
Ncount = UBound(Vdata)
Do While i < Ncount
If Vdata(i) < 0 Then
Print "负数:" & Vdata(i)
Fsum = Fsum + Val(Vdata(i))
Else
Print "正数:" & Vdata(i)
Zsum = Zsum + Val(Vdata(i))
End If
i = i + 1
Loop
Print "正数和=" & Zsum
Print "负数和=" & Fsum
End Sub
Private Sub Command3_Click() '用for .....next 循环实现
Dim Sdata As String
Dim Vdata As Variant
Dim Ncount As Integer
Dim Zsum As Double
Dim Fsum As Double
Dim i As Integer
i = 0
Sdata = "-2,73,82,-76,-1,24,321,-25,89,-20"
Vdata = Split(Sdata, ",")
Ncount = UBound(Vdata)
For i = 0 To Ncount
If Vdata(i) < 0 Then
Print "负数:" & Vdata(i)
Fsum = Fsum + Val(Vdata(i))
Else
Print "正数:" & Vdata(i)
Zsum = Zsum + Val(Vdata(i))
End If
Next i
Print "正数和=" & Zsum
Print "负数和=" & Fsum
End Sub
Dim Sdata As String
Dim Vdata As Variant
Dim Ncount As Integer
Dim Zsum As Double
Dim Fsum As Double
Dim i As Integer
i = 0
Sdata = "-2,73,82,-76,-1,24,321,-25,89,-20"
Vdata = Split(Sdata, ",")
Ncount = UBound(Vdata)
While i < Ncount
If Vdata(i) < 0 Then
Print "负数:" & Vdata(i)
Fsum = Fsum + Val(Vdata(i))
Else
Print "正数:" & Vdata(i)
Zsum = Zsum + Val(Vdata(i))
End If
i = i + 1
Wend
Print "正数和=" & Zsum
Print "负数和=" & Fsum
End Sub
Private Sub Command2_Click() '用 do.....loop循环实现
Dim Sdata As String
Dim Vdata As Variant
Dim Ncount As Integer
Dim Zsum As Double
Dim Fsum As Double
Dim i As Integer
i = 0
Sdata = "-2,73,82,-76,-1,24,321,-25,89,-20"
Vdata = Split(Sdata, ",")
Ncount = UBound(Vdata)
Do While i < Ncount
If Vdata(i) < 0 Then
Print "负数:" & Vdata(i)
Fsum = Fsum + Val(Vdata(i))
Else
Print "正数:" & Vdata(i)
Zsum = Zsum + Val(Vdata(i))
End If
i = i + 1
Loop
Print "正数和=" & Zsum
Print "负数和=" & Fsum
End Sub
Private Sub Command3_Click() '用for .....next 循环实现
Dim Sdata As String
Dim Vdata As Variant
Dim Ncount As Integer
Dim Zsum As Double
Dim Fsum As Double
Dim i As Integer
i = 0
Sdata = "-2,73,82,-76,-1,24,321,-25,89,-20"
Vdata = Split(Sdata, ",")
Ncount = UBound(Vdata)
For i = 0 To Ncount
If Vdata(i) < 0 Then
Print "负数:" & Vdata(i)
Fsum = Fsum + Val(Vdata(i))
Else
Print "正数:" & Vdata(i)
Zsum = Zsum + Val(Vdata(i))
End If
Next i
Print "正数和=" & Zsum
Print "负数和=" & Fsum
End Sub
展开全部
for:
dim a(9)
dim i,b,c
b=0
a(0)=-2
a(1)=73
a(2)=82
a(3)=-76
a(4)=-1
a(5)=24
a(6)=321
a(7)=-25
a(8)=89
a(9)=-20
for i=0 to 9
if a(i)<0 then
b=b+a(i) '负数
else
c=c+a(i) '正数
end if
next
print b,c
while:
dim a(9)
dim i,b,c,d
b=0:c=0
a(0)=-2
a(1)=73
a(2)=82
a(3)=-76
a(4)=-1
a(5)=24
a(6)=321
a(7)=-25
a(8)=89
a(9)=-20
while a(b)<0 and b<9
if a(b)<0 then
c=c+a(b) '正数
else
d=d+a(b) '负数
endif
b=b+1
wend
print c,d
do loop 和while 语句基本一样。
dim a(9)
dim i,b,c
b=0
a(0)=-2
a(1)=73
a(2)=82
a(3)=-76
a(4)=-1
a(5)=24
a(6)=321
a(7)=-25
a(8)=89
a(9)=-20
for i=0 to 9
if a(i)<0 then
b=b+a(i) '负数
else
c=c+a(i) '正数
end if
next
print b,c
while:
dim a(9)
dim i,b,c,d
b=0:c=0
a(0)=-2
a(1)=73
a(2)=82
a(3)=-76
a(4)=-1
a(5)=24
a(6)=321
a(7)=-25
a(8)=89
a(9)=-20
while a(b)<0 and b<9
if a(b)<0 then
c=c+a(b) '正数
else
d=d+a(b) '负数
endif
b=b+1
wend
print c,d
do loop 和while 语句基本一样。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Option Explicit
Dim vSplit
Private Sub Command1_Click()
Dim i As Long
Dim sum As Long
Cls
For i = LBound(vSplit) To UBound(vSplit)
sum = sum + CInt(vSplit(i))
If vSplit(i) < 0 Then
Print vSplit(i)
End If
Next i
End Sub
Private Sub Command2_Click()
Dim i As Long
Dim sum As Long
Cls
i = LBound(vSplit)
While i <= UBound(vSplit)
sum = sum + CInt(vSplit(i))
If vSplit(i) < 0 Then
Print vSplit(i)
End If
i = i + 1
Wend
End Sub
Private Sub Command3_Click()
Dim i As Long
Dim sum As Long
Cls
i = LBound(vSplit)
Do While i <= UBound(vSplit)
sum = sum + CInt(vSplit(i))
If vSplit(i) < 0 Then
Print vSplit(i)
End If
i = i + 1
Loop
End Sub
Private Sub Form_Load()
Dim sData As String
sData = "-2,73,82,-76,-1,24,321,-25,89,-20"
vSplit = Split(sData, ",")
End Sub
Dim vSplit
Private Sub Command1_Click()
Dim i As Long
Dim sum As Long
Cls
For i = LBound(vSplit) To UBound(vSplit)
sum = sum + CInt(vSplit(i))
If vSplit(i) < 0 Then
Print vSplit(i)
End If
Next i
End Sub
Private Sub Command2_Click()
Dim i As Long
Dim sum As Long
Cls
i = LBound(vSplit)
While i <= UBound(vSplit)
sum = sum + CInt(vSplit(i))
If vSplit(i) < 0 Then
Print vSplit(i)
End If
i = i + 1
Wend
End Sub
Private Sub Command3_Click()
Dim i As Long
Dim sum As Long
Cls
i = LBound(vSplit)
Do While i <= UBound(vSplit)
sum = sum + CInt(vSplit(i))
If vSplit(i) < 0 Then
Print vSplit(i)
End If
i = i + 1
Loop
End Sub
Private Sub Form_Load()
Dim sData As String
sData = "-2,73,82,-76,-1,24,321,-25,89,-20"
vSplit = Split(sData, ",")
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
比如这10个数入在数组z中
正数的和放在ss中
负数的和放在sf中
dim ss as integer
dim sf as integer
ss=0
sf=0
用for
for i=0 to 9
if z(i)<0 then
print z(i) 不知你说的打印是用什么打这里我用的是在屏幕上显示出来
sf=sf+z(i)
else
ss=ss+z(i)
endif
next
print sf
print ss
用while
while i<10
里面一样,while的格式我忘了,你再查查
用do loop也一样,把循环条件写对了就行了
正数的和放在ss中
负数的和放在sf中
dim ss as integer
dim sf as integer
ss=0
sf=0
用for
for i=0 to 9
if z(i)<0 then
print z(i) 不知你说的打印是用什么打这里我用的是在屏幕上显示出来
sf=sf+z(i)
else
ss=ss+z(i)
endif
next
print sf
print ss
用while
while i<10
里面一样,while的格式我忘了,你再查查
用do loop也一样,把循环条件写对了就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询