string arrays and parameters

inzo21

Regular
Joined
Nov 5, 2003
Messages
74
Hi everyone.

I'm trying to pass a list of string values through a procedure that will remove the values of the strings from a text file. This procedure is in a seperate class and is called by a module using the command line.

the code I have for the proc:
---Begin---
Public Sub RemoveFile(ByVal RemovalList() As String)
Dim FileInList As String
Dim IsSameFile As Integer
Dim TempFileList As New ArrayList()
Dim FileToRemove As String

FileInList = FileStreamReader.ReadLine()

For Each FileToRemove In RemovalList

While Not FileInList Is Nothing
IsSameFile = FileToRemove.CompareTo(FileInList)
If IsSameFile <> 0 Then
TempFileList.Add(FileInList)
FileInList = FileStreamReader.ReadLine()
Else
LogEntry.AddEntry("The File " & FileInList & " was removed ")
FileInList = FileStreamReader.ReadLine()
End If
End While
Next FileToRemove

...and some other stuff to recreate

--End--

I'm trying this in the module

myclass.removefile("this.txt", "that.txt")

no soup. No matter how many vales, I receive a ("Value of Type String cannot be converted to a 1-dimensional array of String)

I understand the error - but can't think of another way to get this functionality.

I've tried using collections, arraylists, and the like - still no luck. I'm guessing it's a simple problem that I'll see after many a beers. But, if any of you have an idea - I'd be much obliged.

inzo
 
What you are doing is passing in 2 arguments, when the method wants only one, an array. You could build that array in your method, or if you want to pass in a smiliar way you showed you can do it like this:
Visual Basic:
RemoveFile(New String(){"firstvalue", "secondvalue", "thridvalue"})
 
got it

Thanks for the input. As expected, after a beer or two I came up with a different solution.

I passed a String array to the method call (rather than multiple string objects or casting a new object in the parameter). I'll be doing this anyway.

Then, I modified the code in the method to parse the array. for those interested, here'w what I came up with.

--Begin code--

Public Sub RemoveFile(ByVal RemovalList() As String)
Dim FileInList As String
Dim IsSameFile As Integer
Dim TempFileList As New ArrayList()
Dim FileToRemove As String
Dim removecounter As Integer = 0

FileInList = FileStreamReader.ReadLine()
TempFileList.Clear()

While Not FileInList Is Nothing
TempFileList.Add(FileInList)
FileInList = FileStreamReader.ReadLine()
End While

FileStreamReader.Close()

For Each FileToRemove In RemovalList
Do
removecounter = TempFileList.Count
TempFileList.Remove(FileToRemove)
Loop While TempFileList.Count < removecounter

Next FileToRemove


--End Code-

Basically, this sub reads a file - puts the string values into an arraylist object, compares all values of the String array passed to it in the paramater call, and removes those values from the arraylist that are identical in the list.

I then use an enumerator object to rebuild the original file with the values left in the arraylist.

Not sure if it is the most efficient way, but it gets the job done for now.

thanks again.

inzo
 
Back
Top