AnsweredAssumed Answered

error in vb program

Question asked by a3r on Jul 16, 2014
Latest reply on Jul 17, 2014 by ningchen
when i compile this code i got an error as   "Number of indices is the less than the dimension of the array"
code is
Imports Microsoft.Office.Interop
Imports Ivi.Visa.Interop



Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim readdata() As Double
        Dim poin As Integer
        Dim freqdata() As Double

        Dim xl As New Excel.Application
        Dim wkb As Excel.Workbook
        Dim wks As Excel.Worksheet
        Dim rng As Excel.Range
        Dim donotsavechanges As Boolean = False
        Dim cnt, row As Integer
        Dim c, f, mycelldata, total, avg, z, x As Double

        Dim iomgr As Ivi.Visa.Interop.ResourceManager
        Dim age506x = New FormattedIO488
        age506x.IO = iomgr.Open("TCPIP::169.254.213.57")
        age506x.IO.Timeout = 1000

        age506x.WriteString(":CALC1:PAR1:SEL",True)
        age506x.WriteString(":INT1:CONT OFF", True)
        age506x.WriteString(":ABOR",True)

        age506x.WriteString(":FORM:DATA ASC", True)

        age506x.WriteString(":SENS1:SWE:POIN?", True)
        poin = age506x.ReadNumber
        ReDim freqdata(poin - 1)
        age506x.WriteString(":SENS1:FREQ:DATA?", True)
        freqdata()  = age506x.ReadList(IEEEASCIIType.ASCIIType_R8, ",")
        

        ReDim readdata(poin * 2 - 1)
        age506x.WriteString(":CALC1:DATA:FDAT", True)
        readdata() = age506x.ReadList(IEEEASCIIType.ASCIIType_R8, ",")

        xl.Visible = True
        wkb = xl.Workbooks.Open("D:\g.xlsx")
        wks = wkb.Sheets.Item("sheet1")
        c = 0
        row = 0
        Dim i As Integer

        For i = 1 To poin
            wks.Cells(1, i) = freqdata(i - 1)
            'For cnt = 0 To 10
            'f = c * 2
            'wks.Cells(row, 2) = c
            'wks.Cells(row, 2) = f
            'row += 1
            'c = c + 4
        Next i
        i = 0
        For K = 1 To 10

            For i = 1 To poin
                wks.Cells(K + 1, i + 1) = readdata(i - 1)
            Next i
        Next K
        age506x.IO.Close()

    End Sub
End Class  

Outcomes