Compact 2013 Ebook

17.3 VB GetTime App
Created by djones on 6/26/2013 5:49:29 AM

Managed Code Visual Basic GetTime Application

In this activity the GetTime application as implemented in the native code and XAML chapters, is implemented as a Managed Code VB .NET CF application.

Create the Application

  1. In application development IDE, create a new project: File—>New Project 
    (Or File—>Add—>New Project if in the C# project from 17.2)

  2. Under Visual Basic, locate Windows Embedded Compact/SDK and select Device Application 
    aaa
    Figure 17.6
  3. Name the app ManagedTimeVB and Finish [OK]
  4. Create the UI for the application as shown: 
    image
    Figure 17.8
    • The controls are
      • A label (Local Time:)
      • A TextBox (textBox1)
      • Two Buttons, called TimeButton and ExitButton
    • Set the Text property of the form to ManagedTime
  5. At the bottom of the Visual Designer windows, locate the Menu control icon and delete it.
    As we have no menu, this just takes up space at the top of the form and may impinge upon what the TextBox displays.

  6. Create the event handlers for the buttons by in the Visual Designer double-clicking on the buttons
    Public Class frmManagedTime
    
        Private Sub TimeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimeButton.Click
    
        End Sub
    
        Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
    
        End Sub
    
    End Class
    

    Listing 17.5 The VB code behind with the button event handlers.

  7. Implement the TimeButton event handler by inserting the following code:
    TextBox1.Text = DateTime.Now.ToString()
    Listing 17.6 The VB TimeButton event handler code.


  8. Implement the ExitButton event handler by inserting the following code:
    Application.Exit()

    Listing 17.7 The VB ExitButton event handler code.

  9. Set the application in Debug mode (default) and build the application

Run the Application

Now to run the application on the target device using CoreCon.

Refer the 16.4 CoreCon Application Development Connectivity.

  1. Boot the target and get its IP Address:
    On the OS development system) Target—>Target Control—>IpConfig /d 
    The IP Address will appear on the OS Output Debug Window
  2. Start CoreCon on the target
  3. (Back on the app development system) In the property pages of the app project,
    Enter the IP address of the target
  4. Check the connectivity by attempting to deploy the app:
    From the project context—>Deploy
    The app should successfully deploy
  5. Run the application (eg press F5 etc.)
  6. Test the app functionality, including exit.

    image

    Figure 17.9 The ManagedTimeVB app running

  7. Place a Breakpoint in the TimeButton event handler, run the app in Debug mode and determine that the debugging works.
  8. From the Project Context(Right-click on it in Solution Explorer)—>Run app
  9. From the Project Context(Right-click on it in Solution Explorer)—>Step into the application 

    The local time has been formatted as a string in its default format. To explicitly format as per the previous chapters use a format string. A format string is similar to printf format string. Instead of %d, %s etc. the parameters to be formatted in the string are listed in it in braces numbered from zero.
  10. Modify the the TimeButton event code by replacing it with the following code:
     
    
               Dim localTime as DateTime = DateTime.Now _
               Dim dateTimeStr as string = string.Format( _
                    "Time  {0}:{1}:{2} Date  {3}//{4}//{5}", _
                    localTime.Hour, localTime.Minute, localTime.Second, _
                    localTime.Day, localTime.Month, localTime.Year) 
               TextBox1.Text = dateTimeStr
    

    Listing 17.8 The revised VB TimeButton event handler code using a formatted string

    Note:  The line continuation character (underscore) in the String.Format statement. Unlike C#  statements, VB statements can't be blindly spread over multiple lines without these. They must be preceded by a whitespace character and must have nothing after them.
  11. Rebuild the application and test run it as above. 
    image
    Figure 17.10 The updated ManagedeTimeVB app running


More: 17.4 Calling Native Code from Managed Code

print

Click here to provide feedback and input

  Comments

There is no comment.

Turkish porno izle video site in rokettubeporno izle