![]() |
|
#1
|
|||
|
|||
|
Code:
Sub q()
Dim vInput As Variant
vInput = InputBox("", "", "9,1,3,5,6,2,4,10,7,8")
Dim arr As Variant, a As Variant
arr = Split(vInput, ",")
Debug.Print TypeName(arr) '' String()
For a = LBound(arr) To UBound(arr)
arr(a) = CInt(arr(a)) '' to convert string to integer
Debug.Print TypeName(arr(a)) '' String
Next a
End Sub
I ask it here. I code the above in Word though. I want to use CInt() to convert each item in an array from string to integer but it fails. How can I convert a string array to an integer array? Thank you. |
|
#2
|
||||
|
||||
|
Try:
Code:
Sub q()
Dim vInput As Variant
vInput = InputBox("", "", "9.1,1,3,5,6,2,4,10,7,8")
Dim arr(), a As Long
For a = 0 To UBound(Split(vInput, ","))
ReDim Preserve arr(a)
arr(a) = CInt(Split(vInput, ",")(a)) '' to convert string to integer
MsgBox arr(a) & vbTab & TypeName(arr(a))
Next a
End Sub
arr(a) = CLng(Split(vInput, ",")(a))
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Quote:
Thanks for your hint, not that I didn't really know what Long is. |
|
#4
|
||||
|
||||
|
A 'Long' is an variable that can store larger integer values than an 'Integer' variable. In more recent versions of Office, 'Integer' variables are actually stored in memory as Long variables. What this means is that a type conversion is required to convert 'Integer' variables to/from Long variables each time they're used. That type conversion has a small processing overhead.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#5
|
|||
|
|||
|
Quote:
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Array argument in macro command | Wries | Excel Programming | 2 | 11-20-2012 01:08 AM |
| How to reserve an array in a public function? | tinfanide | Word VBA | 2 | 02-27-2012 06:51 AM |
Complex array formula
|
andrei | Excel | 9 | 02-03-2012 03:40 AM |
| How to capture start and ending Ref. Nos. in an array | KIM SOLIS | Excel | 5 | 09-07-2011 07:43 AM |
| Look up an array based on user input | johnsmb | Excel | 2 | 01-07-2011 01:12 PM |