如何解决索引超出了vb中数组的界限,见下面的编码 [英] how to solve index was outside the bounds of the array in vb, see below coding

查看:581
本文介绍了如何解决索引超出了vb中数组的界限,见下面的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

读取阅读按钮的信息

Read in information for Read button

Private Sub btnRead_Click(sender As Object, e As EventArgs) Handles btnRead.Click
    Dim F As Integer
    Dim P As Integer

    For F = 1 To NumFarmers
        MarsFarmers(F).Name = InputBox("Please enter farmer name" & CStr(F))
        MarsFarmers(F).Workers = CInt(InputBox("Please enter number of workers" & CStr(F)))
        For P = 1 To NumPeriods
            MarsFarmers(F).Profit(P) = CInt(InputBox("Please enter profit of farmer" & CStr(F)))
        Next P
    Next F
End Sub

推荐答案

数组从 0开始(零)到 count -1 除非选项库 [ ^ ]设置为 1



请参阅:

数组在Visual Basic中 [ ^ ]
Arrays start from 0 (zero) to count -1 unless Option Base[^] is set to 1.

See:
Arrays in Visual Basic[^]


NumFarmers 的值是多少? MarsFarmers 数组应具有此长度。



同样, NumPeriods的值是多少?每个MarsFarmer的利润数组都应该有这个长度。



如何实例化/初始化这些数组?



否则,解决这个问题的最简单方法是在方法开头加上一个beakpoint,按F5并按F11开始逐行调试;仔细观察每个步骤中的每个相关变量,并确认它与您认为的相应。
What is the value of NumFarmers? MarsFarmers array should have this length.

Similarly, what is the value of NumPeriods? The Profit array for each "MarsFarmer" should have this length.

How do you instantiate/initialize these arrays?

Otherwise, the simplest way to solve that is to put a beakpoint at the beginning of the method, press F5 and start debugging line by line by pressing F11; carefully watch for every relevant variable at each step, and confirm it is equal to what you think it should.


这篇关于如何解决索引超出了vb中数组的界限,见下面的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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