PDA

View Full Version : Solved: Argument Not Optional Error



MikeDube
10-21-2009, 06:58 PM
I am writing a code that prompts the user for the location of a text value. Once it gets the text file it stores it as filename. I then brought filename over to this subroutine to parse it out into a multidimensional array. For some reason however, I keep getting argument not optional even though I had help writing the code and it seems to work. The code is:

Public Sub AnalyzeTradeLog_Click(Filename)
Dim TraderLog As Object
Dim TraderLogTxtFile As Object
Dim TraderLogArray As Variant
Dim TempArray As Variant
Dim i As Long
Dim x As Long
Dim y As Long
Dim Cols As Long
Set TraderLog = CreateObject("Scripting.FileSystemObject")
Set TraderLogTxtFile = TraderLog.OpenTextFile(Filename)
With TraderLogTxtFile
i = i + 1
Cols = UBound(Split(.ReadLine, vbTab, , vbTextCompare)) + 1
Do While Not TraderLogTxtFile.AtEndOfStream
i = i + 1
TraderLogTxtFile.SkipLine
Loop
TraderLogTxtFile.Close
End With
ReDim TraderLogArray(1 To i, 1 To Cols)
Set TraderLogTxtFile = TraderLog.OpenTextFile(Filename)
With TraderLogTxtFile
For x = 1 To UBound(TraderLogArray, 1)
TempArray = Split(.ReadLine, vbTab, , vbTextCompare)
For y = LBound(TempArray) To UBound(TempArray)
TraderLogArray(x, y + 1) = TempArray(y)
Next y
Next x
End With
Range("A1").Resize(UBound(TraderLogArray, 1), UBound(TraderLogArray, 2)).Value = TraderLogArray
End Sub

MikeDube
10-21-2009, 08:22 PM
I'm sorry to anyone who wasted their time looking at this. The error was simply that I wasn't specifying the filename deep enough (i.e. text.exe instead of c:\Desktop\[...]\txt.exe