How do i add an array from a function into excel from vb.net?

  • Thread starter Thread starter HIRA12345
  • Start date Start date
H

HIRA12345

Guest
‘my function to make an array
Public Function TheArray() As Array
Dim count As Integer = ListBox1.Items.Count
Dim MyArray(count, 5) As Integer
For i As Integer = 0 To count - 1

MyArray(i, 0) = ListBox1.Items(i).ToString
MyArray(i, 1) = ListBox2.Items(i).ToString
MyArray(i, 2) = ListBox3.Items(i).ToString
MyArray(i, 3) = ListBox4.Items(i).ToString
MyArray(i, 4) = ListBox5.Items(i).ToString

Next
Return MyArray

End Function


‘my code I have used so far to create export array from function to excel
Public Class Form5
Dim oExcel As Object
Dim oBook As Object

Dim oSheet As Object
Dim filename As String

Public Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load


oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Add
oSheet = oBook.Worksheets(1)


oSheet.Range("A2").Value = ("Generation number")
oSheet.Range("B2").Value = ("Juvenile Population")
oSheet.Range("C2").Value = ("Adult Population")
oSheet.Range("D2").Value = ("Senile Population")
oSheet.Range("E2").Value = ("Total")



Dim count As Integer = Form4.ListBox1.Items.Count
Dim array1(count, 5) As Integer

array1 = Form4.TheArray()

For row = 0 To count - 1

For column = 0 To 4

oSheet.Range("A3:D3").value = array1(row, column)

Next
Next
‘I hope to display values that my array contains which is according to the values entered by the user so I don’t know the number of rows-yet there are 5 columns

Continue reading...
 
Back
Top