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

Another array question

Status
Not open for further replies.

brlissab

Technical User
Oct 11, 2002
35
CH
Hi
Have text file(with numeric values), With undefined lines and six columns(at the Moment).
Here is my kode, who creates dyn Array

nFile = "FileDir\nList.txt"
ForReading = 1
Dim MyArray()
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = oFSO.OpenTextFile(nFile,1)

If Not objTextFile.AtEndOfStream Then
strReadAll = objTextFile.ReadAll
ArrRow = Split(strReadAll, vbcrlf)
For i = 0 To Ubound(ArrRow)
ArrCol = Split(ArrRow(i), ",")
If i = 0 Then
Redim MyArray(UBound(ArrRow), UBound(ArrCol))
End If
For j = 0 To UBound(ArrCol)
MyArray(i,j) = ArrCol(j)
Next
Next
End If

You can access dimensions of the dyn Array by a

Wscript.Echo UBound(MyArray,1), Ubound(MyArray,2)

My Question, how can i calculate sum of all comluns, no matter lines quantity?
Some ideas or suggestions would be nice.
Best cumpliments

 
A starting point:
For j = 0 To UBound(MyArray,2)
myTot = 0
For i = 0 To UBound(MyArray,1)
myTot = myTot + MyArray(i,j)
Next
MsgBox "Total of column #" & (j+1) & " = " & myTot
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Works fine!
I Would like to develop some array functions to get harder into code, but for arrays(2d) with numeric and monetary values, vba for excel is maybe a better way to get it.
Also , i'm progressing in vbs, wich indeed i like it, but it would not a bad think considering vba for that kind of tasks and for code similitudes. what do you think?
Thank you for your help PHV.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top