what's wrong with this vb6 code? msgbox + mscomm1 +TTS

Discussion in 'Chit Chat' started by Beja, Feb 11, 2015.

  1. Beja

    Beja Expert Licensed User

    Hi guys,

    In voice recognition I say "this is a test"
    I can see "this is a test" displayed on text1.text, but
    When I try to msgbox text1.text, I get the first letter only "t", instead of the whole "this is a test" recognized sentence.
    pls help!

    Sorry, code is too buggy, so I deleted it.
     
    Last edited: Feb 12, 2015
  2. Troberg

    Troberg Well-Known Member Licensed User

    I'm not sure if that'äs the problem, but I see a few things that strike me as odd/risky:

    * The empty loop at the end of OnComm. An empty loop is not the best way to wait, and do you really need to wait there? I suspect that you can miss data that way.

    * In HandleInput, I wouldn't mess with SelStart and SelText, if nothing else because a mistimed click from the user might throw it off. I would go with Text1.Text=Text1.Text & InBuff instead.

    * I avoid using default properties (Text2=Text1), as I've seen on a few occasions that they can cause odd behaviours. I would have written it as Text2.Text=Text1.Text.
     
  3. rboeck

    rboeck Well-Known Member Licensed User

    Hi,

    i had used this code in OnComm Event:

    If Comm1.InBufferCount < 47 Then
    DoEvents
    Exit Sub
    End If

    This example was made for an fixed length string of an device; but you should think about signaling, what the end of the string is.

    Like Troberg wrote, is a bad practice to make an emty loop for waiting; you can leave the onCommEvent like shown and you come back, when new data is coming. Avoid only to use CommX.input, or you have to add the strings parts together. Another possibility would be to work with timers.
     
  4. Beja

    Beja Expert Licensed User

    thanks Troberg
    Now changed the code to reflect what you suggested .. but still .. msgbox is not showing the complete text, but only the first character.
    Any idea?
    msgbox text1.text
     
  5. Troberg

    Troberg Well-Known Member Licensed User

    Could it be that you have some hidden character in the string which mess up, such as chr$(0)? As I see it, if the text box displays it, the data is there, and should be displayed. So, chances are that all is not as it seems with the data.

    What happens if you, just to test, just set the textbox in code, like this:

    Text1.Text = "Some text"
    MsgBox Text1.Text

    Just to make some simple sanity test.
     
  6. Beja

    Beja Expert Licensed User

    Nop!
    Good troubleshooting but...
    the msgbox now is correctly displaying the text1 content.. but the text box that should hold the complete reco text is only displaying the first letter.
     
  7. Troberg

    Troberg Well-Known Member Licensed User

    Is it a single line textbox and there is some sneaky crlf in the text?
     
  8. Beja

    Beja Expert Licensed User

    Not sure, will check this.. thanks for the hint
     
  9. Troberg

    Troberg Well-Known Member Licensed User

    Here's a debug sub I use to find out if there are strange characters in a string:

    Code:
    Public Sub ExamineString(Text As String)
    Dim t As String
    Dim n As Integer
    Dim char As String
     
    t = Text
    If t <> vbNullString Then
      
    For n = 1 To Len(t)
        char = Mid$(t, n, 
    1)
        Debug.Print CStr(n) & 
    ": " & vbTab & CStr(Asc(char)) & "  " & vbTab & char
      
    Next
    End If
     
    End Sub
    It has been of much use to me, hope it'll help you.
     
    Last edited: Feb 12, 2015
    Beja likes this.
  10. KMatle

    KMatle Expert Licensed User

    Code:
    For i = 1 To 2000Next
    :eek::eek::eek::eek:
     
    Beja and lemonisdead like this.
  11. Beja

    Beja Expert Licensed User

    Hi Troberg,
    Nothing wrong will happen.. whatever value in text1 will be displayed.
    The problem here is that, msgbox is not waiting until all text is put in text1 by mscomm control.
     
    lemonisdead likes this.
  12. Troberg

    Troberg Well-Known Member Licensed User

    Ah, it was that simple.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice