+ -
当前位置:首页 → 问答吧 → VB取最接近的数问题

VB取最接近的数问题

时间:2011-08-22

来源:互联网

a(0) = 2000
a(1) = 4000
a(2) = 6000
.....
.....

b 是随机数的

如果这时 b= 5000

我要把最接近的数 6000(a2) - b

应该怎样做呢?

作者: billy327   发布时间: 2011-08-22

貌似 4000,6000一样近把。

作者: BestBadGod   发布时间: 2011-08-22

dim result as long
dim j as long 
dim b as long 

b=5000
result =999999

for i=0 to ubound(a)
  if (asb(a(i)-b)<asb(result) then
  result =asb(a(i)-b)
  j=i
  end if 
next i

debug.print "最接近的数为a(" & j & "),差值为:" & result

作者: BestBadGod   发布时间: 2011-08-22

热门下载

更多