VB程序设计里的题目,求详细编程。谢谢了
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
2个回答
展开全部
你只要在窗口中放一个frame,再在frame中放两个label1和label2。再在frame外面放一个label3,一个command1,一个text1。其他由程序完成,程序如下:
Private Sub Command1_Click()
Dim Sum As String
Dim N As Integer
Dim I As Integer, J As Integer, K As Integer
Dim S As Integer
N = Val(Text1)
For I = 1 To N
If I = 1 And (N Mod 2 = 0) Then K = -1 Else K = 1
S = 0
For J = 1 To I
S = S + K
K = -K
Next
Sum = Sum & S
Next
If Right(Sum, 1) = "1" Then Sum = Sum & ".1"
For I = 1 To Len(Sum)
If Mid(Sum, I, 1) = "1" Then Mid(Sum, I, 1) = "3"
Next
Label2.Caption = Sum
End Sub
Private Sub Form_Load()
With Form1
.Caption = "求和计算"
.Width = 7000
.Height = 4000
End With
With Frame1
.Caption = "求数列前N项和"
.Width = 6000
.Height = 1000
.Top = 500
.Left = 500
End With
With Label1
.Width = 2500
.Height = 500
.Caption = "3.3-33.3+333.3-3333.3+...="
.Top = 400
.Left = 100
End With
With Label2
.Width = Frame1.Width - (Label1.Left + Label1.Width) - 100
.Height = Label1.Height
.Caption = ""
.Top = 400
.Left = Label1.Left + Label1.Width
End With
With Text1
.Width = 1000
.Height = 300
.Text = ""
.Top = 2500
.Left = 4000
End With
With Command1
.Caption = "计算"
.Width = 1000
.Height = 300
.Top = 2500
.Left = 1000
End With
With Label3
.Width = 2000
.Height = Label1.Height
.Caption = "输入N的值,N="
.Top = Command1.Top
.Left = Command1.Left + Command1.Width + 500
End With
End Sub
已经运行过。
Private Sub Command1_Click()
Dim Sum As String
Dim N As Integer
Dim I As Integer, J As Integer, K As Integer
Dim S As Integer
N = Val(Text1)
For I = 1 To N
If I = 1 And (N Mod 2 = 0) Then K = -1 Else K = 1
S = 0
For J = 1 To I
S = S + K
K = -K
Next
Sum = Sum & S
Next
If Right(Sum, 1) = "1" Then Sum = Sum & ".1"
For I = 1 To Len(Sum)
If Mid(Sum, I, 1) = "1" Then Mid(Sum, I, 1) = "3"
Next
Label2.Caption = Sum
End Sub
Private Sub Form_Load()
With Form1
.Caption = "求和计算"
.Width = 7000
.Height = 4000
End With
With Frame1
.Caption = "求数列前N项和"
.Width = 6000
.Height = 1000
.Top = 500
.Left = 500
End With
With Label1
.Width = 2500
.Height = 500
.Caption = "3.3-33.3+333.3-3333.3+...="
.Top = 400
.Left = 100
End With
With Label2
.Width = Frame1.Width - (Label1.Left + Label1.Width) - 100
.Height = Label1.Height
.Caption = ""
.Top = 400
.Left = Label1.Left + Label1.Width
End With
With Text1
.Width = 1000
.Height = 300
.Text = ""
.Top = 2500
.Left = 4000
End With
With Command1
.Caption = "计算"
.Width = 1000
.Height = 300
.Top = 2500
.Left = 1000
End With
With Label3
.Width = 2000
.Height = Label1.Height
.Caption = "输入N的值,N="
.Top = Command1.Top
.Left = Command1.Left + Command1.Width + 500
End With
End Sub
已经运行过。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Public Function iTotal(Byval N As Integer) As Double
Dim i As Integer,N as Integer
Dim iTol As Double, iNum As Double, ix As Integer
iNum = 0.3
For i = 1 to N
iNum = iNum + 3 * 10^(i-1) 'iNum = 3.3+30+300+3000+...
ix = (-1)^(i-1) 'ix表示正负号
iTol = iTol + ix * iNum
Next
iTotal = iTol
End Function
Sub 调用函数()
Msgbox iTotal(5)
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询