Micro Focus QTP (UFT) Forums
How Can we add two numbers in VB script without using Arithmatic operators - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Interview Questions (https://www.learnqtp.com/forums/Forum-UFT-QTP-Interview-Questions)
+--- Thread: How Can we add two numbers in VB script without using Arithmatic operators (/Thread-How-Can-we-add-two-numbers-in-VB-script-without-using-Arithmatic-operators)



How Can we add two numbers in VB script without using Arithmatic operators - kotaramamohana - 05-08-2012

Hi Friends,

Can anyone tell, How can we add two numbers in VB script without using arithmatic operators
a=10
b=5



RE: How Can we add two numbers in VB script without using Arithmatic operators - arescool - 06-13-2013

Hi,
I wonder why no one has ever answered to this question :o

Let me try :
Code:
Dim intNumber1 : intNumber1 = 10
Dim intNumber2 : intNumber2 = 5
Dim strDump : strDump = Empty

For i = 1 To intNumber1
    strDump = strDump&"A"
Next

For i=1 To intNumber2
    strDump = strDump&"A"
Next

Msgbox Len ( strDump )

I know this is a very crude solution, so i will be looking to improve on it myself and if anyone of you can suggest a better solution , please do that ...


RE: How Can we add two numbers in VB script without using Arithmatic operators - pavansri - 06-15-2013

you are alsmost there arescool
but your code would return 31, Which is not the answer expected here.

how about this?
Code:
intNum1=10
intNum2=5

For i=1 to intNum1

    strDump=strDump & i & "X"

Next

For j=1 to intNum2

    strDump= strDump & j & "X"

Next

arrDump = split(strDump,"X",-1)

msgbox "Sum of " & intNum1 & " & " & intNum2 & " is " & UBound(arrDump)



RE: How Can we add two numbers in VB script without using Arithmatic operators - supputuri - 06-16-2013

try this below, simple way in QTP

Code:
DataTable.AddSheet("AddNumberwithoutArthOper").AddParameter "FirstNumber",iFirstNumber
DataTable.GetSheet("AddNumberwithoutArthOper").AddParameter "SecondNumber",iSecondNumber
DataTable.GetSheet("AddNumberwithoutArthOper").AddParameter "Sum", "=SUM(A1:B1)"
msgbox DataTable("Sum","AddNumberwithoutArthOper")

Let me know if you need further iNfo...

If you feel this answer solved your query, please mark the status as "solved"and click on "Give Reputation for this user" buuton in my post.


RE: How Can we add two numbers in VB script without using Arithmatic operators - kordirko - 06-23-2013

Using pure vbscript
Code:
a = 10
b = 5

d = now
d1 = DateAdd("s", a, d )
d1 = DateAdd("s", b, d1)

result = DateDiff("s", d, d1 )
MsgBox "Sum of "& a & " and " & b & " is " & result