String functions frustration:

LifesGladiator

New member
Joined
Oct 5, 2010
Messages
2
Programming Experience
1-3
Hi,

Im using VB Express 2010.

Ive had previous VB 6 experience and have been playing around with VBA for some time. Now, I have started working on VB.NET (A complete no brainer i am on .NET)

Okay here is the problem:

I have a Multiline string lets name it ToolsSubscribedTo it contains the following text:
Appscan
CC
CCMS
CQ
CQMS

Now, i need to split this and put it across in a list view which has all the tools as columns. here's an example:

Name Appscan CC CCMS CQ CQMS ReqPro PolicyTester
Mr.Abc 1 1 1 1 1 0 0

Now, in .NET I need a way to search the ToolsSubscribedTo which will contain different combinations for different users and populate the listview to give me a matrix of users against tools.

Here is the code i have right now. Listview columns are added earlier based on list of all tools.

ToolsUsed = Licenses_UsedList.Replace(vbCrLf, " ")
ToolsUsed = ToolsUsed + " "
For j = 0 To UBound(ListofAllTools)

Dim strCurrentTool As String
strCurrentTool = ListofAllTools(j) + " "

If InStr(ToolsUsed, strCurrentTool, CompareMethod.Text) > 0 Then
lv.SubItems.Add("1")
Else
lv.SubItems.Add("")
End If

Next

Need to be careful as if i search for CQ, it is available in two lines so i add a space after each tool and search including the space.

Now,
When strCurrentTool = "CQ" and Tools Used = "CC CCMS CQ CQMS "
InStr(ToolsUsed, strCurrentTool, CompareMethod.Text) returns 8.

If i make strCurrentTool = "CQ " it returns 0 why is that? is there a better way to achieve this?
I am so worried about this space because for some records, CQMS might be before CQ and i dont want to mistake CQ with CQMS thru InStr.

Now im really confused.......... Somebody please help.
 
Last edited:
hi,

welcome to the forum, and please, if you post code use the CODE tag, it's damn confusing to read it.
Anyway, it's kinda funny you're having this problem in vb.net2010 cause I've just migrate to it but had to implement ish the same in vb6.
Anyway, I think you're just making everything more complex than it should be.
Check the function I've done, that's in vb6 and everytime you call it gives you the next value, and "consumes" the value out of Msg:
VB.NET:
Private Function NextVal(ByRef Msg As String, ByVal Separator As String) As String

    Dim Position As Long
    Dim TempVal As String
    
    Position = InStr(1, Msg, Separator, vbTextCompare)

    TempVal = Left(Msg, Position)
    Msg = Trim(Right(Msg, Len(Msg) - Len(TempVal)))
    NextVal = Trim(TempVal)
    
End Function

so this in vb.net should be:
VB.NET:
    Private Function NextVal(ByRef Msg As String, ByVal Separator As String) As String

        Dim Position As Long
        Dim TempVal As String

        Position = InStr(1, Msg, Separator, vbTextCompare)

        TempVal = Msg.Substring(0, Position) ' Maybe Position-1
        Msg = Msg.Substring(Msg.Length - TempVal.Length).Trim ' Maybe plus one or minus one
        NextVal = Trim(TempVal)

    End Function

and whenever it returns "" it means it's over
so:
VB.NET:
While(Yourstring.Lengh > 0)

lv.subitems.add(NextVal(YourString, vbCrLf))

End While

well, at least it's how I would do it, I'm sure others will have different opinions.
 
Thank you. I will give it a try. And thank you for letting me know about the code tag. This is my first post in any of the developer forums and will keep this in mind.
 
Back
Top