Solved

convert asp with vbscript subroutine to asp.net

Posted on 2013-10-30
2
609 Views
Last Modified: 2013-10-31
I have a asp page with vbscript subroutine in the page, it display a graphic bar chart.  I would like convert this page to asp.net(vb.net) page, but I have problem, I moved the asp page to aspx, it gave me lots of errors, because the vbscript subroutine is combined with asp code altogether.  Below is my asp page, how to convert to .net?  Hope someone can give me some help.
<% 
Dim objConn, objRS, strSQL, Sum, objSum, strMonth, strYear, objstrMonth, objstrYear
Set objConn=Server.CreateObject("ADODB.Connection")
objConn.Open UserConnString
%>

<%
Set objRS=Server.CreateObject("ADODB.Recordset")
strsql="select DatePart(mm, task_dateadded) as strMonth, cast(DatePart(yyyy, task_dateadded) as varchar(4)) as strYear, count (task_code) as Sum from task group by DatePart(mm,task_dateadded), cast(DatePart(yyyy,task_dateadded) as varchar(4)) order by strYear desc, strMonth desc"


objRS.open strsql, objConn

Set objSum     =  objRS("Sum")
Set objstrMonth  =  objRS("strMonth")
Set objstrYear   =  objRS("strYear")

%>

<HTML>
<HEAD>
<title>Graph</title>
</HEAD>
<BODY>


<%sub displayverticalgraph(strtitle,strytitle,strxtitle,avalues,alabels)

const GRAPH_HEIGHT 	= 300 	 		
const GRAPH_WIDTH 	= 400   		
const GRAPH_SPACING 	= 0	
const GRAPH_BORDER 	= 0	 		
const GRAPH_BARS 	= 2     		
const USELOWVALUE 	= FALSE 		
const SHOWLABELS 	= TRUE 		
const L_LABEL_SEPARATOR = "|"			
const R_LABEL_SEPARATOR = "|"			
const LABELSIZE 	= -4			
const GRAPHBORDERSIZE 	= 1
const INTIMGBORDER 	= 1  	 		
Const ALT_TEXT		= 4			
						


agraph_bars = array("dark_green","red","gold","blue","pink","light_blue","light_gold","orange","green","purple")


intmax = 0


for i = 0 to ubound(avalues)
if  cint(intmax) < cint(avalues(i)) then  intmax = cint(avalues(i)) 
next
if uselowvalue then 
intmin = avalues(0)
for i = 0 to ubound(avalues)
if  cint(intmin) > cint(avalues(i)) then  intmin = cint(avalues(i)) 
next
end if

graphmultiplier = round(graph_height-100/intmax)

imgwidth = round(300/(ubound(avalues)+1))
if imgwidth > 16 then imgwidth = 16 


%>

