Write VB script to test given number is Prime Number
Answer Posted / rvanamala
'--------- "n" is a given number
n = 101
retval= PrimeNo(n)
If strComp(retVal,"1",1) =0 Then
MsgBox n &" is a Prime Number"
Elseif strComp(retVal,"0",1) =0 Then
MsgBox n &" is not a Prime Number"
Else
MsgBox n &" is -ve Number"
End If
'-------------------
Function PrimeNo(x)
k=0
z=0
If strComp(n,"0",1) = 0 Then
PrimeNo = 0
Exit Function
Elseif n < 0 Then
PrimeNo = -1
Exit Function
End If
For i = 1 to x
IsPrime = 0
If strComp(x,"1",1)= 0 Then
PrimeNo = 0
Exit Function
End If
z = x mod i
If eval("z = 0") and strComp(i,x,1) <>0 and
strComp(i,"1",1) <> 0 Then
PrimeNo = 0
Exit Function
Else
IsPrime= 1
End If
Next
PrimeNo = IsPrime
End Function
'-----------------------------------
Is This Answer Correct ? | 0 Yes | 10 No |
Post New Answer View All Answers
How you can make an action as re-usable action?
Hi we are using QTP9.0 for Seibel Application and this seibel application will give you a popup messagebox which is of web , so qtp takes 3 mins to recognize the messagebox and to click on it , we have more number of messageboxes like this . please suggest me some solution
supose i hv to acsess some functionlaties of a test in 1 machin , some part other machin how can acsess?
How to check which add-ins are associated with a test in qtp?
What is data driver in qtp?
How to start recording using quicktest professional (qtp)?
Where is the Bitmap checkpoint information stored?
Explain types of descriptive programming?
Can the user toggle between using Local OR and shared OR for the same action?
How qtp recognizes the object?
How you can delete excel file in qtp?
i am new QTP... please tell me automation frameworks , types & for whiich type of applications frameworks are used & how to generate script in keyword driven framework
Print the Prime numbers in below format only up to 20(Need commas also) 1,2,3,5,7,9,11,13,17,19
What is object spy in quicktest professional?
Tell me about qtp?