Go Down

Topic: problem with visualbasic 2010 coding (Read 3 times) previous topic - next topic

arduino_learners

hi everyone,
need ur help to solve the problem that i face.im working on developing the flood monitoring system, using serial data received, then manipulte the data by arduino atMega328 deumilanove. im trying to do the visual basic command but i got an error stated that there are command that is not initialized.my coding are as follows.

visual basic 2010 coding.

Imports System.Text
Imports System.IO.Ports
Imports System.Threading
Imports System.TimeZone
Imports System.Math

Public Class Form1
    Dim voltage As Integer
    Delegate Sub ProcessDataDelegate(ByVal Longitude As String, ByVal Latitude As String)
    Private Sub SerialPort1_DataReceived(ByVal sender As Object, _
                                         ByVal e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        Try
            Dim Longitude As Integer = SerialPort1.ReadLine()
            Dim Latitude As Integer = SerialPort1.ReadLine()
            Me.Invoke(New ProcessDataDelegate(AddressOf ProcessData), Longitude, Latitude)
        Catch ex As Exception
            MessageBox.Show(ex.ToString, " Unable to get the location")
            SerialPort1.Close()
        End Try
    End Sub
    Sub ProcessData(ByVal Longitude As String, ByVal Latitude As String)
        TextBox1.Text = Longitude
        TextBox2.Text = Latitude
    End Sub
    Private Sub Button1_Click(ByVal sender As Object, ByVal _e As EventArgs) Handles Button1.Click
        If Button1.Text = "Close" Then
            SerialPort1.Close()
            Button1.Text = "Open"
        Else
            If Not SerialPort1.IsOpen Then SerialPort1.Open()

            Button1.Text = " Close"

        End If
    End Sub
    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal _e As FormClosingEventArgs
                                  ) Handles Me.FormClosing
        SerialPort1.Close()

    End Sub
   
    Private Sub WebBrowser2_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser2.DocumentCompleted
        WebBrowser2.Navigate("maps.google.com/maps?q=")
    End Sub

    Private Sub CheckedListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If (voltage <= 0.5) Then
            MsgBox("Checked")
        Else
            MsgBox("Unchecked")

        End If
    End Sub


    Private Sub CheckedListBox1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckedListBox1.SelectedIndexChanged
        If CheckedListBox1.GetItemCheckState(voltage <= 0.5) Then
            CheckedListBox1.Text = True
            CheckedListBox1.CheckOnClick = True
        Else
            If Not CheckedListBox1.CheckOnClick Then
                CheckedListBox1.Text = False

            End If

        End If

    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
        If (voltage <= 0.5) Then
            CheckedListBox1.Text = True
            MsgBox(" safe")
            TextBox3.Show()
        End If
            If (voltage >= 0.5 And voltage <= 0.6) Then
                CheckedListBox2.Text = True
                MsgBox(" WARNING")
                TextBox3.Show()
            End If
        If (voltage <= 0.6 And voltage <= 0.7) Then
            CheckedListBox3.Text = True
            MsgBox("DANGER")
            TextBox3.Show()
        End If

    End Sub

    Private Sub SplitContainer2_Panel2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles SplitContainer2.Panel2.Paint

    End Sub

    Private Sub SplitContainer1_Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles SplitContainer1.Panel1.Paint
     
    End Sub

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub CheckedListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckedListBox2.SelectedIndexChanged
        If CheckedListBox2.GetItemCheckState(voltage >= 0.5 And voltage <= 0.6) Then
            CheckedListBox2.Text = True
            CheckedListBox2.CheckOnClick = True
        Else
            If Not CheckedListBox2.CheckOnClick Then
                CheckedListBox1.Text = False
            End If
        End If

    End Sub

    Private Sub CheckedListBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckedListBox3.SelectedIndexChanged
        If CheckedListBox3.GetItemCheckState(voltage >= 0.6 And voltage <= 0.7) Then
            CheckedListBox2.Text = True
            CheckedListBox2.CheckOnClick = True
        Else
            If Not CheckedListBox2.CheckOnClick Then
                CheckedListBox1.Text = False
            End If
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
        Timer1.Interval = 1
    End Sub

    Private Sub PictureBox1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click


    End Sub

    Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.TextChanged

        Label6.Text = DateString

    End Sub

    Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.TextChanged

        Label7.Text = TimeOfDay
    End Sub
End Class


hope anyone can help me solve this problem.thanks.

PaulS

Quote
but i got an error stated that there are command that is not initialized.

I doubt that the syntax of the message was as mangled as that. Post the EXACT error message.

Good thing you found this problem early before you wrote a ton of code.

arduino_learners

i cannot paste the print screen of the error..

after compiling the coding...another window appeared stated that " an invalid operation excerption was unhandled"
The error is: Failed to initialize because CategoryName is missing

tq.

PaulS

Where is SerialPort1 defined/initialized? How is it defined and initialized?

arduino_learners

should it be initialized?how? because previously i have complied the code, but no error happens. how ever , the error appeared as i put the timer function to the code.

Go Up