1

I have a scenario where I'm trying to build a loop with the pattern below. So it goes through the loop and prints out the pattern at the end. My issue is the array is throwing an exception when holding the pattern

pattern
*
**
***
****
***
**
*"

I'm having issues because the array is unable to hold the pattern. How else would I be able to construct this loop

Sub Main()      
  pattern = Array("'","'*","'**","'***","'**","'*"")
  Dim patternstyle

  'iterating using For each loop. 
  For each item in pattern
    patternstyle = patternstyle&item&vbnewline
  Next

  msgbox patternstyle
End Sub
user692942
  • 16,398
  • 7
  • 76
  • 175
NewCoder
  • 35
  • 6

1 Answers1

0

The error you are receiving will be:

Microsoft VBScript compilation error: Unterminated string constant

This is because this line;

pattern = Array("'","'*","'**","'***","'**","'*"")

has an unterminated string in the last array element.

To fix the problem either remove the trailing double-quote like this;

pattern = Array("'","'*","'**","'***","'**","'*")

or escape it by doubling it so the string is still correctly terminated, like this;

pattern = Array("'","'*","'**","'***","'**","'*""")

Output (after removing trailing double-quote):

'
'*
'**
'***
'**
'*
user692942
  • 16,398
  • 7
  • 76
  • 175