Opv
05-22-2011, 12:41 PM
I'm playing around with a script that lists the items from a variant and then allows the user to select which item to be used. For example:
Sub Exercise()
Dim Answer As Byte
Dim test, results As String
Dim mytest As Variant
Dim i As Long
test = "Test1; Test2; Test3"
mytest = Split(test, "; ")
For i = 0 To UBound(mytest)
results = results & mytest(i) & vbCrLf
Next
Answer = CByte(InputBox(results))
MsgBox mytest(Answer)
The issue I have with this script is that with a variant the first item on the list is Item 0 rather than Item 1, which I expect could be confusing when someone looks at the Input box and desires to select the "first" item on the list. Selecting "3", for example, would result in an "out of range" error.
Is there a way to do something like the above so that the number selected matches the item order on the input box list?
Sub Exercise()
Dim Answer As Byte
Dim test, results As String
Dim mytest As Variant
Dim i As Long
test = "Test1; Test2; Test3"
mytest = Split(test, "; ")
For i = 0 To UBound(mytest)
results = results & mytest(i) & vbCrLf
Next
Answer = CByte(InputBox(results))
MsgBox mytest(Answer)
The issue I have with this script is that with a variant the first item on the list is Item 0 rather than Item 1, which I expect could be confusing when someone looks at the Input box and desires to select the "first" item on the list. Selecting "3", for example, would result in an "out of range" error.
Is there a way to do something like the above so that the number selected matches the item order on the input box list?