title: How to return array from function using VBScript
body: <p>I have 10 records (rows) in my Excel sheet and I am taking it into array and I am not able to return it from function. I get only the last value. Below is my script.</p>
  
  <pre><code>Function fnFetchDataUsingArray()
      Dim arrExcelValues()
      sSheetName = Environment.Value("TestName")
  
      sExcelWorkbookPath = "I:\ProLinkIII_TestAutomation\trunk\ProLink_TestAutomation\Datasheet\DTSheet_5700C.xlsx"
  
      Set objExcel = CreateObject("Excel.Application")
      Set objWorkbook = objExcel.Workbooks.Open(sExcelWorkbookPath)
  
      objExcel.Visible = False
      Set currentWorkSheet = objExcel.ActiveWorkbook.Worksheets(sSheetName)
  
      i = 1
      x = 0
  
      Do Until objExcel.Cells(i, 2).Value = ""
          ReDim Preserve arrExcelValues(x)
  
          arrExcelValues(x) = objExcel.Cells(i, 2).Value
  
          i = i + 1
          x = x + 1
  
          fnFetchDataUsingArray = arrExcelValues(x-1)
      Loop
  
      objExcel.Quit
  End Function
  </code></pre>
  
  <p>Calling the function:</p>
  
  <pre><code>arr = fnFetchDataUsingArray()
  MsgBox arr
  </code></pre>
  
  <p>I am getting only the last value. Attached screenshot of my datasheet.</p>
  
  <p><a href="https://i.stack.imgur.com/gDtht.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gDtht.png" alt="Datasheet Screenshot"></a></p>