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


Please Help Members By Posting Answers For Below Questions

How you can make an action as re-usable action?

649


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

1664


supose i hv to acsess some functionlaties of a test in 1 machin , some part other machin how can acsess?

1358


How to check which add-ins are associated with a test in qtp?

580


What is data driver in qtp?

572






How to start recording using quicktest professional (qtp)?

595


Where is the Bitmap checkpoint information stored?

1759


Explain types of descriptive programming?

589


Can the user toggle between using Local OR and shared OR for the same action?

554


How qtp recognizes the object?

667


How you can delete excel file in qtp?

595


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

1606


Print the Prime numbers in below format only up to 20(Need commas also) 1,2,3,5,7,9,11,13,17,19

1182


What is object spy in quicktest professional?

617


Tell me about qtp?

538