To all
I am testing passing an array from a sub to a function which then returns an array. I am having trouble with the indices.
The test below doesn't do anything clever. I am only testing passing array()
Thanks
Regards
JXB
'----------------------------------------------
Sub TestingArray()
Dim myvalues()
Dim testarray()
myvalues={0.,0.,0.,0.} ' initialise array
testarray={0.,0.,0.,0.} ' initialise array
'Pass the array testarray() to function ReturnedArray()
'the function ReturnedArray() returns a new array
'which is allocated to array myvalues()
myvalues = ReturnedArray(testarray)
InfoWindow.WriteLine ("--" & myvalues(1))
End Sub
Function ReturnedArray(ByRef InputArray() As Object)
Dim myarray() as Double = {10,20,30,40}
ReturnedArray=myarray()
End Function
re: pass array
Arrays are zero based. In your code myarray(0)=10, myarray(1)=20, etc. The 'length' of your array is 4, you can iterate through the array by going from 0 to length - 1.
Base option 1
Thanks for that. I did notice that the Base option 1 is not accepted in NX!
I think the trouble is on the line
ReturnedArray=myarray()
where the programme cannot do that as I think it does not recognise ReturnedArray as an array
Thanks
Regards
re: base option
The "base option" has nothing to do with NX, it is not an option in .net. In VB6 and earlier(?) you could use it, but no longer.
http://support.microsoft.com/kb/311333
re: return array
I made a few tweaks, see if this does what you want.
Sub TestingArray()
Dim myvalues() As Double
Dim testarray() As Double
myvalues = {0, 0, 0, 0} ' initialise array
testarray = {0, 0, 0, 0} ' initialise array
'Pass the array testarray() to function ReturnedArray()
'the function ReturnedArray() returns a new array
'which is allocated to array myvalues()
myvalues = ReturnedArray(testarray)
lw.WriteLine("-- " & myvalues(1))
End Sub
Function ReturnedArray(ByRef InputArray() As Double) As Double()
Dim myarray() As Double = {10, 20, 30, 40}
Return myarray
End Function
Thanks for that. Much
Thanks for that. Much appreciated. It looks like the way I defined my array variable is a bit sloppy!
2 very stupid questions
1. I am writing in vb using Notepad ++. Is this not the langue to use?
2. Is there a way of using the following
myvariable1=2 : myvariable2=3: myvariable3=4
like in xls macro
Thanks
Regards
re: IDE
Notepad++ is much better than notepad or the NX text editor, but better still is an integrated development environment (IDE). Microsoft offers "express" editions that you can use for free, they can be found here:
http://www.visualstudio.com/downloads/download-visual-studio-vs
I'm currently using VB.net express 2010, but the newer versions should also work.
Yes, you can use the syntax of:
myvariable1=2 : myvariable2=3: myvariable3=4
Downloaded visualstudio "express"
Thanks for the link. Another tool to learn! I am gathering notes on the way to deploy the macros/journals. At the moment I have a 3-4 stand alone .vb files which works fine. I need to think of the best way of "deploying" them as 1 file/application. I think this is done with .dll (?). I have found stuff on the Siemens web site which I may upload once I have tarted up the notes and understood them. The idea is to have all the vb files (and .dlx if GUI are created) as 1 "project" (myNXlibrary.dll ?) which is up-loaded when the user is starting NX
Any suggestions or pitfalls to avoid are welcome
Thanks
Regards
JXB
I have found notes on using the ribbon to define a new menu but so far it is partially working
Thanks
Regards