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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redim Arrays......Need Help!

Status
Not open for further replies.

pghsteelers

Technical User
Apr 21, 2006
121
US
I have an array that will take a variable and assign each "character" to an index of the array. Now, the variable that I am working with is a file versions which allot of the time is made up of multiple decimal points. Therefore, I do two other steps while assigning each character of the file version to an array:
1) I count the number of characters before reaching a non-numeric value and
2) I add up the value of the numbers until a non-numeric value is reached.

I then place both values in a 2D array. Each row of the 2D array contains first the value added (see #1) and the second column I place the number of characters counted before the non-numeric (see #2).

However, the problem or what I am seeking help with is how I can code in that the 2D array will be redim to the correct size. For example 11.2.39.0 would be 4 rows (0-3)

as of now, I have thrown a check in the loop that is assigning the variable characters to the array to count the number of decimals, then Redim the 2D array to 1 more than the decimal account. So if a variable was found to have 3 decimals the 2d array would be:

Redim array(decimalcnt +1).

But I have to consider all oddities such as some variable like 11.3....4.9. where the 2D array would end up having 8 rows, but would only end up having 4 values. The other rows would be NULL.

How could I code it to place a 0 for each row that was found to not have a value, because the array had consecutive decimals such as 11.3....4.9. ?
Would it be easier just to throw the 2d throw a For..Next loop to check each index for an "" NULL value and assign it 0 or could this be done at the time of assigning values to the 2D array?

I encluded the code I am working on so hopefully I haven't confused everyone.

Function CreateArray(CurrVer, CompVer, arrCurrVer(), arrCompVer(), arrCurrSegSum(), arrCompSegSum())
Dim i, CurrDigCnt, CompDigCnt, CurrDecCnt, SegSwitch
CurrIndxCnt = 0
SegSwitch = 0
CurrDecCnt = 0

Redim arrCurrSegSum(Len(CurrVer) - 1)
Redim arrCompSegSum(Len(CompVer) - 1)

for i=0 to len(CurrVer)-1
arrCurrVer(i) = mid(CurrVer,i+1,1)
if IsNumeric(arrCurrVer(i)) = False Then
CurrDecCnt = CurrDecCnt + 1
End If
next

for i=0 to len(CompVer)-1
arrCompVer(i) = mid(CompVer,i+1,1)
if IsNumeric(arrCompVer(i)) = False Then
CompDecCnt = CompDecCnt + 1
End If
next

Redim arrCurrSegSum(CurrDecCnt + 1, 1)
Redim arrCompSegSum(CompDecCnt + 1, 1)

For i = 0 to len(CurrVer)-1
if IsNumeric(arrCurrVer(i)) = True Then
arrCurrSegSum(SegSwitch, 0) = arrCurrSegSum(SegSwitch, 0) + arrCurrVer(i)
arrCurrSegSum(SegSwitch, 1) = arrCurrSegSum(SegSwitch, 1) + 1
ElseIf IsNumeric(arrCurrVer(i)) = False Then
SegSwitch = SegSwitch + 1
End If
Next

SegSwitch = 0

for i=0 to len(CompVer)-1
if IsNumeric(arrCompVer(i)) = True Then
arrCompSegSum(SegSwitch, 0) = arrCompSegSum(SegSwitch, 0) + arrCompVer(i)
arrCompSegSum(SegSwitch, 1) = arrCompSegSum(SegSwitch, 1) + 1
ElseIf IsNumeric(arrCompVer(i)) = False Then
SegSwitch = SegSwitch + 1
End If
Next

 
Have a look at the Split function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
This what you're looking for?

CurrVer = "11.3....4.9."
arrVer = Split(CurrVer,".")
For i = 0 to UBound(arrVer)
If arrVer(i) = "" then arrVer(i) = "0"
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top