vb的经典考试小程序有那些啊??

vb的经典考试小程序有那些啊??,第1张

建议你去百度找下历年的考题吧,我随便弄两题....答案也放下面

1、给定程序其功能是:建立并打印主对角线的元素为8,主对角线之上的元素为0,主对角线之下的元素为2的一个8 X 8的矩阵,请将程序写出

2、本程序的功能是计算给定正整数序列中奇数之和,请将程序写出

1、

Private Sub Command1_Click()

Dim matrix(8, 8) As Integer

Dim i As Integer, j As Integer

For i = 1 To 8

For j = 1 To 8

If i = j Then

matrix(i, j) = 8

ElseIf i <j Then

matrix(i, j) = 0

Else

matrix(i, j) = 2

End If

Print matrix(i, j)

Next

Print

Next

End Sub

2、

Option Explicit

Option Base 1

Private Sub Command1_Click()

Dim ss(), i As Integer, sum As Long

ss = Array(1, 2, 3, 4, 5, 11, 12, 13, 14, 15, 101, 102, 103, 104, 105)

sum = 0

For i = 1 To UBound(ss)

If ss(i) Mod 2 = 1 Then

sum = sum + ss(i)

End If

Next

Print sum

End Sub

画四个TEXT 文本,分别输入A,x,y,z

注意输入是数字哦

一个按钮。直接复制代码到VB中看,

(起先有事才没回你呢,你的消息我也没看到,,回来了才发现你作业交了哈哈,,,)

Private Sub Command1_Click()

Dim a As Integer

Dim x As Integer

Dim y As Integer

Dim z As Integer

a = Text1.Text

x = Text2.Text

y = Text3.Text

z = Text4.Text

Dim ax As Integer

Dim ay As Integer

Dim az As Integer

Dim m As Integer

Dim N(1000) As Integer '1000应该够了,,不会超标吧哈哈,,浪费点资源

Dim Nx(1000) As Integer

Dim Ny(1000) As Integer

Dim Nz(1000) As Integer

Dim s As Integer

m = 0

ax = (a - a Mod x) / x

ay = (a - a Mod y) / y

az = (a - a Mod z) / z

Dim fx As Integer

Dim fy As Integer

Dim fz As Integer

For fx = 1 To ax

For fy = 1 To ay

For fz = 1 To az

s = a - fx * x - fy * y - fz * z

If s >0 Then

m = m + 1

N(m) = s

Nx(m) = fx

Ny(m) = fy

Nz(m) = fz

End If

Next fz

Next fy

Next fx '各种情况都存入数组了

'============================下面比较大小==================

Dim kk As Integer

Dim min As Integer

Dim minx As Integer

Dim miny As Integer

Dim minz As Integer

min = N(1)

For kk = 1 To m - 1

If N(kk) <= min Then

min = N(kk)

minx = Nx(kk)

miny = Ny(kk)

minz = Nz(kk)

End If

Next kk

Print "最小余为:" &min

Print "x截的段数为:" &minx

Print "x截的段数为:" &miny

Print "x截的段数为:" &minz

End Sub

Private Sub cmdStart_Click()

cmdNext.【Enabled】 = True

cmdCheck.Enabled = True

cmdStart.Enabled = False

【call】 GenerateRND

End Sub

Public Sub GenerateRND()

lblFirst.Caption = Int(【100 * rnd】)

lblSecond.Caption = Int(【100 * rnd】)

End Sub

Private Sub cmdCheck_Click()

Dim operand As String

Dim var1 As Integer

Dim var2 As Integer

var1 = 【val】(lblFirst.Caption)

var2 = 【val】(lblSecond.Caption)

For i = 0 To 3

If 【optOperator(i)】 .Value = true Then

operand = 【optOperator(i)】 .caption

End If

Next

Select Case 【operand】

Case “+”

result = var1 + var2

Case “-”

result = var1 - var2

Case “*”

result = var1 * var2

Case “/”

result = var1 / var2

End Select

If result = Val(txtResult.【text】) Then

【msgbox】 (“计算正确!”)

Else

【msgbox】 (“错,请重新计算!”)

End If

End Sub

Private Sub cmdNext_Click()

Call 【GenerateRND】

End Sub

Private Sub cmdExit_Click()

【end】

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12126278.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存