Solved

urgent String logic

Posted on 2004-08-26
11
153 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
  • 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

791 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