Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change array of strings to array of Integers 1

Status
Not open for further replies.

BiggerBrother

Technical User
Sep 9, 2003
702
GB
I have a number of arrays, all of which contain strings (approx 500). In a function, a new array is formed, which takes all these string values (all numeric), and converts them into integer arrays.

For example, one array is "2","1","23" which then converts to 2,1,23. This works fine in the application, however, when I build the .exe, I receive an error of: function call on left-hand side of assignment must return Variant or Object.

publice function StrToInt(StrArray() as string) as integer()
dim a as integer
redim StrToInt(ubound(StrArray))
for a = lbound(StrArray) to Ubound(StrArray)
StrToInt(a) = CInt(StrArray(a))
next a

end function

Thanks for any ideas or guidance.

BB
 
I don't know why this is, nor why it only occurs in an .exe, but the error points to:
Code:
public function StrToInt(StrArray as variant) as variant

dim Result() as variant
dim a as integer

redim Result(ubound(StrArray))
for a = lbound(StrArray) to Ubound(StrArray)
    Result(a) = CInt(StrArray(a))
next a

StrToInt = Result
end function

By the way: why take all the trouble? Can't you just convert to integer when you read a value?
intValue = cint(strArray(x))

 
I have to pass another function an array of integer, and so using this function to convert the whole array, means that I can call it for every array, rather than having to hard code each instance separately.

Thanks

BB
 
Sorted it:

publice function StrToInt(StrArray() as string) as integer()

dim a as integer
dim temp() as integer

redim StrToInt(ubound(StrArray))
redim temp(ubound(StrArray))

for a = lbound(StrArray) to Ubound(StrArray)
temp(a) = CInt(StrArray(a))
next a

StrToInt = temp

end function

Cheers

BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top