现将X改为100,Y改为200,下列说法正确的是( )
Private Sub Command1_Click()
For i = 150 To 300
a = i \ 100
b = I mod 100 \ 10
c = i – a*100 – b*10
If i = a * a * a + b * b * b + c * c * c Then
Label1.Caption = Str(i)
End If
Next i
End Sub
程序代码如下:
Private Sub Command1_Click()
Dim Sname As String, Skey As String ‘Sname 保存姓名,Skey保存关键字
Dim i As Integer, j As Integer, n As Integer ‘n关键字的长度
Skey = Text1.Text
n = Len(Skey)
List2.Clear
For i = 1 To List1.ListCount ‘ListCount是列表框中项目的个数
Sname = List1.List(i - 1) ‘将List1中的第i-1项赋值给Sname
For j = 1 To ①
If Skey = ② Then
List2.AddItem Sname
Exit For
End If
Next j
Next i
If ③ = 0 Then List2.AddItem "没有找到带<" & Skey & ">的名字。"
End Sub
图2
图3
程序代码如下:
Private Sub Command1_Click()
Dim n As Integer, i As Integer
List1.Clear
n = Val(Text1.Text)
If n Mod 2 = 0 Then
For i = 2 To Int(n / 2)
If isodd(i) = (isodd(n - i)) Then
List1.AddItem Str(n) + " =" + Str(i) + " +" + Str(n - i)
End If
Next i
Else
Text1.Text = Str(n) + "不是偶数!"
End If
End Sub
Private Function isodd(n As Integer) as boolean
Dim f As integer
f = 0
For i = 2 To Sqr(n)
If n Mod i = 0 Then f = 1: Exit For
Next i
isodd = f
End Function
⑴用一个数组product()来存放产品名。
⑵用另一个数组a()来存放产品名数据的下标(已经按产品名排序的)。
按产品名排序的方法是:取第一个产品名product(0),与后面所有的产品名比较一遍,如果有比第一个产品名大的,M+1,M用来计该产品名的位次。一轮结束后在a(M)元素记下第一个产品名的下标0。然后再取product(1)与其它所有产品名比较一遍,其余同第一个产品名。依次完成每一个产品名位次的计算并记录在a()数组中。
⑶最后按a()数组指定的位置取出list1中的项添加到list2中。
程序代码如下,请补充完整下面的空缺。
Dim products(100) As String '存放产品名的数组
Dim num As Integer '从数据库中读出的记录数
Private Sub Command1_Click()
Dim a(100) As Integer '存放按产品名索引的产品数组下标
Dim i As Integer, j As Integer, m As Integer 'm比当前产品名大的产品名个数
For i = 0 To 100
a(i) = 0
Next i
For i = 0 To num
m = 0
For j =
If i <> j And products(i) > products(j) Then m = m + 1
Next j
Next i
For i = 1 To num
List2.AddItem '按a数组的索引从list1中取出项添加到list2
Next i
End Sub
Private Sub Form_Load()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim s As String, i As Integer
conn.ConnectionString = "provider=microsoft.ace.oledB.12.0;data source=" & App.Path & "\产品库.accdb "
conn.Open
Set rs.ActiveConnection = conn
rs.Open "select * from product"
num = 0
Do While Not rs.EOF And num <= 100
s = ""
For i = 1 To 5
products(num) = rs.Fields(2) '读出当前记录的产品名保存到products数组
s = s & rs.Fields(i - 1) & " ," '将一条记录的各字段内容连接成字符串
Next i
List1.AddItem s
num = num + 1
Loop
num = num - 1
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
End Sub