Passing function value to multidimensional array
Passing function value to multidimensional array
Passing function value to multidimensional array
Passing function value to multidimensional array
Passing function value to multidimensional array
Passing function value to multidimensional array Passing function value to multidimensional array Passing function value to multidimensional array Passing function value to multidimensional array Passing function value to multidimensional array Passing function value to multidimensional array Passing function value to multidimensional array Passing function value to multidimensional array
Passing function value to multidimensional array Passing function value to multidimensional array
Passing function value to multidimensional array
Go Back  Xtreme Visual Basic Talk > > > Passing function value to multidimensional array


Reply
 
Thread Tools Display Modes
  #1  
Old 10-08-2014, 09:26 AM
Rodrigo Mota Rodrigo Mota is offline
Regular
 
Join Date: Apr 2005
Location: Portugal
Posts: 53
Default Passing function value to multidimensional array


Hi guys, how can I get the value returned by the function into the array?
I get an error when trying to assigning it the result.
Here is the code:
Code:
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim aspen As AtProcessDataAuto.ProcessDataFunctions
        Dim tag As String = "li0816a"
        Dim server As String = "Rtdb Porto"
        Dim map As String = ""
        Dim valor(,) As Integer

        valor(, ) = aspen.CurrentValue(tag, server, map, 16, 0, 0)

        Me.Label1.Text = valor(0, 0)

    End Sub
End Class
Thanks for your time and help.
Reply With Quote
  #2  
Old 10-08-2014, 10:11 AM
PlausiblyDamp's Avatar
PlausiblyDampPassing function value to multidimensional array PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

So any clue as to what error you are getting or what the aspen.CurrentValue function returns?
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 10-08-2014, 01:02 PM
Rodrigo Mota Rodrigo Mota is offline
Regular
 
Join Date: Apr 2005
Location: Portugal
Posts: 53
Default

Hi PlausiblyDamp, I don't get any error as I can't compile the program, if I hover valor(,) in valor(, ) = aspen.CurrentValue(tag, server, map, 16, 0, 0), I get the following: Array subscript expression missing.
The aspen.CurrentValue(.....) returns a value associated with a timestamp.
Ex:
valor(0,0)=32.5
valor(1,0)=timestamp
Reply With Quote
  #4  
Old 10-08-2014, 03:17 PM
passel's Avatar
passelPassing function value to multidimensional array passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

You have valor defined as a 2d array of Integer, but you say for example it would contain 32.5, which is not an Integer. An Integer can only be "Whole" numbers, no fractional part.
In any case, assuming the function is returning a 2d array of Integer, then your line should be:

valor = aspen.CurrentValue(tag, server, map, 16, 0, 0)

As a quick test example, I tried this.
Code:
  Private Function aspen() As Single(,)
    Dim test(1, 0) As Single
    test(0, 0) = 32.5
    test(1, 0) = 12345.6
    Return test
  End Function

  Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim valor(,) As Single
    valor = aspen()
    Debug.Print("{0} {1}", valor(0, 0), valor(1, 0))
  End Sub

'and it printed in the Output Window (on my machine)
32.5 12345.6
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #5  
Old 10-08-2014, 03:32 PM
Rodrigo Mota Rodrigo Mota is offline
Regular
 
Join Date: Apr 2005
Location: Portugal
Posts: 53
Default

Thanks for your reply passel your code should work fine, unfortunately I found another problem.
the function isn't returning what it's suposed to.
I don't know if any of you are familiarized with Aspen Tech real time data base and process explorer application?
My problem is that if I use the xla addin it works pretty fine in VBA, but when I try to get it to net the problems start to appear.
VBA code:
Code:
sub getValues()
dim val()as variant
dim tag as string
dim server as string
...
val() = atgettrend(tag, server, Map, starttime, endtime, npoints, Period, Calculation, nDSetting, nOrientation, nTagDirection)

For t = 1 To period - 1
debug.print val(0,t)
Next 

end sub
and the add in I use in the references is: AspenProcessDataAddin

In VB.net the add in is the AtProcessDataAuto.dll that has the before mentioned function, but the problem is that it says it returns an integer, when it should be returning an array (like the vba one). Also when I try to see what integer it's returning I get a "An unhandled exception of type 'System.NullReferenceException' occurred in Testes.exe"
In other words... I'm stuck :P

Thank you.
Reply With Quote
  #6  
Old 10-08-2014, 05:41 PM
PlausiblyDamp's Avatar
PlausiblyDampPassing function value to multidimensional array PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

What is the defined return type of the aspen.CurrentValue function? Without knowing what it returns we are just guessing at how to fix the problem.

To assign the result of the function to a variable you don't need to include the (,) after it.
e.g.
Code:
Dim valor(,) As Integer    'Define the variable

valor = aspen.CurrentValue(tag, server, map, 16, 0, 0)    'assign a value to the variable
this does however require the variable to be defined correctly.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #7  
Old 10-09-2014, 10:30 AM
Rodrigo Mota Rodrigo Mota is offline
Regular
 
Join Date: Apr 2005
Location: Portugal
Posts: 53
Default

If I hover the function it displays the following:

Public Function CurrentValue(ByRef tags As Object, ByRef servers As Object, ByRef maps As Object, dsetting As Integer, orinetation As Short, ByRef data As Object) As Integer
Reply With Quote
  #8  
Old 10-10-2014, 08:39 AM
passel's Avatar
passelPassing function value to multidimensional array passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Ok, so it says it returns an Integer, "...) As Integer", so you shouldn't be assigning the returned value to an array, let along a two dimensional array.
Code:
Dim valor As Integer    'Define the variable

valor = aspen.CurrentValue(tag, server, map, 16, 0, 0)    'assign a value to the variable
<edit>
Also, you seem to be comparing "apples to oranges", i.e. referencing two different functions.
In VBA you gave this example

val() = atgettrend(tag, server, Map, starttime, endtime, npoints, Period, Calculation, nDSetting, nOrientation, nTagDirection)

so it looks like you're calling a function that will "get trend", returning an array (a 2d array by the way you reference the result later).

But in .Net you're calling "CurrentValue", which obviously returns the "current value" of some item, a single value.

It would seem you would also want to call the "get trend" function in .Net if you want it to do the same thing as your VBA code.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 10-10-2014 at 08:46 AM.
Reply With Quote
  #9  
Old 10-12-2014, 03:27 AM
Rodrigo Mota Rodrigo Mota is offline
Regular
 
Join Date: Apr 2005
Location: Portugal
Posts: 53
Default

Hi Passel, I've already defined the variable as an Integer but I still get a null value from the function.
As for the functions they're similar and in VBA they both work the same way, the only difference is that in trend you get a set o values in a time interval and in currVal you get the current value at the current time.
The data is from Aspen Tech Process Explorer and is a realtime database allowing you to get values at times, aggregates, current values, etc, for different controllers (tags).
From what I know the database is Aspen InfoPlus2.1 but I would like to use the at Functions of process explorer in .net as I use it in VBA, becaus eI don't think I'll be able to connect directly to the DB and query it.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Passing function value to multidimensional array
Passing function value to multidimensional array
Passing function value to multidimensional array Passing function value to multidimensional array
Passing function value to multidimensional array
Passing function value to multidimensional array
Passing function value to multidimensional array Passing function value to multidimensional array Passing function value to multidimensional array Passing function value to multidimensional array Passing function value to multidimensional array Passing function value to multidimensional array Passing function value to multidimensional array
Passing function value to multidimensional array
Passing function value to multidimensional array
 
Passing function value to multidimensional array
Passing function value to multidimensional array
 
-->