,.
1、
(1)
Private Sub Command1_Click()
Text3.Text = 2 * (Val(Text1.Text) + Val(Text2.Text))
Text4.Text = Val(Text1.Text) * Val(Text2.Text)
End Sub
(2)
Private Sub Command1_Click()
Text3.Text = Str(2 * (Val(Text1.Text) + Val(Text2.Text)))
Text4.Text = Str(Val(Text1.Text) * Val(Text2.Text))
End Sub
(3)
Private Sub Command1_Click()
Dim c As Double, k As Double, z As Double, m As Double
c = Val(Text1.Text)
k = Val(Text2.Text)
z = 2 * (c + k)
m = c * k
Text3.Text = Str(z)
Text4.Text = Str(m)
End Sub
2、
(1)
Private Sub Command1_Click()
Text2.Text = 2 * 3.1415926 * Val(Text1.Text)
Text3.Text = 3.1415926 * Val(Text1.Text) ^ 2
End Sub
(2)
Private Sub Command1_Click()
Text2.Text = Str(2 * 3.1415926 * Val(Text1.Text))
Text3.Text = Str(3.1415926 * Val(Text1.Text) ^ 2)
End Sub
(3)
Private Sub Command1_Click()
r = Val(Text1.Text)
p = 2 * 3.1415926 * r
s = 3.1415926 * r ^ 2
Text2 = p
Text3 = s
End Sub
3、
(1)
Private Sub Command1_Click()
Text3.Text = Val(Text1.Text) / Val(Text2.Text)
End Sub
(2)
Private Sub Command1_Click()
Text3.Text = Str(Val(Text1.Text) / Val(Text2.Text))
End Sub
(3)
Private Sub Command1_Click()
Dim rmb As Double, bl As Double, my As Double
rmb = Val(Text1.Text)
bl = Val(Text2.Text)
my = rmb / bl
Text3.Text = Str(my)
End Sub
1、在上方文本框Text1中输入任意2位数,单击“处理”按钮Command1,将这个两位数逆序输出到下方文本框Text2中。
Private Sub Command1_Click()
ys = Val(Text1.Text)
ns = (ys Mod 10) * 10 + (ys \ 10)
Text2.Text = ns
End Sub
Private Sub Command1_Click()
ys = Text1.Text
ns = Right(ys, 1) & Left(ys, 1)
Text2.Text = ns
End Sub
Private Sub Command1_Click()
ys = Text1.Text
ns = Mid(ys, 2, 1) & Mid(ys, 1, 1)
Text2.Text = ns
End Sub
2、在上方文本框Text1中写入普通手机号码,点击转换按钮Command1,将普通手机号码转为加横线的手机号码写入Text2文本框中。相反,在下方文本框Text2中写入加横线的手机号码,点击反转按钮Command2,将加横线的手机号码转为普通手机号码写入Text1文本框中。
Private Sub Command1_Click()
yhm = Text1.Text
xhm = Mid(yhm, 1, 3) & "-" & Mid(yhm, 4, 4) & "-" & Mid(yhm, 8, 4)
Text2.Text = xhm
End Sub
Private Sub Command2_Click()
yhm = Text2.Text
xhm = Mid(yhm, 1, 3) & Mid(yhm, 5, 4) & Right(yhm, 4)
Text1.Text = xhm
End Sub
3、在文本框Text1中写入一字符串,点击处理按钮Command1,则将Text1中所有小写字母转换为大写字母,结果写入文本框Text2中,并计算Text1中字符个数写入文本框Text3中。
Private Sub Command1_Click()
yzf = Text1.Text
xzf = UCase(yzf)
zfgs = Len(yzf)
Text2.Text = xzf
Text3.Text = zfgs
End Sub
4、在txtChinese、txtMath文本框中分别输入“语文”和“数学”的成绩,单击“计算”按钮cmdComp,程序计算出总分和平均分,分别放入txtSum、txtAvg文本框中;单击“清空”按钮cmdClear,将4个文本框清空。
Private Sub cmdClear_Click()
txtChinese.Text = ""
txtMath.Text = ""
txtSum.Text = ""
txtAvg.Text = ""
End Sub
Private Sub cmdComp_Click()
zf = Val(txtChinese.Text) + Val(txtMath.Text)
pjf = zf / 2
txtSum.Text = zf
txtAvg.Text = pjf
End Sub
1、在文本框txtName中输入姓名,点击按钮“你输入的姓名是”(Command1),在旁边的标签lblName中显示txtName输入的姓名
Private Sub Command1_Click()
lblName.Caption = txtName.Text
End Sub
2、单击窗体时,选中文本框Text1中的第2~第4个字符,复制到文本框Text2中
Private Sub Form_Click()
Text1.SelStart = 1
Text1.SelLength = 3
Text2.Text = Text1.SelText
End Sub
3、点击“密码字符”按钮Command1,使Text1中的内容用*显示 点击“原始文本”按钮Command2,使Text1中的内容恢复正常显示 点击“锁定文本框”按钮Command3,将文本框Text1锁定 点击“解锁文本框”按钮Command4,将文本框Text1取消锁定 点击“文本框无效”按钮Command5,使文本框Text1无效 点击“文本框有效”按钮Command6,将文本框Text1有效 此外,在文本框Text1中输入删除修改内容时,文本框Text2内容始终与Text1保持一致
Private Sub Command1_Click()
Text1.PasswordChar = "*"
End Sub
Private Sub Command2_Click()
Text1.PasswordChar = ""
End Sub
Private Sub Command3_Click()
Text1.Locked = True
End Sub
Private Sub Command4_Click()
Text1.Locked = False
End Sub
Private Sub Command5_Click()
Text1.Enabled = False
End Sub
4、程序运行时,在Text1中填入文字,在Text2中填入正整数字号 点击“增大字号”按钮Command1,使Text1的字号增大Text2中指定的数值 点击“减小字号”按钮Command2,使Text1的字号减小Text2中指定的数值 点击“设置字号”按钮Command3,使Text1的字号设置为Text2中指定的数值
Private Sub Command1_Click()
Text1.FontSize = Text1.FontSize + Val(Text2.Text)
End Sub
Private Sub Command2_Click()
Text1.FontSize = Text1.FontSize - Val(Text2.Text)
End Sub
Private Sub Command3_Click()
Text1.FontSize = Val(Text2.Text)
End Sub
5、用户单击窗体时,文本框Text1的值在其原值基础上递增加1。程序运行起始时次数为0(文本框初始值为0)。
Private Sub Form_Click()
Text1.Text = Val(Text1.Text) + 1
End Sub
Private Sub Form_Load()
Text1.Text = 0
End Sub
6、点击“复制文本”按钮Command1,将Text1中的内容复制到Text2中 点击“复制选中文本”按钮Command2,将Text1中选中的内容复制到Text2中 点击“隐藏文本框”按钮Command3,将文本框Text1隐藏 点击“显示文本框”按钮Command4,将文本框Text1显示(取消隐藏)
Private Sub Command1_Click()
Text2.Text = Text1.Text
End Sub
Private Sub Command2_Click()
Text2.Text = Text1.SelText
End Sub
Private Sub Command3_Click()
Text1.Visible = False
End Sub
Private Sub Command4_Click()
Text1.Visible = True
End Sub
7、“向上移动”、“向下移动”、“向左移动”、“向右移动”四个按钮的控件名分别为Command1~Command4。单击按钮,窗体向对应的方向移动100个单位
Private Sub Command1_Click()
Form1.Top = Form1.Top - 100
End Sub
Private Sub Command2_Click()
Form1.Top = Form1.Top + 100
End Sub
Private Sub Command3_Click()
Form1.Left = Form1.Left - 100
End Sub
Private Sub Command4_Click()
Form1.Left = Form1.Left + 100
End Sub
8、单击“产生”命令按钮Command1,在上面三个文本框Text1~Text3中分别输出随机产生的3个正整数,其中1个1位数(0~9),1个2位数,1个3位数。单击“计算”命令按钮Command2计算它们的平均值,四舍五入保留2位小数,结果在标签LabelAvg中显示。 注意:本题需使用A~B区间随机整数公式。随机函数请使用Rnd(),不要省略括号。
Private Sub Command1_Click()
Dim w1%, w2%, w3%
Randomize
w1 = Int((9 - 0 + 1) * Rnd() + 0)
w2 = Int((99 - 10 + 1) * Rnd() + 10)
w3 = Int((999 - 100 + 1) * Rnd() + 100)
Text1.Text = w1
Text2.Text = w2
Text3.Text = w3
End Sub
Private Sub Command2_Click()
Dim w1%, w2%, w3%, pjz#
w1 = Val(Text1.Text)
w2 = Val(Text2.Text)
w3 = Val(Text3.Text)
pjz = (w1 + w2 + w3) / 3
pjz = Round(pjz, 2)
LabelAvg.Caption = pjz
End Sub
9、在文本框Text1中写入一字符串,点击处理按钮Command1,则将Text1中所有小写字母转换为大写字母,结果写入文本框Text2中,并计算Text1中字符个数写入文本框Text3中。
Private Sub Command1_Click()
Text2.Text = UCase(Text1.Text)
Text3.Text = Len(Text1.Text)
End Sub
10、在上方文本框Text1中写入普通手机号码,点击转换按钮Command1,将普通手机号码转为加横线的手机号码写入Text2文本框中。相反,在下方文本框Text2中写入加横线的手机号码,点击反转按钮Command2,将加横线的手机号码转为普通手机号码写入Text1文本框中。
Private Sub Command1_Click()
Text2.Text = Left(Text1.Text, 3) & "-" & Mid(Text1.Text, 4, 4) & "-" & Right(Text1.Text, 4)
End Sub
Private Sub Command2_Click()
Text1.Text = Left(Text2.Text, 3) & Mid(Text2.Text, 5, 4) & Right(Text2.Text, 4)
End Sub
1、单击“产生”命令按钮Command1,在上面三个文本框Text1~Text3中分别输出随机产生的3个正整数,其中1个1位数(0~9),1个2位数,1个3位数。单击“计算”命令按钮Command2计算它们的平均值,四舍五入保留2位小数,结果在标签LabelAvg中显示。 注意:本题需使用A~B区间随机整数公式。随机函数请使用Rnd(),不要省略括号。
Private Sub Command1_Click()
Dim w1&, w2&, w3&
Randomize
w1 = Int((9 - 0 + 1) * Rnd() + 0)
w2 = Int((99 - 10 + 1) * Rnd() + 10)
w3 = Int((999 - 100 + 1) * Rnd() + 100)
Text1.Text = w1
Text2.Text = w2
Text3.Text = w3
End Sub
Private Sub Command2_Click()
Dim w1&, w2&, w3&, pjz#
w1 = Val(Text1.Text)
w2 = Val(Text2.Text)
w3 = Val(Text3.Text)
pjz = Round((w1 + w2 + w3) / 3, 2)
LabelAvg.Caption = pjz
End Sub
2、在txtChinese、txtMath文本框中分别输入“语文”和“数学”的成绩,单击“计算”按钮cmdComp,程序计算出总分和平均分,分别放入txtSum、txtAvg文本框中;单击“清空”按钮cmdClear,将4个文本框清空。
Private Sub cmdClear_Click()
txtChinese.Text = ""
txtMath.Text = ""
txtSum.Text = ""
txtAvg.Text = ""
End Sub
Private Sub cmdComp_Click()
Dim yw As Double, sx As Double
Dim zf As Double, pjf As Double
yw = Val(txtChinese.Text)
sx = Val(txtMath.Text)
zf = yw + sx
pjf = zf / 2
txtSum.Text = zf
txtAvg.Text = pjf
End Sub
3、已知火车的出发时间和达到时间,编写程序计算整个旅途所用的时间。出发时间对应的文本框为Text1和Text2,到达时间对应的文本框为Text3和Text4,旅途时间对应的文本框为Text5和Text6,计算按钮为Command1。(时间形式:小时:分钟,24小时制)
Private Sub Command1_Click()
Dim cfs%, cff%, dds%, ddf%, ltsj%
Dim lts%, ltf%
cfs = Val(Text1.Text)
cff = Val(Text2.Text)
dds = Val(Text3.Text)
ddf = Val(Text4.Text)
ltsj = (dds * 60 + ddf) - (cfs * 60 + cff)
lts = ltsj \ 60
ltf = ltsj Mod 60
Text5.Text = lts
Text6.Text = ltf
End Sub
4、在上方文本框Text1中输入任意3位数,单击“处理”按钮Command1,将这个3位数逆序输出到下方文本框Text2中。
Private Sub Command1_Click()
Dim ys%, b%, s%, g%, ns%
ys = Val(Text1.Text)
b = Int(ys / 100)
s = Int((ys - b * 100) / 10)
g = ys - b * 100 - s * 10
ns = g * 100 + s * 10 + b
Text2.Text = ns
End Sub
5、已知火车的出发时间和旅途所用的时间,编写程序计算火车达到的时间。出发时间对应的文本框为Text1和Text2,旅途所用的时间对应的文本框为Text3和Text4,到达时间对应的文本框为Text5和Text6,计算按钮为Command1。(时间形式:小时:分钟,24小时制)
Private Sub Command1_Click()
Dim cfs%, cff%, lts%, ltf%, ddsj%
Dim dds%, ddf%
cfs = Val(Text1.Text)
cff = Val(Text2.Text)
lts = Val(Text3.Text)
ltf = Val(Text4.Text)
ddsj = (cfs * 60 + cff) + (lts * 60 + ltf)
dds = ddsj \ 60
ddf = ddsj Mod 60
Text5.Text = dds
Text6.Text = ddf
End Sub
1、用户单击交换按钮Command1,交换2个文本框Text1和Text2的内容
Private Sub Command1_Click()
Dim temp$
temp = Text1.Text
Text1.Text = Text2.Text
Text2.Text = temp
End Sub
2、点击按钮Command1,程序分别输入矩形的长和宽,输出矩形的周长和面积,结果保留2位小数。使用InputBox和MsgBox完成输入输出。(第一次输出矩形周长,第二次输出矩形面积)
Private Sub Command1_Click()
Dim c#, k#, p#, s#
c = Val(InputBox("c=?"))
k = Val(InputBox("k=?"))
p = Round(2 * (c + k))
s = Round(c * k, 2)
MsgBox str(p)
MsgBox str(s)
End Sub
3、点击按钮Command1,程序输入圆的半径,输出圆的周长和面积,结果保留2位小数。使用InputBox和MsgBox完成输入输出。(PI为3.14,第一次输出圆周长,第二次输出圆面积)
Private Sub Command1_Click()
Dim r#, s#, p#
r = Val(InputBox("r=?"))
p = Round(2 * 3.14 * r, 2)
s = Round(3.14 * r * r, 2)
MsgBox str(p)
MsgBox str(s)
End Sub
4、在文本框Text1中输入1个小写英文字母,点击加密按钮Command1,则将该英文字母变为字母表中其后面的一个字母放入文本框Text2中,如a改为b,m改为n,z改为a,以此类推。点击解密按钮Command2,将文本框Text2中字母解密后放入Text1中。
Private Sub Command1_Click()
Dim yw As String * 1, mw As String * 1
yw = Text1.Text
mw = Chr(97 + (Asc(yw) - 97 + 1) Mod 26) ‘或Chr(Asc(“a”) + (Asc(yw) - Asc(“a”)+ 1) Mod 26)
Text2.Text = mw
End Sub
Private Sub Command2_Click()
Dim yw As String * 1, mw As String * 1
mw = Text2.Text
yw = Chr(122 + (Asc(mw) - 122 - 1) Mod 26) ‘或Chr(Asc(“z”) + (Asc(mw) - Asc(“z”) - 1) Mod 26)
Text1.Text = yw
End Sub
5、在文本框Text1中输入1个小写英文字母,点击加密按钮Command1,则将该英文字母变为字母表中其后面的第N个字母放入文本框Text2中,N表示加密方法,由Text3中的值指定。如N为2,则a加密后变为c,z加密后变为b,以此类推。点击解密按钮Command2,将文本框Text2中字母解密后放入Text1中。
Private Sub Command1_Click()
Dim yw As String * 1, mw As String, fa As Integer
yw = Text1.Text
fa = Val(Text3.Text)
mw = Chr(97 + ((Asc(yw) - 97 + fa) Mod 26)) ‘或Chr(Asc(“a”) + (Asc(yw) - Asc(“a”)+ fa) Mod 26)
Text2.Text = mw
End Sub
Private Sub Command2_Click()
Dim yw As String * 1, mw As String, fa As Integer
mw = Text2.Text
fa = Val(Text3.Text)
yw = Chr(122 + ((Asc(mw) - 122 - fa) Mod 26)) ‘或Chr(Asc(“z”) + (Asc(mw) - Asc(“z”) - fa) Mod 26)
Text1.Text = yw
End Sub
6、在文本框Text1中输入3个小写英文字母,点击加密按钮Command1,则将每个字母改为英文字母表a-z中对应的第N个字母放入文本框Text2中,N表示加密方法,由Text3中的值指定。如N为2,则abz加密后变为cdb。点击解密按钮Command2,将文本框Text2中字母解密后放入Text1中。
Private Sub Command1_Click()
Dim yw As String * 3, y1$, y2$, y3$
Dim mw As String * 3, m1$, m2$, m3$
Dim fa%
yw = Text1.Text: fa = Val(Text3.Text)
y1 = Left(yw, 1): y2 = Mid(yw, 2, 1): y3 = Right(yw, 1)
m1 = Chr(97 + ((Asc(y1) - 97 + fa) Mod 26)) ‘或Chr(Asc(“a”) + (Asc(y1) - Asc(“a”)+ fa) Mod 26)
m2 = Chr(97 + ((Asc(y2) - 97 + fa) Mod 26)) ‘或Chr(Asc(“a”) + (Asc(y2) - Asc(“a”)+ fa) Mod 26)
m3 = Chr(97 + ((Asc(y3) - 97 + fa) Mod 26)) ‘或Chr(Asc(“a”) + (Asc(y3) - Asc(“a”)+ fa) Mod 26)
mw = m1 & m2 & m3
Text2.Text = mw
End Sub
Private Sub Command2_Click()
Dim yw As String * 3, y1$, y2$, y3$
Dim mw As String * 3, m1$, m2$, m3$
Dim fa%
mw = Text2.Text: fa = Val(Text3.Text)
m1 = Left(mw, 1): m2 = Mid(mw, 2, 1): m3 = Right(mw, 1)
y1 = Chr(122 + ((Asc(m1) - 122 - fa) Mod 26)) ‘或Chr(Asc(“z”) + (Asc(m1) - Asc(“z”) - fa) Mod 26)
y2 = Chr(122 + ((Asc(m2) - 122 - fa) Mod 26)) ‘或Chr(Asc(“z”) + (Asc(m2) - Asc(“z”) - fa) Mod 26)
y3 = Chr(122 + ((Asc(m3) - 122 - fa) Mod 26)) ‘或Chr(Asc(“z”) + (Asc(m3) - Asc(“z”) - fa) Mod 26)
yw = y1 & y2 & y3
Text1.Text = yw
End Sub
7、点击按钮Command1,程序输入x,通过分段函数计算并输出y。使用InputBox和MsgBox完成输入输出。
Private Sub Command1_Click()
Dim x As Double, y As Double
x = Val(InputBox("x=?"))
If x > 0 Then y = x * x
If x <= 0 Then y = -x
MsgBox y
End Sub
8、上下两个文本框分别为Text1和Text2,在两个文本框中任意输入2个整数,点击交换
按钮Command1,将2个数按照大小顺序放好
Private Sub Command1_Click()
Dim x As Integer, y As Integer, temp As Integer
x = Val(Text1.Text)
y = Val(Text2.Text)
If x < y Then temp = x: x = y: y = temp
Text1.Text = str(x)
Text2.Text = str(y)
End Sub
1、在文本框Text1中输入1个小写英文字母,点击加密按钮Command1,则将该英文字母变为字母表中其后面的一个字母放入文本框Text2中,如a改为b,m改为n,z改为a,以此类推。点击解密按钮Command2,将文本框Text2中字母解密后放入Text1中。
Private Sub Command1_Click()
Dim yw As String, mw As String
yw = Text1.Text
mw = Chr(97 + (Asc(yw) - 97 + 1) Mod 26) ‘或Chr(Asc(“a”) + (Asc(yw) - Asc(“a”)+ 1) Mod 26)
Text2.Text = mw
End Sub
Private Sub Command2_Click()
Dim yw As String, mw As String
mw = Text2.Text
yw = Chr(122 + (Asc(mw) - 122 - 1) Mod 26) ‘或Chr(Asc(“z”) + (Asc(mw) - Asc(“z”) - 1) Mod 26)
Text1.Text = yw
End Sub
2、在文本框Text1中输入1个小写英文字母,点击加密按钮Command1,则将该英文字母变为字母表中其后面的第N个字母放入文本框Text2中,N表示加密方法,由Text3中的值指定。如N为2,则a加密后变为c,z加密后变为b,以此类推。点击解密按钮Command2,将文本框Text2中字母解密后放入Text1中。
Private Sub Command1_Click()
Dim yw As String, mw As String, jmfa As Integer
yw = Text1
jmfa = Val(Text3)
mw = Chr(97 + (Asc(yw) - 97 + jmfa) Mod 26) ‘或Chr(Asc(“a”) + (Asc(yw) - Asc(“a”)+ jmfa) Mod 26)
Text2 = mw
End Sub
Private Sub Command2_Click()
Dim yw As String, mw As String, jmfa As Integer
mw = Text2
jmfa = Val(Text3)
yw = Chr(122 + (Asc(mw) - 122 - jmfa) Mod 26) ‘或Chr(Asc(“z”) + (Asc(mw) - Asc(“z”) - jmfa) Mod 26)
Text1 = yw
End Sub
3、点击按钮Command1,程序输入x,通过分段函数计算并输出y。使用InputBox和MsgBox完成输入输出。
Private Sub Command1_Click()
Dim x#, y#
x = Val(InputBox("x=?"))
If x > 0 Then
y = x * x
Else
y = -x
End If
MsgBox str(y)
End Sub
4、点击按钮Command1,程序分别输入语文、数学、英语的成绩,输出及格课程平均成绩。使用InputBox和MsgBox完成输入输出。
Private Sub Command1_Click()
Dim yw#, sx#, yy#, n%, s#, p#
yw = Val(InputBox("yw=?"))
sx = Val(InputBox("sx=?"))
yy = Val(InputBox("yy=?"))
n = 0
If yw >= 60 Then n = n + 1: s = s + yw
If sx >= 60 Then n = n + 1: s = s + sx
If yy >= 60 Then n = n + 1: s = s + yy
If n > 0 Then p = s / n Else p = 0
MsgBox str(p)
End Sub
5、点击按钮Command1,程序输入一个四位数,判断千位、百位、十位和个位数字之和是否为偶数,偶数输出Yes,否则输出No。使用InputBox和MsgBox完成输入输出。
Private Sub Command1_Click()
Dim x%, q%, b%, s%, g%
x = Val(InputBox("x=?"))
q = Int(x / 1000)
b = Int((x - q * 1000) / 100)
s = Int((x - q * 1000 - b * 100) / 10)
g = x - q * 1000 - b * 100 - s * 10
If (q + b + s + g) Mod 2 = 0 Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub
1、点击按钮Command1,程序分别输入3个整数,输出最大值。使用InputBox和MsgBox完成输入输出。
Private Sub Command1_Click()
Dim a%, b%, c%, max%
a = Val(InputBox("a=?"))
b = Val(InputBox("b=?"))
c = Val(InputBox("c=?"))
max = a
If b > max Then max = b
If c > max Then max = c
MsgBox max
End Sub
2、点击按钮Command1,程序分别输入3个整数,输出最小值。使用InputBox和MsgBox完成输入输出。
Private Sub Command1_Click()
Dim a%, b%, c%, min%
a = Val(InputBox("a=?"))
b = Val(InputBox("b=?"))
c = Val(InputBox("c=?"))
min = a
If b < min Then min = b
If c < min Then min = c
MsgBox str(min)
End Sub
3、交话费送话费活动,交话费100元及以上送8元,否则送所交话费的5%。点击按钮Command1,程序分别输入原有话费和新交话费,输出总话费。使用InputBox和MsgBox完成输入输出。
Private Sub Command1_Click()
Dim yyhf!, xjhf!, zhf!
yyhf = Val(InputBox("yyhf=?"))
xjhf = Val(InputBox("xjhf=?"))
If xjhf >=
展开阅读全文