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

Beja

Expert
Licensed User
Longtime 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:

Troberg

Well-Known Member
Licensed User
Longtime 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.
 

rboeck

Well-Known Member
Licensed User
Longtime 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.
 

Beja

Expert
Licensed User
Longtime 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
 

Troberg

Well-Known Member
Licensed User
Longtime 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.
 

Beja

Expert
Licensed User
Longtime 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.
 

Beja

Expert
Licensed User
Longtime User
Not sure, will check this.. thanks for the hint
 

Troberg

Well-Known Member
Licensed User
Longtime User
Here's a debug sub I use to find out if there are strange characters in a string:

B4X:
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:

Beja

Expert
Licensed User
Longtime User
Text1.Text = "Some text"
MsgBox Text1.Text

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.
 
Top