Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QTP Tips and Tricks
#30
(07-27-2011, 04:05 PM)rajpes Wrote: Just a puzzle here,You need print the pattern like below depending on no. of rows

rows=3,
**1**
*212*
32123

rows=4,
***1***
**212**
*32123*
4321234


Code:
r=inputbox ("enter no of rows")
c=(2*r)-1
m=(c-1)/2

ReDim a(r-1,c-1)
For i=0 to r-1
    For j=0 to c-1
        a(i,j)="*"
    Next
Next
'mid of all rows
For i=0 to r-1
  a(i,r-1)=1
Next


'rows manipulation
For i=1 to r-1
    For j=0 to m-1
                'If previous row has a value at next column position,increment it by 1
        If a(i-1,j+1)<>"*" Then
            val=a(i-1,j+1)+2 '2 instead of 1 because i am decrementing 'val' by 1 in next line
            For k=j to m-1
                 val=val-1
                 a(i,k)=val
                a(i,c-1-k)=val
            Next
        End If
    Next
Next

'print
For i=0 to r-1
    For j=0 to c-1
      txt= txt& a(i,j)
    Next
    txt=txt&vblf
Next
msgbox txt
If you have a better tested code, please post it



Hi Rajpes,

Here you go -
Code:
row = inputbox(" enter no. of rows")
    r = row
    c = row*2- 1

    ReDim a(r,c)

    For i = 0 to r-1
        For j = 0 to c-1
            a(i, j) = abs(r -j-1) + 1
            If a(i, j ) > i+1 Then
                a(i, j) = "*"
            End If
            txt= txt& a(i,j)
        Next
        txt=txt&vblf
Next
msgbox txt

If you have better code than this then please post Smile
Reply


Messages In This Thread
QTP Tips and Tricks - by rajpes - 07-25-2011, 11:49 AM
How to open and edit multiple scripts - by rajpes - 07-25-2011, 03:48 PM
RE: QTP Tips and Tricks - by Ankur - 07-25-2011, 04:02 PM
Simplest way to open a webpage - by rajpes - 07-26-2011, 03:24 PM
VBScript to print a pattern - by rajpes - 07-27-2011, 04:05 PM
RE: QTP Tips and Tricks - by nakulgupta18 - 03-07-2014, 04:05 AM
RE: VBScript to print a pattern - by ashitroy1991 - 08-24-2017, 12:46 PM
weblist index tip - by rajpes - 07-29-2011, 11:14 PM
RE: QTP Tips and Tricks - by gaveyom - 08-29-2011, 11:19 AM
@gaveyom - by rajpes - 09-21-2011, 05:11 PM
Initializing a counter in Do loop - by rajpes - 09-21-2011, 06:15 PM
worksheets or sheets - by rajpes - 09-22-2011, 12:13 PM
ComboBox items into array - by rajpes - 09-23-2011, 03:49 PM
DataTable.Import/ImportSheet - by rajpes - 09-25-2011, 12:29 PM
How to know the password - by rajpes - 10-11-2011, 11:06 AM
RE: QTP Tips and Tricks - by sshukla12 - 12-21-2011, 10:43 AM
RE: QTP Tips and Tricks - by Sathiya - 12-21-2011, 05:54 PM
RE: QTP Tips and Tricks - by rajpes - 01-30-2012, 07:51 PM
RE: QTP Tips and Tricks - by rajpes - 02-02-2012, 04:59 PM
RE: QTP Tips and Tricks - by sshukla12 - 03-02-2012, 02:37 PM
Using "Navigate and Learn" option - by rajpes - 02-06-2012, 07:45 PM
RE: Using "Navigate and Learn" option - by Dhiman - 02-15-2012, 10:02 PM
RE: Using "Navigate and Learn" option - by rajpes - 03-02-2012, 01:42 PM

Forum Jump:


Users browsing this thread: 3 Guest(s)