如何在vb6中编写此代码?

如何在vb6中编写此代码?,vb6,Vb6,如何获取数组中用于循环条件的下一个值 dim x(10) as integer dim d1,d2 as integer for i = 0 to 10 d1 = x(1) 'first value in an array e.g. is 10 d2 = x(2) 'second value in an array e.g. is 20 if (d2-d1) > 1 then Msgbox "Item Count" else msgbox "Item

如何获取数组中用于循环条件的下一个值

dim x(10) as integer
dim d1,d2 as integer

for i = 0 to 10 

 d1 = x(1) 'first value in an array e.g. is 10
 d2 = x(2) 'second value in an array e.g. is 20

 if (d2-d1) > 1 then
     Msgbox "Item Count"
 else 
     msgbox "Item Deleted"
 end if

next i

如果我正确理解了您的需求,您需要使用步骤关键字和for循环,如下所示:

Dim x(10) As Integer
Dim d1, d2 As Integer
Dim i As Integer

For i = 0 To 8 Step 2

 d1 = x(i + 1) 'first value in an array e.g. is 10
 d2 = x(i + 2) 'second value in an array e.g. is 20

 If (d2 - d1) > 1 Then
     MsgBox "Item Count"
 Else
     MsgBox "Item Deleted"
  End If

Next i

为什么这是标记的
SQL
?我很抱歉标记SQL,我在数据库中使用SQL。虽然这不是我要问的问题的一部分,但它会帮助我们,如果你告诉我们你试图通过这段代码实现什么,它会帮助你。您正在搜索数组中的最大值吗?有更好的方法。通常你会在下一次迭代的顶部检查,当你有正确的数据时。如果他想按顺序测试呢?不是每一对数字,也忽略了数组的0索引,尝试(i)和(i+1)instead,我只想对每个循环设置第二个数组的值在第一个数组上要扣除的条件。假设第一个循环上第一个数组的值是10,然后我想得到第二个循环上第二个数组的值,假设它是20。然后在整个循环中按顺序完成。。