Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print as per the value entered for the variable.
#1
Solved: 11 Years, 3 Months, 3 Weeks ago
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. *****
Reply
#2
Solved: 11 Years, 3 Months, 3 Weeks ago
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

Reply
#3
Solved: 11 Years, 3 Months, 3 Weeks ago
String(n,"*")
Reply
#4
Solved: 11 Years, 3 Months, 3 Weeks ago
(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".
Reply
#5
Solved: 11 Years, 3 Months, 3 Weeks ago
Code:
Dim var
var="10"  'Assigning Value To The Variable
print(val) 'It will print 10
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)