Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 6-Dec-12 20:39pm
Edited 6-Dec-12 20:42pm
Mehdi Gholam237.1K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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..
 
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
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

use this-
 
    If tempp.Length > 12 Then tempp = tempp.Substring(0, 12)
 
please mark as answer if helped.
  Permalink  
Comments
Amit.p30 at 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 at 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

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,108
1 OriginalGriff 8,186
2 CPallini 2,613
3 Richard MacCutchan 2,231
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100