Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Private Sub SMSPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles comPort.DataReceived

        Dim str As String = ""
        Dim temp As String = ""

        objCon.GetConnectionString()
        If e.EventType = SerialData.Chars Then

            SMSPort.DtrEnable = True
            System.Threading.Thread.Sleep(100)
            tempp = SMSPort.ReadExisting().Replace("", "").Trim()

//' iwant to add here split function to split more than 12 charcters into only 12 character then give entry into database..

            'For i As Integer = 1 To tempp.Length Step 12
            '    Debug.Write(Mid(tempp, i, 12))

            If tempp <> "" Then
                objCon.GetConnectionString()
                objCon.GetConnection("Insert into tblAttended(Id,Status,Date,Time)values('" + tempp.ToString() + "','In','" + System.DateTime.Today.ToShortDateString() + "','" + DateTime.Now.ToShortTimeString() + "')")

                ListView1.Items.Add(tempp)
                txtUniqueNumber.Text = tempp.Trim()
                ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)
            End If
            'Next i

            

            Control.CheckForIllegalCrossThreadCalls = False

    End Sub
Posted
Updated 6-Dec-12 20:42pm
v2

use this-

VB
If tempp.Length > 12 Then tempp = tempp.Substring(0, 12)


please mark as answer if helped.
 
Share this answer
 
Comments
Amit.p30 7-Dec-12 2:59am    
thank You so much Ankit that error solved.. but i have one second error here: :

ListView1.Items.Add(tempp) // Error
txtUniqueNumber.Text = tempp.Trim()
ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent) // error


"ERROR : Cross-thread operation not valid: Control 'listView1' accessed from a thread other than the thread it was created on."
AnkitGoel.com 7-Dec-12 3:35am    
This is due to inter-thread communication problem-

Please refer this link-

http://www.codeproject.com/Questions/504980/ERRORplus-3aplusCross-threadplusoperationplusnotpl
Ankit thnks... one big question over here.. with this code

"If tempp.Length > 12 Then tempp = tempp.Substring(0, 12)"

suppose 36 characters string then i can divide into 12 characters once only.. but i want to store that whole string (36 characters) into 3 differnt substring nd wnt to store into database...

kindly guide as soon as posible ...

my code is like this..

VB
Dim str As String = ""
        Dim temp As String = ""

        objCon.GetConnectionString()
        If e.EventType = SerialData.Chars Then

            SMSPort.DtrEnable = True
            System.Threading.Thread.Sleep(100)
            tempp = SMSPort.ReadExisting().Replace(">", "").Trim()


            For i As Integer = 1 To tempp.Length Step 12
                Debug.Write(Mid(tempp, i, 12))

                If tempp <> "" Then
                    objCon.GetConnectionString()
                    objCon.GetConnection("Insert into tblAttended(Id,Status,Date,Time)values('" + tempp.ToString() + "','In','" + System.DateTime.Today.ToShortDateString() + "','" + DateTime.Now.ToShortTimeString() + "')")

                    'ListView1.Items.Add(tempp)
                    txtUniqueNumber.Text = tempp.Trim()
                    'ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)
                End If

            Next i
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900