12 Replies - 1961 Views - Last Post: 31 January 2013 - 01:13 PM Rate Topic: -----

#1 mannakhan10  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 21-May 11

ASP - Arithmetic Operations within Array

Posted 28 January 2013 - 10:03 AM

Hey guys it's been a while since I last posted anything here.

Kinda stuck on something I feel as though is really easy but I'm just not getting it...
But let's get right to it.

Posting it in Web Development General because I didn't see a section for ASP.

I'm working with a Osisoft PI server that displays real-time updating values per PI tag.
We are displaying the information in the simplest way possible using ASP, which will display the PI tags' value when you refresh it.

Dim u7
u7 = Array(_
    Array("", "", "", ""), _
    Array("Watts", "U7RL:348", "110", "", "") _


However, when it comes to ASP, I'm trying to figure out how to take the static PI tag within the array and use it for a function to display in that same array.

Please refer to my code above.
Array is as follows:
Array("LABEL/TITLE OF PI TAG", "STATIC PI TAG DISPLAYING A VALUE (NOT THE TAG)", "TARGET VALUE", "DIFFERENCE BETWEEN PI TAG AND TARGET VALUE"), _


In other terms:
Array("Temperature", "TEMP:01", "32", "TEMP:01 - 32"), _


There aren't too many guides on ASP online as most just pull up ASP.NET related information.
I tried declaring the target value as an integer:

intTarget = 32


before writing in the code, then putting in the arithmetic function to carry out, but that does not work and gives the page errors.

I've looked into VBscript for looping and if/then/else statements. I'm wondering what I would need to use loops instead?
Do I even need to use VBscript? I think I can accomplish this using purely ASP.
I've gone to W3Schools.net and read up on a few things, but they don't seem to help.

Can anyone guide me on how to pull a static value for a PI tag, and then use it in an arithmetic operation within the same array, and then display it with the correct real time calculation?

The code I am working with uses HTML, VBScript, SQL, and connects to a remote server to pull in values per tags associated with them.
I feel as though I may have to change the way my code builds the HTML table and SQL statements? Or maybe it does not see the PI tag as a numerical value? Not sure where to start.

Additional Information Just in case:

' Build the WHERE clause of the SQL statement with all the tag names '
strWhere = ""
strWhere = BuildSQL(u7, strWhere)
strSQL = "SELECT status, tag, text = DIGSTRING(status), Rval=Value FROM picomp WHERE tag in (" & strWhere & ") AND Time = DATE('*')"

' Execute the SQL statement'
Set oRecordSet = oConnection.Execute(strSQL, nRec)
if Err.number  <> 0 then
	ErrorHandler 2
end if

' Build the 'vib USS' table '
response.write "<HR><TABLE class = 'clsTable'>"
response.write "<TR>"
response.write "<TD><U> Unit 7 </U></TD>"
response.write "</TR>"
response.write "<TR>"
response.write "<TD><U>Descriptions</U></TD>"
response.write "<TD><U> Current Value </U></TD>"
response.write "<TD><U> Target Value </U></TD>"
response.write "<TD><U> Difference </U></TD>"
response.write "</TR>"
BuildTable0 u7, oRecordset, 0
response.write "</TABLE>"


HTML Code for building the table:
<style>
body
{
	background-color:black;
}

.clsTable
{

	cellspacing: 0;
	cellpadding:0;
	font-weight: bold;
	font-size: 8pt;
	color: white;
	font-family: Tahoma;
	background-color:black;
	frame:void;
}
</style>


If any questions or need any additional information let me know.
Any and all suggestions, help, and guidance is much appreciated as I've been stuck on what route to go.
Thanks everyone!

Is This A Good Question/Topic? 0
  • +

Replies To: ASP - Arithmetic Operations within Array

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3215
  • View blog
  • Posts: 10,785
  • Joined: 12-December 12

Re: ASP - Arithmetic Operations within Array

Posted 28 January 2013 - 10:31 AM

This is not very clear to me: What exact problem are you having and what errors do you receive? Have you managed to pull data into an array? If so, what are you then trying to do with the array?

Some clarification required.

BTW What is frame:void in your CSS?
Was This Post Helpful? 0
  • +
  • -

#3 mannakhan10  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 21-May 11

Re: ASP - Arithmetic Operations within Array

Posted 28 January 2013 - 11:51 AM

View Postandrewsw, on 28 January 2013 - 10:31 AM, said:

This is not very clear to me: What exact problem are you having and what errors do you receive? Have you managed to pull data into an array? If so, what are you then trying to do with the array?

Some clarification required.

BTW What is frame:void in your CSS?


Hi andrewsw. I'm trying to take the value I get from a remote server that associates numerical values with tag-names, known as PI tags (i.e. "TEMP:01") and uses a function to calculate additional information for another part of that same array.
This tag will display a number that is associated with "Temperature", and on the ASP page while updating real time every time I refresh my page. The "32" next to it is the target temperature I am aiming for. After the "32" there is another section in the array. In that "" I want to show the difference between the numerical value I get from the "TEMP:01" PI tag and the Target Value of "32".
I do not believe it is possible to take the numerical value displayed from the PI tag and code in arithmetic operators.

For example:
Array("Temperature", "TEMP:01", "32", TEMP:01 - 32), _


(assuming TEMP:01 is currently 33.5 degrees F) would display on the page as:

Temperature 33.5 32 1.5

I am trying to get it to follow that format and actually calculate the values for me, however, I get an error such as "Mismatch 2" and other strange errors where my page does not display at all and I get a white page with an error message.

I've now tried declaring the Target Value as:
intTarval = 32

and writing the array as:
Array("Temperature", "TEMP:01", "intTarval", "TEMP:01" - "intTaravl"), _


However, that does not work either.

The frame:void takes out the outer border created by the table to make it invisible. But since the background is black, that part of the CSS makes no difference in the code it seems.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3215
  • View blog
  • Posts: 10,785
  • Joined: 12-December 12

Re: ASP - Arithmetic Operations within Array

Posted 28 January 2013 - 12:12 PM

Well, to answer the first question

Array("Temperature", "TEMP:01", "intTarval", "TEMP:01" - "intTaravl"), _
is incorrect. If you want to append the value of the variable 'intTaravl' to the end of the text "TEMP:01" then you need to concatenate using the & sign:

"TEMP:01" & intTaravl


If you want " - " to appear between then you need to include that as well:

"TEMP:01 - " & intTaravl

BTW You've supplied an awful lot of information which has obscured a straight-forward question.

Also, from your opening code, make sure that , _ is appropriate at the end of the line. That is, the next line must be a continuation of the current lines' statement.

[Is this VBScript or VB.Net? Dunno.]

This post has been edited by andrewsw: 28 January 2013 - 12:16 PM

Was This Post Helpful? 1
  • +
  • -

#5 mannakhan10  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 21-May 11

Re: ASP - Arithmetic Operations within Array

Posted 28 January 2013 - 12:17 PM

' Initialize all tag arrays for Unit 7'
Dim intTemp, intPi
intTemp = 32
intPi = 30
Dim u7
u7 = Array(_
    Array("", "", "", ""), _
    Array("Temperature", "TEMP:01", intNMT, intNMT - intPi) _


Will display the code on the page as:

Temperature 33.5 32 2

However, what my true intention is is to make the code seem similar to this by utilizing the value that is found in the PI tag that will provide the current temperature value:
' Initialize all tag arrays for Unit 7'
Dim intTemp, intPi
intTemp = 32
intPi = TEMP:01 //the current numerical values from TEMP:01
Dim u7
u7 = Array(_
    Array("", "", "", ""), _
    Array("Temperature", "TEMP:01", intNMT, intNMT - intPi) _


and display as on the ASP page:

Temperature 34.58 32 2.58

View Postandrewsw, on 28 January 2013 - 12:12 PM, said:

Well, to answer the first question

Array("Temperature", "TEMP:01", "intTarval", "TEMP:01" - "intTaravl"), _
is incorrect. If you want to append the value of the variable 'intTaravl' to the end of the text "TEMP:01" then you need to concatenate using the & sign:

"TEMP:01" & intTaravl


If you want " - " to appear between then you need to include that as well:

"TEMP:01 - " & intTaravl

BTW You've supplied an awful lot of information which has obscured a straight-forward question.

Also, from your opening code, make sure that , _ is appropriate at the end of the line. That is, the next line must be a continuation of the current lines' statement.


That was an error on my part when posting haha.
However, you have provided much help. I will go ahead and try this out and let you know what errors I get (if any).
Was This Post Helpful? 0
  • +
  • -

#6 mannakhan10  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 21-May 11

Re: ASP - Arithmetic Operations within Array

Posted 28 January 2013 - 12:46 PM

I have tried the following code:

' Initialize all tag arrays for Unit 7'
Dim intTemp
intTemp = 32
Dim u7
u7 = Array(_
Array("", "", "", ""), _
Array("Temperature", "TEMP:01", intTemp, "TEMP:01 -" & intTemp) _


However, it does not calculate out the value to be displayed. It just displays:
Tag < TEMP:01 -32 > not found 2

on the page.
From what I can tell, it sees the whole part:
"TEMP:01 -" & intTemp

from:
Array(... , ... , ... , "TEMP:01 -" & intTemp) _


as one of my PI tags...

Is there any possible way to store that static value from "TEMP:01" as an integer or variable?

I've been searching all over Google and there's a bunch of stuff for ASP.NET but not ASP.

And I am using the default scripting language for ASP, VBscript.

Thanks for all the help and patience so far andrewsw.
Was This Post Helpful? 0
  • +
  • -

#7 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 262
  • View blog
  • Posts: 1,460
  • Joined: 07-April 08

Re: ASP - Arithmetic Operations within Array

Posted 29 January 2013 - 01:57 PM

View Postandrewsw, on 28 January 2013 - 02:12 PM, said:

[Is this VBScript or VB.Net? Dunno.]


To answer this question it will be VBScript as "Classic" ASP (ASP 3.0) used VBScript.


As for mannakhan10, I'm not exactly sure I understand what your asking. You're kind of all over the place in your posts. I will review what you have a few times to see if I understand it, but in the mean time if you can post the entirety of your code. I think part of the confusion is that we get little bits and pieces. Specifically related to BuildTable0 as I think your problems are in there.
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3215
  • View blog
  • Posts: 10,785
  • Joined: 12-December 12

Re: ASP - Arithmetic Operations within Array

Posted 29 January 2013 - 02:54 PM

Quote

To answer this question it will be VBScript as "Classic" ASP (ASP 3.0) used VBScript.


I asked because the Array assignment is incorrect AFAIK in VBScript(?). That is, I don't think we can use Array literals in this assignment. I might be wrong :)

This post has been edited by andrewsw: 29 January 2013 - 02:55 PM

Was This Post Helpful? 0
  • +
  • -

#9 mannakhan10  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 21-May 11

Re: ASP - Arithmetic Operations within Array

Posted 30 January 2013 - 09:52 AM

View Postrgfirefly24, on 29 January 2013 - 01:57 PM, said:

View Postandrewsw, on 28 January 2013 - 02:12 PM, said:

[Is this VBScript or VB.Net? Dunno.]


To answer this question it will be VBScript as "Classic" ASP (ASP 3.0) used VBScript.


As for mannakhan10, I'm not exactly sure I understand what your asking. You're kind of all over the place in your posts. I will review what you have a few times to see if I understand it, but in the mean time if you can post the entirety of your code. I think part of the confusion is that we get little bits and pieces. Specifically related to BuildTable0 as I think your problems are in there.


I guess to put it in the most simplest form:
TEMP:01 is a static numerical value that I connect to a server and pull the information using the Tag.
However, in the array, it displays the numerical value of TEMP:01 which is 35. The Target Value is 32.
I need the array to take the server tag (TEMP:01) numerical value of 35, and find the difference between the Target Value of 32.
Example:

u7 = Array(_  
Array("", "", "", ""), _  
Array("Temperature", "TEMP:01", 32, "TEMP:01 -" & 32) _


I get errors like:
Tag < TEMP:01 -32 > not found 2

I think it sees that part of the array as a one of the Tag values as well.

Is there a way to take the Tag Value (TEMP:01) and store the numerical value it gives by assigning it to something and then carrying out the arithmetic function, which will show the difference on the page?

Here is the code in its entirety. But the Tag values will not be visible to you since you cannot connect to the servers.
Sorry for the inconvenience:

<html>

<head>
<title>Temp And Pressure Checker</title>
<style>
body
{
	background-color:black;
}

.clsTable
{

	cellspacing: 0;
	cellpadding:0;
	font-weight: bold;
	font-size: 8pt;
	color: white;
	font-family: Tahoma;
	background-color:black;
	frame:void;
}
</style>
</head>

<body>

<%

On Error Resume Next

' PI connection parameters '
Dim sPIconn, sPIuser, sPIpwd
sPIconn = "ps-server"
sPIuser = "demo"
sPIpwd = ""
    
' Error Handler - Displays error message on page '
sub ErrorHandler(iNum)
	response.write "<TABLE class = 'clsTable'>"
	response.write "<TR><TD>Error:<BR>" & Err.Description & " " & iNum & "</TD></TR>"
	response.write "</TABLE>"
	response.end
end sub

' BuildSQL - Builds the list of tags from the tag array '
function BuildSQL(whereArray, strWhere)
	if BuildSQL = "" then
		for iArea = 0 to ubound(whereArray)
			for iTag = 0 to ubound(whereArray(iArea))
				if iTag <> 0 then
					if Len(whereArray(iArea)(iTag)) > 4 then
						if strWhere <> "" then
							strWhere = strWhere & " , "
						end if

						strWhere= strWhere & "'" & whereArray(iArea)(iTag) & "'"
					end if
				end if
			next
		next
		BuildSQL = strWhere
	end if
end function

' BuildTable - Builds the HTML table for a specified tag array '
function BuildTable(tableArray, oRecordset, iRound)
	for iArea = 0 to ubound(tableArray)
		response.write "<TR>"
		for iTag = 0 to ubound(tableArray(iArea))
			if iTag = 0 or Len(tableArray(iArea)(iTag)) <= 4 then
				response.write "<TD align='left'>"
				response.write tableArray(iArea)(iTag)
			else
				response.write "<TD align='right'>"
				if (oRecordset("tag") = tableArray(iArea)(iTag)) then
					if oRecordset("RVal") = "0" and oRecordset("status") <> "0" then
						response.write Round(oRecordset("status"), iRound)
					else
						'response.write Round(oRecordset("RVal"), iRound)
						dim num
						num = oRecordset("RVal")
						num = FormatNumber(num,1)
						response.write num
					end if

					oRecordSet.MoveNext
				else
					response.write "Tag not found."
				end if
			end if
			response.write "</TD>"
		next
		response.write "</TR>"
	next
end function

' BuildTable0 - Builds the HTML table for a specified tag array ' (no decimal places)
function BuildTable0(tableArray, oRecordset, iRound)
	for iArea = 0 to ubound(tableArray)
		response.write "<TR>"
		for iTag = 0 to ubound(tableArray(iArea))
			if iTag = 0 or Len(tableArray(iArea)(iTag)) <= 4 then
				response.write "<TD align='center'>"
				response.write tableArray(iArea)(iTag)
			else
				response.write "<TD align='right'>"
				if (oRecordset("tag") = tableArray(iArea)(iTag)) then
					if oRecordset("RVal") = "0" and oRecordset("status") <> "0" then
						if oRecordset("text") = "" then 
						response.write Round(oRecordset("status"), iRound)
						elseif oRecordset("text") = "YES" then 
							response.write "ON"
						elseif oRecordset("text") = "YES" then 
							response.write "OFF"
						else 
						response.write oRecordset("text")
						end if
					else
						'response.write Round(oRecordset("RVal"), iRound)
							dim num
							num = oRecordset("RVal")
'							num = FormatNumber(num,1) then
							num = FormatNumber(num,1)
							response.write num
					end if
					oRecordSet.MoveNext
				else
					response.write "Tag not found."
				'response.write Orecordset("Rval")
				end if
			end if
			response.write "</TD>"
		next
		response.write "</TR>"
	next
end function

' Open the PI ODBC connection '
Set oConnection=Server.CreateObject("ADODB.Connection")
oConnection.Open sPIconn, sPIuser, sPIpwd
if Err.number  <> 0 then
	ErrorHandler 1
end if

' Initialize all tag arrays for Unit 7'
Dim u7
u7 = Array(_
    Array("", "", "", ""), _
    Array("Temperature", "TEMP:01", "32", ""), _
	Array("Pressure", "PSI:514", "100", "") _

    )


' Display the current date and time '
response.write "<TABLE class = 'clsTable'>"
response.write "<TR>"
response.write "<TD>" & Now & "</TD>"
response.write "</TR>"
response.write "</TABLE>"

' Gross Megawatt SNA table


' Build the WHERE clause of the SQL statement with all the tag names '
strWhere = ""
strWhere = BuildSQL(u7, strWhere)
strSQL = "SELECT status, tag, text = DIGSTRING(status), Rval=Value FROM picomp WHERE tag in (" & strWhere & ") AND Time = DATE('*')"

' Execute the SQL statement'
Set oRecordSet = oConnection.Execute(strSQL, nRec)
if Err.number  <> 0 then
	ErrorHandler 2
end if

' Build the 'vib USS' table '
response.write "<HR><TABLE class = 'clsTable'>"
response.write "<TR>"
response.write "<TD><U> Unit 7 </U></TD>"
response.write "</TR>"
response.write "<TR>"
response.write "<TD><U>Descriptions</U></TD>"
response.write "<TD><U> Current Value </U></TD>"
response.write "<TD><U> Target Value </U></TD>"
response.write "<TD><U> Difference </U></TD>"
response.write "</TR>"
BuildTable0 u7, oRecordset, 0
response.write "</TABLE>"


' Build the WHERE clause of the SQL statement with all the tag names '
strWhere = ""
strWhere = BuildSQL(rrgArray, strWhere)
strSQL = "SELECT status, tag, Rval=Value FROM picomp WHERE tag in (" & strWhere & ") AND Time = DATE('*')"


' Close PI connection '
oRecordset.Close
oConnection.Close

Set oRecordset = Nothing
Set oConnection = Nothing

%>
</body>
</html>

Was This Post Helpful? 0
  • +
  • -

#10 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 262
  • View blog
  • Posts: 1,460
  • Joined: 07-April 08

Re: ASP - Arithmetic Operations within Array

Posted 30 January 2013 - 10:21 AM

How have you tried to debug this? have you set a bunch of response writes to see the values in your array/variables?

Also I don't know what you're expecting exactly by putting in the - 32 in your array, but the array is of type Array(Of Array(Of string)) which means that each of the inner arrays is an Array of strings so no subtraction can be done on it. It is immutable which means you can't change it. you can do a REPLACE to replace the text for the tag name with it's actual value then convert it to a double or something of the sort

Try this:

CDBL(REPLACE("TEMP:01","TEMP:01","32")) - 32



ofcourse you'll replace the last number in the REPLACE with what ever value comes out of the database

This post has been edited by rgfirefly24: 30 January 2013 - 10:31 AM

Was This Post Helpful? 0
  • +
  • -

#11 mannakhan10  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 21-May 11

Re: ASP - Arithmetic Operations within Array

Posted 31 January 2013 - 09:13 AM

View Postrgfirefly24, on 30 January 2013 - 10:21 AM, said:

How have you tried to debug this? have you set a bunch of response writes to see the values in your array/variables?

Also I don't know what you're expecting exactly by putting in the - 32 in your array, but the array is of type Array(Of Array(Of string)) which means that each of the inner arrays is an Array of strings so no subtraction can be done on it. It is immutable which means you can't change it. you can do a REPLACE to replace the text for the tag name with it's actual value then convert it to a double or something of the sort

Try this:

CDBL(REPLACE("TEMP:01","TEMP:01","32")) - 32



ofcourse you'll replace the last number in the REPLACE with what ever value comes out of the database


I'm not sure I fully understand.
I cannot change the last number in the REPLACE with any set value. The database server will feed me real time temperature readings that change by the minute.
Also, I've never used a replace function, but I would insert it right below my array if I assume correct?

You make a good point about it being a String. In ASP is there a way to convert a string into an integer?
I've tried cInt(TEMP:01) before the fuction with no luck.

If there was a way to convert that constantly changing value from TEMP:01 into an integer, I could use it in any arithmetic operation.
Was This Post Helpful? 0
  • +
  • -

#12 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1181
  • View blog
  • Posts: 1,673
  • Joined: 24-August 11

Re: ASP - Arithmetic Operations within Array

Posted 31 January 2013 - 10:14 AM

EDIT: Didn't read enough of the previous posts to realize you're using VBScript and not C#. CInt(expression) should work for you. What happens when you use it?

This post has been edited by h4nnib4l: 31 January 2013 - 10:18 AM

Was This Post Helpful? 0
  • +
  • -

#13 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 262
  • View blog
  • Posts: 1,460
  • Joined: 07-April 08

Re: ASP - Arithmetic Operations within Array

Posted 31 January 2013 - 01:13 PM

View Postmannakhan10, on 31 January 2013 - 11:13 AM, said:

View Postrgfirefly24, on 30 January 2013 - 10:21 AM, said:

Try this:

CDBL(REPLACE("TEMP:01","TEMP:01","32")) - 32



ofcourse you'll replace the last number in the REPLACE with what ever value comes out of the database


I'm not sure I fully understand.
I cannot change the last number in the REPLACE with any set value. The database server will feed me real time temperature readings that change by the minute.
Also, I've never used a replace function, but I would insert it right below my array if I assume correct?

You make a good point about it being a String. In ASP is there a way to convert a string into an integer?
I've tried cInt(TEMP:01) before the fuction with no luck.

If there was a way to convert that constantly changing value from TEMP:01 into an integer, I could use it in any arithmetic operation.


You can put anything in place of the last string in the REPLACE function. I just had 32 there because it is what I used in my tests. It was only meant for you to see and look at, I was not giving you the actual answer is it should be plugged into your code; That is for you to do.

Here is another example as if I was using an array and pulling from a database:
' CDBL is the vbscript function for Convert to Double.  CInt is the vbscript function for Convert to int pick what ever it doesn't matter
CDBL(REPLACE(Array(InnerArray(Position)),"FindMe",CStr(oRecordSet("DatabaseField")))) - 32



Now, take that and change it to your code. You would use this line of code where ever you're inserting data into your array from the database.

Now here are links to the functions I've used so you can look them over

CStr
CInt
CDbl
Replace

You can also find references to the above on W3Schools

This post has been edited by rgfirefly24: 31 January 2013 - 01:14 PM

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1