Microsoft KB Archive/271302

= BUG: VBCE: Unable to Send an Array Using the MSCEComm Control =

Article ID: 271302

Article Last Modified on 8/19/2005

-

APPLIES TO


 * Microsoft eMbedded Visual Basic 3.0
 * Microsoft Windows CE Toolkit for Visual Basic 6.0

-



This article was previously published under Q271302



SYMPTOMS
In a Windows CE Toolkit for Visual Basic (VBCE) 6.0 or an eMbedded Visual Basic (eVB) 3.0 project that uses the MSCEComm control, when you attempt to send an array from the device, the data is not transmitted and there are no errors.



RESOLUTION
To work around this problem, add the following code to Form1 in the Visual Basic for CE sample that is shown in the &quot;Steps to Reproduce Behavior&quot; section: Declare Function WriteFileL Lib &quot;Coredll&quot; Alias &quot;WriteFile&quot; _ (ByVal hFile As Long, lpBuffer As Byte, ByVal nNumberOfBytesToWrite As Long, _   lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long

Public Sub SendArrayData(ByVal hCommID As Long, baData) Dim i, lRet, iWrite For i = LBound(baData) To UBound(baData) lRet = WriteFileL(hCommID, baData(i), 1, iWrite, 0) Next End Sub Next replace the Command2_Click event code, in the same project, with the following: Private Sub Command2_Click Dim bTemp(29) As Byte, y As Integer

For y = 0 To 29 bTemp(y) = y   Next y

SendArrayData Comm1.CommID, bTemp End Sub When you run both of these projects and select Receive Array, you should see that when you click Send Array, the textbox displays the numbers 0 through 29.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
You will need to create two projects, one using Windows CE Toolkit for Visual Basic 6.0 or eMbedded Visual Basic 3.0, and the other using Microsoft Visual Basic 6.0.

Visual Basic for CE Project
 Start VBCE 6.0 or eVB 3.0. Create a new Windows CE HPC PRO project. Form1 is created by default. On the Project menu, click Components, and then click to add the Microsoft CE Comm Control 3.0. Add a text box, two command buttons, two option buttons, and a Comm control to Form1.  Paste the following code to Form1: Option Explicit Dim CRflag As Boolean, UseString As String, bText As Boolean Private Sub Comm1_OnComm Select Case Comm1.CommEvent Case comEvReceive If bText Then ReceiveText (Comm1.Input) Else ReceiveArray (Comm1.Input) End If   End Select End Sub

Private Sub Command1_Click Comm1.Output = &quot;Text works correctly&quot; End Sub

Private Sub Command2_Click Dim bTemp(29) As Byte, y As Integer For y = 0 To 29 bTemp(y) = y   Next y    Comm1.Output = bTemp End Sub

Private Sub Form_Load Option1.Caption = &quot;Receive Text&quot; Option2.Caption = &quot;Receive Array&quot; Option1.Value = True Command1.Caption = &quot;Send Text&quot; Command2.Caption = &quot;Send Array&quot;

Comm1.CommPort = 1 Comm1.RThreshold = 1 Comm1.Handshaking = comRTS Comm1.PortOpen = True End Sub

Private Sub Form_Unload(Cancel As Integer) If Comm1.PortOpen Then Comm1.PortOpen = False End Sub

Private Sub Option1_Click bText = True Text1.Text = &quot;&quot; Comm1.InputMode = comInputModeText End Sub

Private Sub Option2_Click bText = False Text1.Text = &quot;&quot; Comm1.InputMode = comInputModeBinary End Sub

Private Sub ReceiveText(ByVal InString As String) Dim y As String Dim x As Integer

For x = 1 To (Len(InString) + 1) y = Mid(InString, x, 1) If y = Chr(13) Then CRflag = True y = &quot;&quot; UseString = Trim(UseString) UseString = &quot;&quot; End If     If y = Chr(10) Then y = &quot;&quot; CRflag = False End If     If CRflag = False Then UseString = UseString & y        Text1.SelStart = Len(Text1.Text) Text1.SelText = y     End If   Next x End Sub

Private Sub ReceiveArray(ByVal inArray As Variant) Dim lCount As Long For lCount = 0 To UBound(inArray) Text1.Text = Text1.Text & CStr(inArray(lCount)) & &quot; &quot; Next End Sub  Compile and then save the project.</li> Create a setup package using the Application Install Wizard, and deploy the package to the device.</li></ol>

Visual Basic 6.0 Project
<ol> Start Visual Basic 6.0.</li> Create a new Standard EXE project. Form1 is created by default.</li> On the Project menu, click Components, and then click to add the Microsoft Comm Control 6.0.</li> Add a text box, two command buttons, two option buttons, and a Comm control to Form1.</li>  Paste the following code to Form1: Option Explicit Dim bText As Boolean

Private Sub Command1_Click MSComm1.Output = &quot;Text works correctly&quot; End Sub

Private Sub Command2_Click Dim bTemp(29) As Byte, y As Integer For y = 0 To 29 bTemp(y) = y   Next y    MSComm1.Output = bTemp End Sub

Private Sub Form_Load Command1.Caption = &quot;Send Text&quot; Command2.Caption = &quot;Send Array&quot; MSComm1.CommPort = 1 MSComm1.RThreshold = 1 MSComm1.Handshaking = comRTS MSComm1.PortOpen = True Option1.Caption = &quot;Receive Text&quot; Option2.Caption = &quot;Receive Array&quot; Option1.Value = True End Sub

Private Sub Form_Unload(Cancel As Integer) If MSComm1.PortOpen Then MSComm1.PortOpen = False End Sub

Private Sub MSComm1_OnComm Select Case MSComm1.CommEvent Case comEvReceive If bText Then ReceiveText (MSComm1.Input) Else ReceiveArray (MSComm1.Input) End If   End Select End Sub

Private Sub Option1_Click bText = True Text1.Text = &quot;&quot; MSComm1.InputMode = comInputModeText End Sub

Private Sub Option2_Click bText = False Text1.Text = &quot;&quot; MSComm1.InputMode = comInputModeBinary End Sub

Private Sub ReceiveText(ByVal InString As String) Dim y As String Dim x As Integer ' These are declared Static so that they will persist between ' function calls: Static CRflag As Boolean Static UseString As String

For x = 1 To (Len(InString) + 1) y = Mid$(InString, x, 1) If y = Chr$(13) Then CRflag = True y = &quot;&quot; UseString = Trim(UseString) UseString = &quot;&quot; End If     If y = Chr$(10) Then y = &quot;&quot; CRflag = False End If     If CRflag = False Then UseString = UseString & y        Text1.SelStart = Len(Text1.Text) Text1.SelText = y     End If   Next x End Sub

Private Sub ReceiveArray(ByVal inArray As Variant) Dim lCount As Long For lCount = 0 To UBound(inArray) Text1.Text = Text1.Text & CStr(inArray(lCount)) & &quot; &quot; Next End Sub </li></ol>

After you have completed both projects and deployed the application to the device, perform the following steps:
 * 1) Go to the Connection Settings of ActiveSync and uncheck Allow serial cable or infrared connection to this COM port.
 * 2) Start the application on the device and run the Visual Basic project in the development environment.
 * 3) On the device, click Send Text. You should see &quot;Text works correctly&quot; displayed in the Visual Basic application. This works correctly in the other direction as well.
 * 4) Select Receive Array on both applications, and click Send Array on the device. You will see that nothing is displayed in the Visual Basic application. If you click Send Array on the Visual Basic application, you will see the numbers 0 through 29 displayed on the device.

Additional query words: wce evb vbce

Keywords: kbbug kbpending KB271302

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.