Microsoft KB Archive/271302

From BetaArchive Wiki

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 "Steps to Reproduce Behavior" section:

Declare Function WriteFileL Lib "Coredll" Alias "WriteFile" _
    (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.

MORE INFORMATION

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

  1. Start VBCE 6.0 or eVB 3.0.
  2. Create a new Windows CE HPC PRO project. Form1 is created by default.
  3. On the Project menu, click Components, and then click to add the Microsoft CE Comm Control 3.0.
  4. Add a text box, two command buttons, two option buttons, and a Comm control to Form1.
  5. 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 = "Text works correctly"
    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 = "Receive Text"
        Option2.Caption = "Receive Array"
        Option1.Value = True
        
        Command1.Caption = "Send Text"
        Command2.Caption = "Send Array"
    
        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 = ""
        Comm1.InputMode = comInputModeText
    End Sub
    
    Private Sub Option2_Click()
        bText = False
        Text1.Text = ""
        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 = ""
             UseString = Trim(UseString)
             UseString = ""
          End If
          If y = Chr(10) Then
             y = ""
             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)) & " "
        Next
    End Sub
                        
  6. Compile and then save the project.
  7. Create a setup package using the Application Install Wizard, and deploy the package to the device.

Visual Basic 6.0 Project

  1. Start Visual Basic 6.0.
  2. Create a new Standard EXE project. Form1 is created by default.
  3. On the Project menu, click Components, and then click to add the Microsoft Comm Control 6.0.
  4. Add a text box, two command buttons, two option buttons, and a Comm control to Form1.
  5. Paste the following code to Form1:

    Option Explicit
    Dim bText As Boolean
    
    Private Sub Command1_Click()
        MSComm1.Output = "Text works correctly"
    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 = "Send Text"
        Command2.Caption = "Send Array"
            
        MSComm1.CommPort = 1
        MSComm1.RThreshold = 1
        MSComm1.Handshaking = comRTS
        MSComm1.PortOpen = True
        
        Option1.Caption = "Receive Text"
        Option2.Caption = "Receive Array"
        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 = ""
        MSComm1.InputMode = comInputModeText
    End Sub
    
    Private Sub Option2_Click()
        bText = False
        Text1.Text = ""
        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 = ""
             UseString = Trim(UseString)
             UseString = ""
          End If
          If y = Chr$(10) Then
             y = ""
             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)) & " "
        Next
    End Sub
                        

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 "Text works correctly" 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