knrt.net
当前位置:首页 >> VB编程:n由inputBox函数输入变量s的值在窗体上输... >>

VB编程:n由inputBox函数输入变量s的值在窗体上输...

n=inputbox("请输入n(n>=2)") dim s as double dim i as integer for i=2 to n s=s + 1/i*(i-1) next print s

Private Sub Command1_Click() n = CInt(InputBox("求N!,请输入N的值:")) s = 1 For i = 2 To n s = s * i Next i MsgBox ("N!=" & s) End Sub

Private Sub Command1_Click() Dim n, i, S As Long n = InputBox("请输入自然数n的值", "期末考试第一题") For i = 1 To n Step 2 S = i + i Next Label1.Caption = "1到" & n & "之间奇数的和为:" & S End Sub Private Sub Command2_Click() ...

Dim MyValue MyValue = Int(Rnd*10^N) if MyValue < 10^(N-1) then MyValue = MyValue + (Int(Rnd*9)+1) * 10^(N-1) end if 没认证是否正确,思路是产生一个N位的随机数,不满N位在最高位再补一个一位随机数

窗体上画一个按钮 Private Sub Command1_Click() a = InputBox("请输入A") b = InputBox("请输入B") Me.Print a, b c = a a = b b = c Me.Print a; b End Sub

使用一个输入框的话就需要确定3个数字的分隔符,然后用Split函数把inputbox的字符串拆开。 如果使用三个字符串可以这样写: Dim a, b, c, d, e As Single a = Val(InputBox("请输入第一个数字")) b = Val(InputBox("请输入第二个数字")) c = Val...

原始数据所在工作簿包含多个格式相同的工作表,只不过每个工作表内容不同,比如说不同人名的工作表数据或者不同部门填写的数据。 在原始数据同目录下新建一个工作簿,建立两个工作表,名称分别为“首页”和“合并汇总表”。 按Alt+F11进入VBA代码编...

Private Sub Form_Click()Dim n As Integer, a() As Integer, i As Integer, j As Integern = Val(InputBox("请输入行数"))ReDim a(1 To n, 1 To n)For i = 1 To n For j = 1 To i If j = 1 Or j = i Then a(i, j) = 1 Else a(i, j) = a(i - 1, ...

Public Class Form1 Private Function jc1(ByVal q) Dim i%, p% p = 1 For i = 1 To q Step 1 p = p * i Next Return p End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1....

Private Sub Form_Click() '点击窗体运行程序MsgBox "两个数的和为" & (Val(InputBox("请输入第一个数")) + Val(InputBox("请输入第二个数")))End Sub

网站首页 | 网站地图
All rights reserved Powered by www.knrt.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com