<table border =<%=GRAPH_BORDER%> width:100% height=<%=graph_height%>>

  <tr>
    <td rowspan=3 valign="middle"><font face="Arial, Helvetica, sans-serif" size="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=strytitle%></font></td>
    <td colspan=<%=ubound(avalues)+2%> height=50 align="center">
    <strong><font face="Verdana, Arial, Helvetica, sans-serif" size="3" color="#990000"><%=strtitle%></font></strong></td>
  </tr>
	<% count = 0%>
  <tr>
  <td>
	    <table border=<%=GRAPH_BORDER%> cellpadding = 0 cellspacing = <%=graph_spacing%>>
		<tr>
	    <tr>
	     
	     <TD valign="baseline" cellpadding = "0" cellspacing="0">
		  <table border=<%=GRAPH_BORDER%> height="<%=graphmultiplier+8%>" cellpadding = "0" cellspacing="0" align="right">
	         <tr>
			 
	<td height="50%" valign="top" align="right"><font face="Arial, Helvetica, sans-serif" size="-1"><%=intmax%></font></td>
	</tr>
	<tr>
	<td height="50%" valign="bottom" align="right">
	        
		 <%if uselowvalue then
	             response.write cstr(intmin)
		   else
		     response.write "<font face='Arial, Helvetica, sans-serif' size='-1'>0</font>"
		   end if
		  %>
		 </td>
	         </tr>
	      </table>
	     </td>
	     <td valign="baseline" align="right"><img src="../images/yaxis.gif" height="300" align="absbottom">
	     </td>
             
             <%
         
	     for i = 0 to ubound(avalues)
	      strgraph = agraph_bars(count)
	       	if alt_text = 1 then 
		    stralt = alabels(i)
		  elseif alt_text = 2 then 
		    stralt = avalues(i)
		  elseif alt_text = 3 then 
		    stralt = alabels(i) &" - "  &avalues(i)
		  elseif alt_text = 4 then   
		    stralt = round(avalues(i) /intmax  *100,2) &"%"
		 end if     
	        
	        if uselowvalue then  %>
                  <td valign="bottom" align="center">
	          <img src="../images/<%=strgraph%>.gif" height="<%=round((avalues(i)-intmin)/intmax*graphmultiplier,0)%>" width="<%=imgwidth%>" alt="<%=strAlt%>" border="<%=intimgborder%>"></td>
	       <%else%>
	          <td valign="bottom" align="center">
	          <img src="../images/<%=strgraph%>.gif" height="<%=round(avalues(i)/intmax*graphmultiplier,0)%>" width="<%=imgwidth %>" alt="<%=strAlt%>" border="<%=intimgborder%>"></td>
	       <%end if 
		
	        if count = graph_bars-1 then 
	          count = 0 
	        else
	          count = count + 1
	        end if		
	      next  
	      
	      
		  	 response.write "<td width='50'>&nbsp;</td></tr><tr><td width=8></td><td></td><td colspan=" &(ubound(avalues)+1) &" valign='top'>" _
			 &"<img src='../images/xaxis.gif' width='100%' height='1' align='align='left'></td></tr>"
			 
			 
			 response.write "<tr><td width=8><font face='Arial, Helvetica, sans-serif' size='-4'><b>Task Opened</font></b></td><td>&nbsp;</td>"
			 for i=0 to ubound(avalues)
			 
			 response.write"<td align='center'><font face='Arial, Helvetica, sans-serif' size='-4'>"&avalues(i)&"</font></td>"
			 next
			 response.write"</tr>"
			 
			 
	         if showlabels then %>
	         <tr><td width=8 height=1><font face="Arial, Helvetica, sans-serif" size="-4"><b>Month</b></font></td><td>&nbsp;</td>
	            <%for i = 0 to ubound(avalues)%>
	               <td valign="bottom" width=<%=imgwidth%> >
				   <font size=
	               <%=labelsize &">" &l_label_separator &alabels(i) &r_label_separator %></font></td>
	            <%next%>
	         </tr>
	     <%end if%>
	
		 
    	<tr><td colspan=<%=ubound(avalues)+3%> height=50 align="center"><font face="Arial, Helvetica, sans-serif" size="-1"><%=strxtitle%></font></td>
    	</tr>
	</table>
	</td>
	</tr>
	<tr>
	<td></td></tr>
	</table>

<%end sub %>

<%

Dim aMonthValues()
Dim aMonthNames() 
Dim Month() 
Dim Year() 


i = 0
Do While Not objRS.EOF
    i = i + 1
    objRS.MoveNext
Loop
i=i-1
objRS.MoveFirst

ReDim preserve aMonthValues(i)
Redim preserve aMonthNames(i)
Redim preserve Month(i)
Redim preserve Year(i)


x=0
Do Until objRS.EOF
aMonthValues(x)=objRS("Sum")
Month(x)=objRS("strMonth")
Year(x)=objRS("strYear")
aMonthNames(x)=Month(x) &"/" &Year(x)
objRS.MoveNext
x=x+1
Loop


displayverticalgraph "Monthly Report","<img src='axis.gif'>","Month",aMonthValues,aMonthNames 
%>

</TR>
</TABLE>
<%
objRS.close
set objRS=nothing

objConn.close
set objConn=nothing
%>

</BODY>
</HTML>

Open in new window

0
Comment
Question by:5281
2 Comments
 
LVL 28

Accepted Solution

by:
sybe earned 500 total points
ID: 39613476
Why do you want to convert this? If it works, then let it be.

If you really need in in .Net, then best is to rewrite this from scratch.

Lastly:
I see some quick things that won't work in vb.net:

- you can not mix html and script in a functionj in .Net as you could in classic asp. But you can have a function that creates and returns a HTML string, or you could use an <asp:Repeater>

- Some stuff is not or not directly supported in vb.net. Like ADODB.RecordSet, it can be supported in .Net, but asp.net has its own classes which are better fit. Also the function "cint()" is non-existing in vb.Net.

- The code isn't very well written. Who counts records in a recordset by looping through all records?

- Please use some css in stead of the <font> tag
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get id from json Data with NewtonSoft 3 34
SSL https .net web site force redirect 3 38
Capture logon name 13 48
VB 2005 Tooltips on Form Load Event 15 16
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now