VBA宏运行时错误6:循环内的溢出编码 [英] VBA Macro Run time error 6: overflow- coding inside a loop

查看:527
本文介绍了VBA宏运行时错误6:循环内的溢出编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此错误有问题.我正在创建一个GA,循环是将我的适应性值分配给一个数组.

Having a problem with this Error. I am creating a GA and the loop is to assign my fitness value to an array.

一些变量

Dim Chromolength as integer
Chromolength = varchromolength * aVariables 
Dim i as integer, j as integer, counter as integer
Dim Poparr() As Integer
Dim FitValarr() As Integer

代码:

ReDim Poparr(1 To PopSize, 1 To Chromolength)

For i = 1 To PopSize                
  For j = 1 To Chromolength       
    If Rnd < 0.5 Then           
        Poparr(i, j) = 0
    Else
        Poparr(i, j) = 1        
    End If
  Next j
Next i

For i = 1 To PopSize                   
 j = 1                           
 counter = Chromolength              
 Do While counter > 0  
   FitValarr(i) = FitValarr(i) + Poparr(i, counter) * 2 ^ (j - 1)          
  j = j + 1                   
  counter = counter - 1       
 Loop
Next i      

我在遇到问题:

FitValarr(i) = FitValarr(i) + Poparr(i, counter) * 2 ^ (j - 1) 

很抱歉,我对VBA还是很陌生.

I apologize, I am fairly new to VBA.

推荐答案

当您创建一个整数表达式时,会产生溢出条件,该整数表达式的值大于16位有符号整数所能表示的值.给定表达式,FitValarr(i)的内容或表达式2 ^(j-1)可能溢出.建议将当前声明为Int的所有变量更改为Long.长整数是32位带符号的值,并提供相应范围更大的可能值.

An overflow condition arises when you create an integer expression that evaluates to a value larger than can be expressed in a 16-bit signed integer. Given the expression, either the contents of FitValarr(i), or the expression 2^(j-1) could be overflowing. Suggest all the the variables presently declared as Int be changed to Long. Long integers are 32-bit signed values and provide a correspondingly larger range of possible values.

这篇关于VBA宏运行时错误6:循环内的溢出编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