下标超出范围 [英] Subscript out of range

查看:124
本文介绍了下标超出范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub Combofullname_LostFocus()
Dim temp As Variant
If Text2.Text = Empty Then Exit Sub
temp = Split(Combo14.Text, " ")
   If temp(0) <> Empty Then
   
   If UBound(temp) Then
        Text2.Text = temp(0)
 Else
 If UBound(temp) Then
       Text3.Text = temp(1)
 Else
 If UBound(temp) Then
        Text4.Text = temp(2)
    End If
    End If
    End If
    End If
End Sub



当我运行此代码时,它会显示超出范围的错误下标。

请帮助


When I run this code it shows error subscript out of range.
Please help

推荐答案

变种......哦,天哪!



无论如何,这是你的错误:



调用 Split 可能会给一个只包含一个元素的数组。比 temp(1) temp(2)将解决不存在的数组元素。



-SA
Variant… Oh, gosh!

Anyway, here is your bug:

The call to Split may give an array with just one element. Than temp(1) or temp(2) will address non-existing array element.

—SA


您需要确保索引正确且在范围内。确保在拆分后,你有0,1,2个索引。只是DEBUG,看看它失败的地点和时间。



在这里,看看这些:

MSDN:下标超出范围(错误9) [ ^ ]

MSDN:下标超出范围(Visual Basic) [ ^ ]
You need to make sure that the index is correct and in range. Make sure, post split, you do have 0,1,2 indexes. Just DEBUG and see where and when it fails.

Here, have a look at these:
MSDN: Subscript out of range (Error 9)[^]
MSDN: Subscript out of range (Visual Basic) [^]


这篇关于下标超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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