由于某些原因,我在让代码正确处理数组时遇到了问题。对于数组中的几乎所有元素,它都可以工作,但由于某些原因,它无法识别数组中一系列连续的四个元素。该数组填充一个ComboBox,它可以很好地做到这一点。但是当我验证用户的输入时,它就像是随机决定不识别数组中位置6-9的元素。该数组只是美国明尼苏达州以外的州和地区的列表。
Dim vOtherStates() As String
'Minnesota excluded from list of states.
vOtherStates = Split("Select State|Alabama|Alaska|Arizona|Arkansas|California|" _
& "Colorado|Connecticut|Delaware|District of Columbia|" _
& "Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|" _
& "Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|" _
& "Michigan|Mississippi|Missouri|Montana|Nebraska|" _
& "Nevada|New Hampshire|New Jersey|New Mexico|New York|" _
& "North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|" _
& "Puerto Rico|Rhode Island|South Carolina|South Dakota|Tennessee|" _
& "Texas|Utah|Vermont|Virginia|Virgin Islands|Washington|" _
& "West Virginia|Wisconsin|Wyoming", "|")
Function ValidState(state As String) As Boolean
Dim osSelect As Boolean
Select Case state
Case 0 To 52
' any ListIndex from 0 to 52 IS selected and execution may continue
osSelect = True
Case Else
' ListIndex 0 to 52 is NOT selected and execution fails
osSelect = False
End Select
If osSelect = False Then
MsgBox "Please choose a state from the options listed.", , "Validation Error"
ValidState = False
Exit Function
Else:
ValidState = True
End If
End Function如果你能给我任何帮助,告诉我为什么它会这样做,我将不胜感激。谢谢。
发布于 2015-03-30 23:55:43
正如@Sobigen在函数中指出的那样,将数据类型更改为long (从字符串)解决了这个问题。
https://stackoverflow.com/questions/29350038
复制相似问题