简体   繁体   English

数组填充无法正常工作

[英]Array fill not working as expected

I am trying to fill an array of length 300 with the same value using VB here is my code: 我正在尝试使用VB用相同的值填充长度为300的数组,这是我的代码:

Dim counter As Integer
If (value = True) Then
    For counter = LBound(arrLowThresholds) To UBound(arrLowThresholds) Step 1
        arrLowThresholds(counter) = LOG_TEST_LOW_THRESHOLD
        arrHighThresholds(counter) = LOG_TEST_HIGH_THRESHOLD
    Next
End If

The problem with this is that only the first element of the arrays is being filled. 问题在于,只有数组的第一个元素被填充。 Note that some of the variables are declared elsewhere that is the reason that the declaration is not visible. 请注意,某些变量在其他地方声明,这是声明不可见的原因。

arrLowThresholds and arrHighThresholds are the arrays while LOG_TEST_LOW_THRESHOLD and LOG_TEST_HIGH_THRESHOLD are the variables arrLowThresholdsarrHighThresholds是数组,而LOG_TEST_LOW_THRESHOLDLOG_TEST_HIGH_THRESHOLD是变量

I solved the problem by making a local array to use with the for loop. 我通过使局部数组与for循环一起使用来解决了这个问题。 Then I copied the contents to the array I am actually using. 然后,我将内容复制到实际使用的数组中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM