Micro Focus QTP (UFT) Forums
Print as per the value entered for the variable. - 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: Print as per the value entered for the variable. (/Thread-Print-as-per-the-value-entered-for-the-variable)



Print as per the value entered for the variable. - vibhakhandelwal - 10-18-2011

hi,

I was asked this question: Write a Logic/program/function in QTP
Given a variable, print/display * (stars) as per the value of the variable entered.
say if the variables value is 5 then stars should be printed 5 times. *****


RE: Print as per the value entered for the variable. - sreekanth chilam - 10-18-2011

Hi,

Here we go...
Code:
temp=""
N=5
For i=1 to N
     temp=temp&"*"
Next
msgbox temp

In the same way you can play with below examples as well.
Execute the below code and see Smile


Code:
For j=1 to 10
      temp=""
     For i=1 to j
         temp=temp&"*"
    Next
      print temp
Next

Code:
For j=10 to 1 step-1
      temp=""
     For i=j to 1 step-1
         temp=temp&"*"
    Next
      print temp
Next




RE: Print as per the value entered for the variable. - inborntester - 03-02-2012

String(n,"*")


RE: Print as per the value entered for the variable. - swathi - 03-05-2012

(03-02-2012, 04:35 PM)inborntester Wrote: String(n,"*")

The following example uses the String function to return repeating character strings of the length specified:

Code:
Dim MyString
MyString = String(5, "*")   ' Returns "*****".
MyString = String(5, 42)   ' Returns "*****".
MyString = String(10, "ABC")   ' Returns "AAAAAAAAAA".



RE: Print as per the value entered for the variable. - VenkateswaRao - 03-05-2012

Code:
Dim var
var="10"  'Assigning Value To The Variable
print(val) 'It will print 10