By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,306 Members | 1,621 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,306 IT Pros & Developers. It's quick & easy.

Help. Dot Net keep flagging an error remdim

P: n/a
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\include, to your Visual Basic
' project. Add the example code as a .bas module, and
' call main_34970A.
'UPGRADE_WARNING: Application will terminate when Sub Main() finishes.
Click for more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="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.DefInstance.Show()

VISAaddress = "9"
status = viOpenDefaultRM(viDefaultRM)
status = viOpen(viDefaultRM, "GPIB::" & VISAaddress & "::INSTR", 0,
2500, Instrument)
If status < 0 Then
MsgBox("Unable to open Port")
End
End If
Configure_34970A(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(numberSweeps, numberChannels)
ReDim Units(numberSweeps, numberChannels)
ReDim ChanNumb(numberSweeps, numberChannels)
ReDim Time(numberSweeps, 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(Instrument)
status = viClose(viDefaultRM)
' 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.DefInstance.T1CH1.Text = CStr(I_VADREF)
HFPS.DefInstance.T1CH2.Text = CStr(I_VCC)
HFPS.DefInstance.T1CH3.Text = CStr(I_VREF1)
HFPS.DefInstance.T1CH4.Text = CStr(I_VREF2)
HFPS.DefInstance.T1CH5.Text = CStr(I_VREF3)
HFPS.DefInstance.T1CH6.Text = CStr(I_VREF4)
HFPS.DefInstance.T1CH7.Text = CStr(I_VREF5)
HFPS.DefInstance.T1CH8.Text = CStr(I_VKAM5V)
HFPS.DefInstance.T1CH9.Text = CStr(I_VKAML2)
HFPS.DefInstance.T1CH10.Text = CStr(I_VCCL)
HFPS.DefInstance.T1CH11.Text = CStr(I_VCCL2)
HFPS.DefInstance.T1CH12.Text = CStr(I_BUCKL)
HFPS.DefInstance.T1CH13.Text = CStr(I_BUCKH)
HFPS.DefInstance.T1CH14.Text = CStr(I_BAT)
HFPS.DefInstance.Show()

End Sub
Sub Configure_34970A(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(Instrument, 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:NPLC 0.02,(@" & CStr(Slot) & CStr(Channel) & ")"
Call viWrite(Instrument, 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.FixedLengthString(256)
Dim actual As Integer

numberSweeps = 1
' Include the Measurement units with reading
SCPIcmd = "Format:Reading:Unit On"
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
' Include the channel with reading
SCPIcmd = "Format:Reading:Channel On"
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
' Include the time with reading
SCPIcmd = "Format:Reading:Time On"
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
' Set up the scan List
SCPIcmd = "Route:Scan
(@301,302,303,304,305,306,307,308,309,310,311,312, 313,314,315,316,317,318,319,320)"
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
' Configure the trigger source
SCPIcmd = "Trigger:Source Timer"
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
' Set the time between scans
SCPIcmd = "Trigger:Timer 0.01"
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
' Set the number of scans
SCPIcmd = "Trigger:Count " & Str(numberSweeps)
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
' Read the number of channels on scan list
SCPIcmd = "Route:Scan:Size?"
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
Call viRead(Instrument, replyString.Value, 255, actual)
numberChannels = Val(replyString.Value)
' Arm the trigger with initiate
SCPIcmd = "Initiate"
Call viWrite(Instrument, 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.FixedLengthString(256)

' Get the data one channel at a time
For Channel = 1 To numberChannels
' Wait for reading in instrument memory
Do
SCPIcmd = "Data:Points?"
Call viWrite(Instrument, SCPIcmd & Chr(10),
Len(SCPIcmd) + 1, actual)
Call viRead(Instrument, replyString.Value, 255, actual)
Points = CShort(Left(replyString.Value, actual))
Loop Until Points >= 1
' Get one channel of data from instrument
SCPIcmd = "Data:Remove? 1"
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) +
1, actual)
Call viRead(Instrument, replyString.Value, 255, actual)
' Remove the reading data from string
Readings(Sweeps, Channel) = CDbl(Mid(replyString.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(replyString.Val ue, 21, 12)) / 86400)
' Remove the channel number from string
ChanNumb(Sweeps, Channel) = Val(Mid(replyString.Value, 34,
3))
Next Channel
End Sub
End Module

Sep 1 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 1 Sep 2005 02:28:59 -0700, "WAYNEL" <ho**@wlawson.co.uk> wrote:
Hi

I am trying to re-write some of the example code that Agilent gives for
VB to VB.Net.


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

Sep 1 '05 #2

P: n/a
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" <ho**@wlawson.co.uk> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.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\include, to your Visual Basic
' project. Add the example code as a .bas module, and
' call main_34970A.
'UPGRADE_WARNING: Application will terminate when Sub Main() finishes.
Click for more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="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.DefInstance.Show()

VISAaddress = "9"
status = viOpenDefaultRM(viDefaultRM)
status = viOpen(viDefaultRM, "GPIB::" & VISAaddress & "::INSTR", 0,
2500, Instrument)
If status < 0 Then
MsgBox("Unable to open Port")
End
End If
Configure_34970A(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(numberSweeps, numberChannels)
ReDim Units(numberSweeps, numberChannels)
ReDim ChanNumb(numberSweeps, numberChannels)
ReDim Time(numberSweeps, 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(Instrument)
status = viClose(viDefaultRM)
' 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.DefInstance.T1CH1.Text = CStr(I_VADREF)
HFPS.DefInstance.T1CH2.Text = CStr(I_VCC)
HFPS.DefInstance.T1CH3.Text = CStr(I_VREF1)
HFPS.DefInstance.T1CH4.Text = CStr(I_VREF2)
HFPS.DefInstance.T1CH5.Text = CStr(I_VREF3)
HFPS.DefInstance.T1CH6.Text = CStr(I_VREF4)
HFPS.DefInstance.T1CH7.Text = CStr(I_VREF5)
HFPS.DefInstance.T1CH8.Text = CStr(I_VKAM5V)
HFPS.DefInstance.T1CH9.Text = CStr(I_VKAML2)
HFPS.DefInstance.T1CH10.Text = CStr(I_VCCL)
HFPS.DefInstance.T1CH11.Text = CStr(I_VCCL2)
HFPS.DefInstance.T1CH12.Text = CStr(I_BUCKL)
HFPS.DefInstance.T1CH13.Text = CStr(I_BUCKH)
HFPS.DefInstance.T1CH14.Text = CStr(I_BAT)
HFPS.DefInstance.Show()

End Sub
Sub Configure_34970A(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(Instrument, 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:NPLC 0.02,(@" & CStr(Slot) & CStr(Channel) & ")"
Call viWrite(Instrument, 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.FixedLengthString(256)
Dim actual As Integer

numberSweeps = 1
' Include the Measurement units with reading
SCPIcmd = "Format:Reading:Unit On"
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
' Include the channel with reading
SCPIcmd = "Format:Reading:Channel On"
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
' Include the time with reading
SCPIcmd = "Format:Reading:Time On"
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
' Set up the scan List
SCPIcmd = "Route:Scan
(@301,302,303,304,305,306,307,308,309,310,311,312, 313,314,315,316,317,318,319,320)"
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
' Configure the trigger source
SCPIcmd = "Trigger:Source Timer"
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
' Set the time between scans
SCPIcmd = "Trigger:Timer 0.01"
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
' Set the number of scans
SCPIcmd = "Trigger:Count " & Str(numberSweeps)
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
' Read the number of channels on scan list
SCPIcmd = "Route:Scan:Size?"
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) + 1, actual)
Call viRead(Instrument, replyString.Value, 255, actual)
numberChannels = Val(replyString.Value)
' Arm the trigger with initiate
SCPIcmd = "Initiate"
Call viWrite(Instrument, 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.FixedLengthString(256)

' Get the data one channel at a time
For Channel = 1 To numberChannels
' Wait for reading in instrument memory
Do
SCPIcmd = "Data:Points?"
Call viWrite(Instrument, SCPIcmd & Chr(10),
Len(SCPIcmd) + 1, actual)
Call viRead(Instrument, replyString.Value, 255, actual)
Points = CShort(Left(replyString.Value, actual))
Loop Until Points >= 1
' Get one channel of data from instrument
SCPIcmd = "Data:Remove? 1"
Call viWrite(Instrument, SCPIcmd & Chr(10), Len(SCPIcmd) +
1, actual)
Call viRead(Instrument, replyString.Value, 255, actual)
' Remove the reading data from string
Readings(Sweeps, Channel) = CDbl(Mid(replyString.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(replyString.Val ue, 21, 12)) / 86400)
' Remove the channel number from string
ChanNumb(Sweeps, Channel) = Val(Mid(replyString.Value, 34,
3))
Next Channel
End Sub
End Module
Sep 1 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.