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

problem with strcmp()

Status
Not open for further replies.

damonh78

Programmer
Jul 28, 2005
44
IE
Hi

I am trying to do a string compare on variables from 2 arrays:
result = StrComp(colArray(z), CStr(the_array(0)(y)))

the 1st colArray is declared as a string array and contains 3 fixed strings whose position I am trying to find in the 2nd array which is declared as a variant array and so I am using cstr to cast it to a string.

For some reason even when the variables have the same value the strcomp function sees them as different.
For instance in debug mode when both variables should have the value of .number when I put my cursor over the colArray(z) variable I get ".number" but when I put it over the_array(0)(y) variables the value comes up with 2 sets of "" on each side, ie "".number"" , what does this mean?

I am new to VB and have never seen a variable with 2 exclamation marks on each side. Is this my problem?

Below is the code I am using (with some of the declarations), the procedure takes in a file line by line and feeds in into an array, the files is comma delimited and so it is then tokenized using the split() function. Then I try to use the strcomp() function to try and find the positions of the 3 fixed strings contained in colArray in the_array.

Private Sub processFile(objFile As File)

Dim lines() As String
Dim num_rows As Long
Dim the_array() As Variant
Dim numArray(3) As Integer
Dim numCol As Integer
Dim result As Integer
Dim mTxtStream As TextStream
Dim q As Integer

Set mTxtStream = objFile.OpenAsTextStream(ForReading)
'read the file into an array a line at a time
q = 0
ReDim Preserve lines(1)
Do While Not mTxtStream.AtEndOfStream
ReDim Preserve lines(UBound(lines) + 1)
lines(q) = mTxtStream.ReadLine
q = q + 1
Loop

' Dimension the array.
num_rows = UBound(lines)
'MsgBox num_rows
ReDim the_array(num_rows)

' Copy the data into the array.
'end up with 2d array the_array(R)(C)where r = rows, c = columns
For R = 0 To num_rows
the_array(R) = Split(lines(R), ",")
Next R
'find num columns needed as am having problem with ubound on 2d array
tempArray = Split(lines(0), ",")
numCol = UBound(tempArray)
MsgBox numCol
MsgBox the_array(0)(1)
'find the columns the array strings reside in reside in
'cols start as 0
For z = 0 To (UBound(colArray) - 1)
For y = 0 To numCol - 1
result = StrComp(colArray(z), CStr(the_array(0)(y)))
If result = 0 Then
numArray(z) = y
MsgBox numArray(z)
Exit For
End If
Next y
Next z

end sub

Thanks in Advance,

John
 
Try this:

lines(q) = mTxtStream.ReadLine
lines(q) = Replace(lines(q),"""","")

this should remove any quotes in the line read in.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Jebenson,

That works perfectly thanks very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top