Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How Can we add two numbers in VB script without using Arithmatic operators
#1
Solved: 10 Years, 9 Months ago
Hi Friends,

Can anyone tell, How can we add two numbers in VB script without using arithmatic operators
a=10
b=5
Reply
#2
Solved: 10 Years, 9 Months ago
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 ...
Reply
#3
Solved: 10 Years, 9 Months ago
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)
Reply
#4
Solved: 10 Years, 9 Months ago
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.
Thanks,
SUpputuri
Reply
#5
Solved: 10 Years, 9 Months ago
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
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)