Results 1 to 3 of 3

Thread: AxMSComm1 in VB.net does not work

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2001
    Location
    Atlanta, GA
    Posts
    13

    Question AxMSComm1 in VB.net does not work

    I need help. My AxMSComm1 program does not work at all. (I use the AxMSComm1 from the VB6, I mean I installed the full VB.net and custom installed VB6, just have the AxMSComm1 component)

    My simple program is to get 2 bytes from the com port and display them into the textbox1

    but when i run the program, it does not get anything at all.

    Here is my code
    VB Code:
    1. Public Class Form1
    2.     Inherits System.Windows.Forms.Form
    3.  
    4. #Region " Windows Form Designer generated code "
    5.  
    6.     Public Sub New()
    7.         MyBase.New()
    8.  
    9.         'This call is required by the Windows Form Designer.
    10.         InitializeComponent()
    11.  
    12.         'Add any initialization after the InitializeComponent() call
    13.  
    14.     End Sub
    15.  
    16.     'Form overrides dispose to clean up the component list.
    17.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    18.         If disposing Then
    19.             If Not (components Is Nothing) Then
    20.                 components.Dispose()
    21.             End If
    22.         End If
    23.         MyBase.Dispose(disposing)
    24.     End Sub
    25.  
    26.     'Required by the Windows Form Designer
    27.     Private components As System.ComponentModel.IContainer
    28.  
    29.     'NOTE: The following procedure is required by the Windows Form Designer
    30.     'It can be modified using the Windows Form Designer.  
    31.     'Do not modify it using the code editor.
    32.     Friend WithEvents Button1 As System.Windows.Forms.Button
    33.     Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    34.     Friend WithEvents AxMSComm1 As AxMSCommLib.AxMSComm
    35.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    36.         Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
    37.         Me.Button1 = New System.Windows.Forms.Button
    38.         Me.TextBox1 = New System.Windows.Forms.TextBox
    39.         Me.AxMSComm1 = New AxMSCommLib.AxMSComm
    40.         CType(Me.AxMSComm1, System.ComponentModel.ISupportInitialize).BeginInit()
    41.         Me.SuspendLayout()
    42.         '
    43.         'Button1
    44.         '
    45.         Me.Button1.Location = New System.Drawing.Point(80, 104)
    46.         Me.Button1.Name = "Button1"
    47.         Me.Button1.Size = New System.Drawing.Size(120, 40)
    48.         Me.Button1.TabIndex = 0
    49.         Me.Button1.Text = "Button1"
    50.         '
    51.         'TextBox1
    52.         '
    53.         Me.TextBox1.Location = New System.Drawing.Point(88, 40)
    54.         Me.TextBox1.Name = "TextBox1"
    55.         Me.TextBox1.Size = New System.Drawing.Size(120, 20)
    56.         Me.TextBox1.TabIndex = 2
    57.         Me.TextBox1.Text = "TextBox1"
    58.         '
    59.         'AxMSComm1
    60.         '
    61.         Me.AxMSComm1.Enabled = True
    62.         Me.AxMSComm1.Location = New System.Drawing.Point(16, 184)
    63.         Me.AxMSComm1.Name = "AxMSComm1"
    64.         Me.AxMSComm1.OcxState = CType(resources.GetObject("AxMSComm1.OcxState"), System.Windows.Forms.AxHost.State)
    65.         Me.AxMSComm1.Size = New System.Drawing.Size(38, 38)
    66.         Me.AxMSComm1.TabIndex = 3
    67.         '
    68.         'Form1
    69.         '
    70.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    71.         Me.ClientSize = New System.Drawing.Size(292, 266)
    72.         Me.Controls.Add(Me.AxMSComm1)
    73.         Me.Controls.Add(Me.TextBox1)
    74.         Me.Controls.Add(Me.Button1)
    75.         Me.Name = "Form1"
    76.         Me.Text = "Form1"
    77.         CType(Me.AxMSComm1, System.ComponentModel.ISupportInitialize).EndInit()
    78.         Me.ResumeLayout(False)
    79.  
    80.     End Sub
    81.  
    82. #End Region
    83.  
    84.  
    85.         [COLOR=Red]Private Sub Command1_Click()
    86.  
    87.         AxMSComm1.Settings = "9600,n,8,1"
    88.         AxMSComm1.CommPort = 1
    89.         AxMSComm1.PortOpen = True
    90.  
    91.     End Sub
    92.  
    93.  
    94.  
    95.     Private Sub AxMSComm1_OnComm(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxMSComm1.OnComm
    96.         Dim sdata As String
    97.         If AxMSComm1.PortOpen = True Then
    98.             sdata = AxMSComm1.Input
    99.             TextBox1.Text = sdata
    100.         End If
    101.  
    102.     End Sub[/COLOR]
    103.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    104.  
    105.     End Sub
    106. End Class

    Please help.
    cxiong

  2. #2

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: AxMSComm1 in VB.net does not work

    this code
    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3.         AxMSComm1.Settings = "9600,n,8,1"
    4.         AxMSComm1.CommPort = 1
    5.         AxMSComm1.PortOpen = True
    6.  
    7.     End Sub
    is never being run... I know it would have run when you clicked the button in VB6, but that is not how things work in .NET...

    subroutines that are tied to an event (like a button click) need a handles clause on them (like you see on the AxMSComm1_OnComm routine)

    in your forms design mode, double click the button you added to the form..
    that should bring you into the code, with the button click and handles stuff already done for you.. and simply paste your code in to there
    VB Code:
    1. AxMSComm1.Settings = "9600,n,8,1"
    2.         AxMSComm1.CommPort = 1
    3.         AxMSComm1.PortOpen = True
    and then when you run the app and click the button, it will run the above code..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width