2011-10-20 3 views
-2

私はインターンシップのプログラムを書いていて、助言が必要です。私は研究をしましたが、ほとんど無駄に戻ってきました... "buttonOneClickを1秒間反復する必要があります。プログラムは" P "文字を送り、1秒待って、apを送り、1秒待つなどします。 。また、私はそれがExcelのスプレッドシートに受信した情報を記述する必要がある既存のコードの任意のヘルプ/批評をいただければ幸いですVBプログラム、反復処理のためのルーピングと書き出しを行う

ここで私が持っているものです:。。

Public Class Form2 

Dim buttonOnePush As Boolean = False 
Dim buttonTwoPush As Boolean = False 



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    ' Send strings to a serial port. 

    Using com5 As IO.Ports.SerialPort = 
      My.Computer.Ports.OpenSerialPort("COM5") 
     com5.WriteLine("P") 

    End Using 

End Sub 

Function ReceiveSerialData() As String 
    ' Receive strings from a serial port. 
    Dim returnStr As String = "" 

    Dim com5 As IO.Ports.SerialPort = Nothing 
    Try 
     com5 = My.Computer.Ports.OpenSerialPort("COM5") 
     com5.ReadTimeout = 10000 
     Do 
      Dim Incoming As String = com5.ReadLine() 
      If Incoming Is Nothing Then 
       Exit Do 
      Else 
       returnStr &= Incoming & vbCrLf 
      End If 
     Loop 
    Catch ex As TimeoutException 
     returnStr = "Error: Serial Port read timed out." 
    Finally 
     If com5 IsNot Nothing Then com5.Close() 
    End Try 

    Return returnStr 
End Function 


Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged 
    If IsNumeric(TextBox1.Text) AndAlso IsNumeric(TextBox2.Text) Then 
     TextBox1.Text = CDec(TextBox2.Text) 
    End If 
End Sub 

Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged 
    If IsNumeric(TextBox6.Text) AndAlso IsNumeric(TextBox3.Text) Then 
     TextBox6.Text = CDec(TextBox3.Text) 
    End If 
End Sub 

Private Sub TextBox7_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox7.TextChanged 
    If IsNumeric(TextBox7.Text) AndAlso IsNumeric(TextBox4.Text) Then 
     TextBox7.Text = CDec(TextBox4.Text) 
    End If 
End Sub 

Private Sub TextBox8_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox8.TextChanged 
    If IsNumeric(TextBox8.Text) AndAlso IsNumeric(TextBox5.Text) Then 
     TextBox8.Text = CDec(TextBox5.Text) 
    End If 
End Sub 

Private Sub TextBox15_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox15.TextChanged 
    If IsNumeric(TextBox15.Text) AndAlso IsNumeric(TextBox16.Text) Then 
     TextBox15.Text = Hex(TextBox16.Text) 
    End If 
End Sub 

Private Sub TextBox14_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox14.TextChanged 
    If IsNumeric(TextBox14.Text) AndAlso IsNumeric(TextBox11.Text) Then 
     TextBox14.Text = Hex(TextBox11.Text) 
    End If 
End Sub 

Private Sub TextBox13_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox13.TextChanged 
    If IsNumeric(TextBox13.Text) AndAlso IsNumeric(TextBox10.Text) Then 
     TextBox13.Text = Hex(TextBox10.Text) 
    End If 
End Sub 

Private Sub TextBox12_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox12.TextChanged 
    If IsNumeric(TextBox12.Text) AndAlso IsNumeric(TextBox9.Text) Then 
     TextBox12.Text = Hex(TextBox9.Text) 
    End If 
End Sub 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 
    buttonTwoPush = True 
    buttonOnePush = False 

    Me.Close() 
    Form1.Close() 

End Sub 

エンドクラス

答えて

0

使用Timerコマンドを1秒間隔で発行するツールボックスからタイマーをフォームにドラッグし、ダブルクリックすると01が表示されますメソッド。

フォームのコンストラクタで.Intervalタイマーのメンバーを設定し、.Startおよび.Stopメソッドを使用してコントロールします。

Excelの場合、Microsoft Excel 12.0(またはExcel 2010の場合は14.0)オブジェクトライブラリのプロジェクトへの参照を追加する必要があります。ソリューションエクスプローラでプロジェクトを右クリックして表示されるAdd Referenceダイアログの[COM]タブでこれを探します。包括的なリファレンスについては、this pageを参照してください(VB.NETの簡単な例については、ページの一番下までスクロールしてください)。

関連する問題