Strings

Adding Numbers in Strings

Page 1 of 1

2 Replies - 714 Views - Last Post: 02 May 2010 - 12:13 PM Rate Topic: -----

#1 velaphi  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 55
  • Joined: 20-July 08

Strings

Posted 02 May 2010 - 06:06 AM

I need to add numbers in strings
My program concatenate the numbers instead
Please help

Dim first As String
        Dim complete1 As String
        Dim complete As String
        Dim complete2 As Integer

        first = Trim(TextBox1.Text) '
        complete1 = first.Substring(0, 3)
        complete = first.Substring(7, 3)
        'I need to add the two result from the strings
        complete2 = CInt(complete1 + complete) 'This line is producing wrong result
        'It concatenate the result instead of Adding the results
        MsgBox(complete2)




Is This A Good Question/Topic? 0
  • +

Replies To: Strings

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 469
  • View blog
  • Posts: 4,280
  • Joined: 25-March 09

Re: Strings

Posted 02 May 2010 - 06:13 AM

try:
Dim first As String
        Dim complete1 As String
        Dim complete As String
        Dim complete2 As Integer

        first = Trim(TextBox1.Text) '
        complete1 = first.Substring(0, 3)
        complete = first.Substring(7, 3)
        'I need to add the two result from the strings
        complete2 = CInt(complete1) + CInt(complete)
        'It concatenate the result instead of Adding the results
        MsgBox(complete2)



the way you do it you add string 1 with string 2 (string1=10 + string2=20 => string3=1020) and then make it integer. now the way i do it you cast them to integer then sum them and pass them to the variable. it is little native using cint()

This post has been edited by NoBrain: 02 May 2010 - 06:15 AM

Was This Post Helpful? 0
  • +
  • -

#3 velaphi  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 55
  • Joined: 20-July 08

Re: Strings

Posted 02 May 2010 - 12:13 PM

Thank you it works!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1