Help. Dot Net keep flagging an error remdim

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • WAYNEL

    #1

    Help. Dot Net keep flagging an error remdim

    Hi

    I am trying to re-write some of the example code that Agilent gives for
    VB to VB.Net.
    In .Net I keep getting the error 'cannot change the number of
    dimensions of an array'.

    I have paste the module I am having an issue with. Can anyone help!


    Thanks

    WayneL

    Module Module1

    ' Add the files visa32.bas and vpptype.bas, located in the
    ' directory vxipnp\Win95\in clude, to your Visual Basic
    ' project. Add the example code as a .bas module, and
    ' call main_34970A.
    'UPGRADE_WARNIN G: Application will terminate when Sub Main() finishes.
    Click for more:
    'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?ke yword="vbup1047 "'
    Public Sub Main()
    Dim numberChannels As Short
    Dim numberSweeps As Short
    Dim Sweep As Short
    Dim Readings() As Double
    Dim Units() As String
    Dim ChanNumb() As Short
    Dim Time() As Date
    Dim VISAaddress As String
    Dim status As Integer
    Dim viDefaultRM As Integer
    Dim Instrument As Integer
    Dim i As Short
    Dim Channel As String

    ' Declair all the HFPS currents

    Dim I_VADREF As Double
    Dim I_VCC As Double
    Dim I_VREF1 As Double
    Dim I_VREF2 As Double
    Dim I_VREF3 As Double
    Dim I_VREF4 As Double
    Dim I_VREF5 As Double
    Dim I_VKAM5V As Double
    Dim I_VKAML2 As Double
    Dim I_VCCL As Double
    Dim I_VCCL2 As Double
    Dim I_BUCKL As Double
    Dim I_BUCKH As Double
    Dim I_BAT As Double


    ' Declair all the HFPS voltages
    Dim V_VADREF As Double
    Dim V_VCC As Double
    Dim V_VREF1 As Double
    Dim V_VREF2 As Double
    Dim V_VREF3 As Double
    Dim V_VREF4 As Double
    Dim V_VREF5 As Double
    Dim V_VKAM5V As Double
    Dim V_VKAML2 As Double
    Dim V_VCCL As Double
    Dim V_VCCL2 As Double
    Dim V_BUCKL As Double
    Dim V_BUCKH As Double
    Dim V_BAT As Double


    HFPS.DefInstanc e.Show()

    VISAaddress = "9"
    status = viOpenDefaultRM (viDefaultRM)
    status = viOpen(viDefaul tRM, "GPIB::" & VISAaddress & "::INSTR", 0,
    2500, Instrument)
    If status < 0 Then
    MsgBox("Unable to open Port")
    End
    End If
    Configure_34970 A(Instrument)
    SetScan_34970A( Instrument, numberSweeps, numberChannels)

    ############### ############### ############### ############### ####
    Problem 'cannot change the number of dimensions of an array'
    Starts here!
    ############### ############### ############### ############### ####

    ' Size arrays depending on channel and sweep count
    ReDim Readings(number Sweeps, numberChannels)
    ReDim Units(numberSwe eps, numberChannels)
    ReDim ChanNumb(number Sweeps, numberChannels)
    ReDim Time(numberSwee ps, numberChannels)

    ############### ############### ############### ############### ####
    ' Get data one sweep at a time
    For Sweep = 1 To numberSweeps
    ReadData_34970A (Instrument, Sweep, numberChannels, Readings, Units,
    ChanNumb, Time)
    Next Sweep
    status = viClose(Instrum ent)
    status = viClose(viDefau ltRM)
    ' Get the current reading from the datalogger


    ' Reading (Sweep number, channel)
    I_VADREF = Readings(1, 1)
    I_VCC = Readings(1, 2)
    I_VREF1 = Readings(1, 3)
    I_VREF2 = Readings(1, 4)
    I_VREF3 = Readings(1, 5)
    I_VREF4 = Readings(1, 6)
    I_VREF5 = Readings(1, 7)
    I_VKAM5V = Readings(1, 8)
    I_VKAML2 = Readings(1, 9)
    I_VCCL = Readings(1, 10)
    I_VCCL2 = Readings(1, 11)
    I_BUCKL = Readings(1, 12)
    I_BUCKH = Readings(1, 13)
    I_BAT = Readings(1, 14)

    HFPS.DefInstanc e.T1CH1.Text = CStr(I_VADREF)
    HFPS.DefInstanc e.T1CH2.Text = CStr(I_VCC)
    HFPS.DefInstanc e.T1CH3.Text = CStr(I_VREF1)
    HFPS.DefInstanc e.T1CH4.Text = CStr(I_VREF2)
    HFPS.DefInstanc e.T1CH5.Text = CStr(I_VREF3)
    HFPS.DefInstanc e.T1CH6.Text = CStr(I_VREF4)
    HFPS.DefInstanc e.T1CH7.Text = CStr(I_VREF5)
    HFPS.DefInstanc e.T1CH8.Text = CStr(I_VKAM5V)
    HFPS.DefInstanc e.T1CH9.Text = CStr(I_VKAML2)
    HFPS.DefInstanc e.T1CH10.Text = CStr(I_VCCL)
    HFPS.DefInstanc e.T1CH11.Text = CStr(I_VCCL2)
    HFPS.DefInstanc e.T1CH12.Text = CStr(I_BUCKL)
    HFPS.DefInstanc e.T1CH13.Text = CStr(I_BUCKH)
    HFPS.DefInstanc e.T1CH14.Text = CStr(I_BAT)
    HFPS.DefInstanc e.Show()

    End Sub
    Sub Configure_34970 A(ByRef Instrument As Integer)
    Dim SCPIcmd As String
    Dim actual As Integer
    Dim Channel As String
    Dim i As Short
    Dim Slot As Short


    ' Set instrument to power on state
    SCPIcmd = "*RST"
    Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
    ' Configure all channels in channel list

    ' Configure all channels in channel list
    ' Slot =3 with all channels set to resistance Auto 6 ½ digits
    Slot = 3
    For i = 1 To 20
    Channel = VB6.Format(CStr (i), "00")
    SCPIcmd = "Conf:Res Auto,(@" & CStr(Slot) & CStr(Channel) &
    ");:Res:NPL C 0.02,(@" & CStr(Slot) & CStr(Channel) & ")"
    Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1,
    actual)
    Next i

    End Sub
    Sub SetScan_34970A( ByRef Instrument As Integer, ByRef numberSweeps As
    Short, ByRef numberChannels As Short)
    Dim SCPIcmd As String
    Dim replyString As New VB6.FixedLength String(256)
    Dim actual As Integer

    numberSweeps = 1
    ' Include the Measurement units with reading
    SCPIcmd = "Format:Reading :Unit On"
    Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
    ' Include the channel with reading
    SCPIcmd = "Format:Reading :Channel On"
    Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
    ' Include the time with reading
    SCPIcmd = "Format:Reading :Time On"
    Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
    ' Set up the scan List
    SCPIcmd = "Route:Scan
    (@301,302,303,3 04,305,306,307, 308,309,310,311 ,312,313,314,31 5,316,317,318,3 19,320)"
    Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
    ' Configure the trigger source
    SCPIcmd = "Trigger:So urce Timer"
    Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
    ' Set the time between scans
    SCPIcmd = "Trigger:Ti mer 0.01"
    Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
    ' Set the number of scans
    SCPIcmd = "Trigger:Co unt " & Str(numberSweep s)
    Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
    ' Read the number of channels on scan list
    SCPIcmd = "Route:Scan:Siz e?"
    Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
    Call viRead(Instrume nt, replyString.Val ue, 255, actual)
    numberChannels = Val(replyString .Value)
    ' Arm the trigger with initiate
    SCPIcmd = "Initiate"
    Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
    End Sub
    Sub ReadData_34970A (ByRef Instrument As Integer, ByRef Sweeps As
    Short, ByRef numberChannels As Short, ByRef Readings(,) As Double,
    ByRef Units(,) As String, ByRef ChanNumb(,) As Short, ByRef Time(,) As
    Date)
    Dim Points As Short
    Dim Channel As Short
    Dim SCPIcmd As String
    Dim actual As Integer
    Dim replyString As New VB6.FixedLength String(256)

    ' Get the data one channel at a time
    For Channel = 1 To numberChannels
    ' Wait for reading in instrument memory
    Do
    SCPIcmd = "Data:Point s?"
    Call viWrite(Instrum ent, SCPIcmd & Chr(10),
    Len(SCPIcmd) + 1, actual)
    Call viRead(Instrume nt, replyString.Val ue, 255, actual)
    Points = CShort(Left(rep lyString.Value, actual))
    Loop Until Points >= 1
    ' Get one channel of data from instrument
    SCPIcmd = "Data:Remov e? 1"
    Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) +
    1, actual)
    Call viRead(Instrume nt, replyString.Val ue, 255, actual)
    ' Remove the reading data from string
    Readings(Sweeps , Channel) = CDbl(Mid(replyS tring.Value, 1,
    15))
    ' Remove the units data from string
    Units(Sweeps, Channel) = Mid(replyString .Value, 17, 3)
    ' Remove the time data from string
    Time(Sweeps, Channel) =
    System.DateTime .FromOADate(Val (Mid(replyStrin g.Value, 21, 12)) / 86400)
    ' Remove the channel number from string
    ChanNumb(Sweeps , Channel) = Val(Mid(replySt ring.Value, 34,
    3))
    Next Channel
    End Sub
    End Module

  • Dragon

    #2
    Re: Help. Dot Net keep flagging an error remdim

    Hi,

    ReDim statement cannot change the number of dimensions in array, as
    error message says.
    So, if you'd like to use ReDim a 2-dimensional array, you need to
    declare it as 2-dimensional, e.g:

    ~
    Dim Readings(,) As Double
    ~

    HTH
    Roman


    Comment

    • J French

      #3
      Re: Help. Dot Net keep flagging an error remdim

      On 1 Sep 2005 02:28:59 -0700, "WAYNEL" <home@wlawson.c o.uk> wrote:
      [color=blue]
      >Hi
      >
      >I am trying to re-write some of the example code that Agilent gives for
      >VB to VB.Net.[/color]

      This NG is used by VB6 coders

      - there are NGs for VB.NET
      - to avoid confusing and misleading answers, ask in an appropriate NG

      For the microsoft news server, try these newsgroups...

      news://msnews.microsoft.com/microsof...dotnet.general
      news://msnews.microsoft.com/microsof...t.languages.vb
      news://msnews.microsoft.com/microsof....vsnet.general
      news://msnews.microsoft.com/microsof...studio.general
      news://msnews.microsoft.com/microsof....vstudio.setup

      Comment

      • Gijs Beukenoot

        #4
        Re: Help. Dot Net keep flagging an error remdim

        From WAYNEL :[color=blue]
        > Hi
        >
        > I am trying to re-write some of the example code that Agilent gives for
        > VB to VB.Net.
        > In .Net I keep getting the error 'cannot change the number of
        > dimensions of an array'.
        >[/color]

        [This answer is posted in microsoft.publi c.dotnet.langua ges.vb only]

        The ReDim statement is used to change the size of one or more
        dimensions of an array that has already been formally declared. ReDim
        cannot change the rank (the number of dimensions) of the array.

        So, in the beginning of your code, change
        Dim Readings() As Double
        to have the correct number of dimnensions
        Dim Readings(,) As Double
        and don't forget the rest of them


        Comment

        • Ken Tucker [MVP]

          #5
          Re: Help. Dot Net keep flagging an error remdim

          Hi,

          You are trying to make 1 dimension array 2 dimensions that is
          why you are getting the error. Try this instead

          Dim readings(,) As Double

          ReDim readings(10, 10)


          Ken
          -----------------------------
          "WAYNEL" <home@wlawson.c o.uk> wrote in message
          news:1125566939 .503353.147370@ g43g2000cwa.goo glegroups.com.. .
          Hi

          I am trying to re-write some of the example code that Agilent gives for
          VB to VB.Net.
          In .Net I keep getting the error 'cannot change the number of
          dimensions of an array'.

          I have paste the module I am having an issue with. Can anyone help!


          Thanks

          WayneL

          Module Module1

          ' Add the files visa32.bas and vpptype.bas, located in the
          ' directory vxipnp\Win95\in clude, to your Visual Basic
          ' project. Add the example code as a .bas module, and
          ' call main_34970A.
          'UPGRADE_WARNIN G: Application will terminate when Sub Main() finishes.
          Click for more:
          'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?ke yword="vbup1047 "'
          Public Sub Main()
          Dim numberChannels As Short
          Dim numberSweeps As Short
          Dim Sweep As Short
          Dim Readings() As Double
          Dim Units() As String
          Dim ChanNumb() As Short
          Dim Time() As Date
          Dim VISAaddress As String
          Dim status As Integer
          Dim viDefaultRM As Integer
          Dim Instrument As Integer
          Dim i As Short
          Dim Channel As String

          ' Declair all the HFPS currents

          Dim I_VADREF As Double
          Dim I_VCC As Double
          Dim I_VREF1 As Double
          Dim I_VREF2 As Double
          Dim I_VREF3 As Double
          Dim I_VREF4 As Double
          Dim I_VREF5 As Double
          Dim I_VKAM5V As Double
          Dim I_VKAML2 As Double
          Dim I_VCCL As Double
          Dim I_VCCL2 As Double
          Dim I_BUCKL As Double
          Dim I_BUCKH As Double
          Dim I_BAT As Double


          ' Declair all the HFPS voltages
          Dim V_VADREF As Double
          Dim V_VCC As Double
          Dim V_VREF1 As Double
          Dim V_VREF2 As Double
          Dim V_VREF3 As Double
          Dim V_VREF4 As Double
          Dim V_VREF5 As Double
          Dim V_VKAM5V As Double
          Dim V_VKAML2 As Double
          Dim V_VCCL As Double
          Dim V_VCCL2 As Double
          Dim V_BUCKL As Double
          Dim V_BUCKH As Double
          Dim V_BAT As Double


          HFPS.DefInstanc e.Show()

          VISAaddress = "9"
          status = viOpenDefaultRM (viDefaultRM)
          status = viOpen(viDefaul tRM, "GPIB::" & VISAaddress & "::INSTR", 0,
          2500, Instrument)
          If status < 0 Then
          MsgBox("Unable to open Port")
          End
          End If
          Configure_34970 A(Instrument)
          SetScan_34970A( Instrument, numberSweeps, numberChannels)

          ############### ############### ############### ############### ####
          Problem 'cannot change the number of dimensions of an array'
          Starts here!
          ############### ############### ############### ############### ####

          ' Size arrays depending on channel and sweep count
          ReDim Readings(number Sweeps, numberChannels)
          ReDim Units(numberSwe eps, numberChannels)
          ReDim ChanNumb(number Sweeps, numberChannels)
          ReDim Time(numberSwee ps, numberChannels)

          ############### ############### ############### ############### ####
          ' Get data one sweep at a time
          For Sweep = 1 To numberSweeps
          ReadData_34970A (Instrument, Sweep, numberChannels, Readings, Units,
          ChanNumb, Time)
          Next Sweep
          status = viClose(Instrum ent)
          status = viClose(viDefau ltRM)
          ' Get the current reading from the datalogger


          ' Reading (Sweep number, channel)
          I_VADREF = Readings(1, 1)
          I_VCC = Readings(1, 2)
          I_VREF1 = Readings(1, 3)
          I_VREF2 = Readings(1, 4)
          I_VREF3 = Readings(1, 5)
          I_VREF4 = Readings(1, 6)
          I_VREF5 = Readings(1, 7)
          I_VKAM5V = Readings(1, 8)
          I_VKAML2 = Readings(1, 9)
          I_VCCL = Readings(1, 10)
          I_VCCL2 = Readings(1, 11)
          I_BUCKL = Readings(1, 12)
          I_BUCKH = Readings(1, 13)
          I_BAT = Readings(1, 14)

          HFPS.DefInstanc e.T1CH1.Text = CStr(I_VADREF)
          HFPS.DefInstanc e.T1CH2.Text = CStr(I_VCC)
          HFPS.DefInstanc e.T1CH3.Text = CStr(I_VREF1)
          HFPS.DefInstanc e.T1CH4.Text = CStr(I_VREF2)
          HFPS.DefInstanc e.T1CH5.Text = CStr(I_VREF3)
          HFPS.DefInstanc e.T1CH6.Text = CStr(I_VREF4)
          HFPS.DefInstanc e.T1CH7.Text = CStr(I_VREF5)
          HFPS.DefInstanc e.T1CH8.Text = CStr(I_VKAM5V)
          HFPS.DefInstanc e.T1CH9.Text = CStr(I_VKAML2)
          HFPS.DefInstanc e.T1CH10.Text = CStr(I_VCCL)
          HFPS.DefInstanc e.T1CH11.Text = CStr(I_VCCL2)
          HFPS.DefInstanc e.T1CH12.Text = CStr(I_BUCKL)
          HFPS.DefInstanc e.T1CH13.Text = CStr(I_BUCKH)
          HFPS.DefInstanc e.T1CH14.Text = CStr(I_BAT)
          HFPS.DefInstanc e.Show()

          End Sub
          Sub Configure_34970 A(ByRef Instrument As Integer)
          Dim SCPIcmd As String
          Dim actual As Integer
          Dim Channel As String
          Dim i As Short
          Dim Slot As Short


          ' Set instrument to power on state
          SCPIcmd = "*RST"
          Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
          ' Configure all channels in channel list

          ' Configure all channels in channel list
          ' Slot =3 with all channels set to resistance Auto 6 ½ digits
          Slot = 3
          For i = 1 To 20
          Channel = VB6.Format(CStr (i), "00")
          SCPIcmd = "Conf:Res Auto,(@" & CStr(Slot) & CStr(Channel) &
          ");:Res:NPL C 0.02,(@" & CStr(Slot) & CStr(Channel) & ")"
          Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1,
          actual)
          Next i

          End Sub
          Sub SetScan_34970A( ByRef Instrument As Integer, ByRef numberSweeps As
          Short, ByRef numberChannels As Short)
          Dim SCPIcmd As String
          Dim replyString As New VB6.FixedLength String(256)
          Dim actual As Integer

          numberSweeps = 1
          ' Include the Measurement units with reading
          SCPIcmd = "Format:Reading :Unit On"
          Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
          ' Include the channel with reading
          SCPIcmd = "Format:Reading :Channel On"
          Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
          ' Include the time with reading
          SCPIcmd = "Format:Reading :Time On"
          Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
          ' Set up the scan List
          SCPIcmd = "Route:Scan
          (@301,302,303,3 04,305,306,307, 308,309,310,311 ,312,313,314,31 5,316,317,318,3 19,320)"
          Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
          ' Configure the trigger source
          SCPIcmd = "Trigger:So urce Timer"
          Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
          ' Set the time between scans
          SCPIcmd = "Trigger:Ti mer 0.01"
          Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
          ' Set the number of scans
          SCPIcmd = "Trigger:Co unt " & Str(numberSweep s)
          Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
          ' Read the number of channels on scan list
          SCPIcmd = "Route:Scan:Siz e?"
          Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
          Call viRead(Instrume nt, replyString.Val ue, 255, actual)
          numberChannels = Val(replyString .Value)
          ' Arm the trigger with initiate
          SCPIcmd = "Initiate"
          Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
          End Sub
          Sub ReadData_34970A (ByRef Instrument As Integer, ByRef Sweeps As
          Short, ByRef numberChannels As Short, ByRef Readings(,) As Double,
          ByRef Units(,) As String, ByRef ChanNumb(,) As Short, ByRef Time(,) As
          Date)
          Dim Points As Short
          Dim Channel As Short
          Dim SCPIcmd As String
          Dim actual As Integer
          Dim replyString As New VB6.FixedLength String(256)

          ' Get the data one channel at a time
          For Channel = 1 To numberChannels
          ' Wait for reading in instrument memory
          Do
          SCPIcmd = "Data:Point s?"
          Call viWrite(Instrum ent, SCPIcmd & Chr(10),
          Len(SCPIcmd) + 1, actual)
          Call viRead(Instrume nt, replyString.Val ue, 255, actual)
          Points = CShort(Left(rep lyString.Value, actual))
          Loop Until Points >= 1
          ' Get one channel of data from instrument
          SCPIcmd = "Data:Remov e? 1"
          Call viWrite(Instrum ent, SCPIcmd & Chr(10), Len(SCPIcmd) +
          1, actual)
          Call viRead(Instrume nt, replyString.Val ue, 255, actual)
          ' Remove the reading data from string
          Readings(Sweeps , Channel) = CDbl(Mid(replyS tring.Value, 1,
          15))
          ' Remove the units data from string
          Units(Sweeps, Channel) = Mid(replyString .Value, 17, 3)
          ' Remove the time data from string
          Time(Sweeps, Channel) =
          System.DateTime .FromOADate(Val (Mid(replyStrin g.Value, 21, 12)) / 86400)
          ' Remove the channel number from string
          ChanNumb(Sweeps , Channel) = Val(Mid(replySt ring.Value, 34,
          3))
          Next Channel
          End Sub
          End Module


          Comment

          Working...