Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27513

VS 2010 SMS character counter

$
0
0
Hi!

One logical excercise...
I am developing a SMS sending program. I am struggling with character counting.
Regular SMS is 160 characters long (including whitespaces). So if the character count exeeds 160 chars then it automatically means that there are 2 SMS messages. If character count exeeds 320 chars then it would be 3 SMS messages and so on...all mobile phone users should be familiar with this.

This is the code I have so far in my textchanged event:
Code:

Dim str As String = TextBox1.Text
        Dim cnt As Integer
        Dim sms_cnt As Integer = 0 'variable that holds the number of sms messages
        cnt = str.Length.ToString ' character count of textbox1

      Label1.Text = cnt 'show how many characters are inserted to textbox1



'This should count how many sms messages are in textbox1
        If cnt = 160 Then
            sms_cnt = +1
            Label2.Text = sms_cnt.ToString & " SMS"
            cnt = 0
        End If

I can't figure out how to reset cnt so it starts counting from 0 when 160 characters are exceeded. I understand that I should use something else instead of calculating the length of textbox1...but what?

Thanks in advance!

Viewing all articles
Browse latest Browse all 27513

Trending Articles