Solved

urgent String logic

Posted on 2004-08-26
11
156 Views
Last Modified: 2010-05-02
Hi
In Sapi 5.1 I m dealing with two events

Private Sub RecoContext_Hypothesis(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal Result As SpeechLib.ISpeechRecoResult)

and return a string
list1.additem  = Result.PhraseInfo.GetText

it runs many time and as in end I want to know how many items are in list group by same items
for example

this is
this is simple
this is
this is soft
this is simple
this is simple

and results must be like this

this is 2 times
this is simple 3 times
this is soft 1 time
and over all same word like
this 6 times
is 6 times
this is 6 times

plz take some time to solve this.
I tried many ways but can not
thanks

 
0
Comment
Question by:SCS_SU
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
11 Comments
 
LVL 9

Expert Comment

by:dancebert
ID: 11908454
create a collection.  For each phrase (e.g. "this is"), check to see if there is a member already in the collection with the phrase as the key.  If it's already there, increment the member by one.  If it's not there, add a new member and set it's value to one.

To determine the count for the individual words, do the same thing as above for each word instead of each phrase.
0
 

Expert Comment

by:kirshan
ID: 11908512
can  u plz write codes
I got u but today due to lot of work I can not code these.
I tried but can not and I need solution as soon as posible to move other sides.

plz
thanks
0
 
LVL 11

Accepted Solution

by:
coopzz earned 30 total points
ID: 11909704
Option Explicit

'you'll need a reference to Microsoft Scripting Runtime
Private m_oColl As Scripting.Dictionary

Private Sub Command1_Click()
    Randomize
    Dim sNew As String
    Select Case (Int((5 - 1 + 1) * Rnd + 1))
        Case 1: sNew = "this is"
        Case 2: sNew = "this was"
        Case 3: sNew = "this can be"
        Case 4: sNew = "this saw"
        Case 5: sNew = "this believed"
    End Select
   
    Dim n As Integer
    If (m_oColl.Exists(sNew)) Then
        m_oColl.Item(sNew) = m_oColl.Item(sNew) + 1
    Else
        m_oColl.Add sNew, 1
    End If
   
    displayResult
End Sub

Private Sub displayResult()
    Dim i As Variant
    List1.Clear
    For Each i In m_oColl
        List1.AddItem i & ": " & m_oColl.Item(i) & " times"
    Next i
End Sub

Private Sub Form_Load()
    Set m_oColl = New Scripting.Dictionary
End Sub

Hope it helps..
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Expert Comment

by:kirshan
ID: 11911134
thanks I will chk it and let u know results.
thanks


0
 
LVL 7

Expert Comment

by:OHDev2004
ID: 11918597
why not using the Precios "Instr" function :P

here's How:
'=========================================
Private Function CountItems (StringtoFind as String , ListtoSearch as Listbox) as Long
Dim Xloop as Long
For Xloop = 0 to ListtoSearch.Listcount - 1
If Instr (1, ListtoSearch.List(Xloop), StringtoFind) <> 0 Then CountItems = CountItems + 1
Next Xloop
End Function
'=========================================

and now to test the Function :
let's say you want to count the "this is" from a Combobox called "List1"
msgbox CountItems("this is", List1)

Cheers
OHDev
0
 
LVL 7

Expert Comment

by:OHDev2004
ID: 11918600
"let's say you want to count the "this is" from a COMBOBOX called "List1" "
sorry i meant Listbox not Combobox :P ...
OHDev
0
 
LVL 11

Expert Comment

by:coopzz
ID: 12295629
?¿ so did this help ¿? or Not.
0
 
LVL 11

Expert Comment

by:coopzz
ID: 12519444
I think my comment deserved some of the points.. it did give a solution after some code was asked for.

but if you read the whole it's a bit strange how it started with scs_su then was getting author type comments from krishan  hmmm...
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question