For each loop issue with pattern

你说的曾经没有我的故事 提交于 2020-05-28 06:35:31

问题


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

回答1:


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):

'
'*
'**
'***
'**
'*


来源:https://stackoverflow.com/questions/61386871/for-each-loop-issue-with-pattern

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!