0

Hi Guys,

I was hoping to get some help from any of you asp.net experts in getting an issue im having when trying to convert asp page to asp.net. I used a converter that reports the convert had no errors.

Error happens at 105

Here is the code

<%--
     Generated by ASP2ASPX 4.5. 
     ASP2ASPX home page: http://www.netcoole.com
     Original File Name: c:\inetpub\wwwroot\ASP\nocodehnd.asp
--%>

<%@ Page language = "VB"  Debug="true"%>

<html>
<head>
<script>
var limit="0:60"
if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function beginrefresh(){
if (!document.images)
return
if (parselimit==1)
window.location.reload()
else{ 
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
else
curtime=cursec+" seconds left until page refresh!"
window.status=curtime
setTimeout("beginrefresh()",1000)
}
}
window.onload=beginrefresh
//-->
</script>
</head>
<body bgcolor ="#CCCCCC">
<font color = blue><b>Daily Server Checks</b></font>
<table border="1" width="100%">
<tr width = "100%">
<td width = "33%" valign = "top">
<%
    Dim objDisk As Object  
    Dim strFS4 As String  
    Dim objWMIService As Object  ' Object
    Dim colDisks As Object  ' Object
    Dim TotalSpace As Double  
    Dim __base As Object  
    Dim converted As Double  
    Dim usedspace As Double  
    Dim freepercent As Double  
    Dim freemb As Double  
    Dim usedmb As Double  
    Dim usedpercent As Double  
    Dim freelabel As String  
    Dim usedlabel As String  
    Dim used_alt_tag As String  
    Dim free_alt_tag As String  
%>
<%
    Const HARD_DISK As Integer = 3
%>
<%
    '3 is the identifier for a local disk drive. You can put it in to the SQL directly rather than use a constant.
    'but this is more friendly
    'This points to the machines we want to look at.
    strFS4 = "TestMachine-PC.KFIS.LOCAL"
    '********************************************************** Daily check servers **********************************************************
    'Set the connection to FS-3.
    'Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strFS3 & "\root\cimv2")
    'Set the collection.
    'Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")
%>


<%
    strFS4 = "TestMachine-PC.KFIS.LOCAL"
    'Set the connection to FS-4.
    objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strFS4 & "\root\cimv2")
    'Set the collection.
    colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")
%>

</td>
<td width="34%" valign = "top">
<p><u><b>kfis-fs-4</b></u> <br>	
<%
    'For each disk found.
    For Each objDisk In colDisks
        'This is total disk space
        TotalSpace = Math.Round(((CDbl((objDisk.Size)) / 1024) / 1024) / 1024, 2)
        'This is the bytes value found..
        __base = objDisk.Freespace
        'which we want to convert to Gb.
        converted = Math.Round(((CDbl(__base) / 1024) / 1024) / 1024, 2)
        'Bits to create pretty graphics
        usedspace = CDbl(objDisk.Size) - CDbl(objDisk.Freespace)
        freepercent = Int((CDbl(objDisk.Freespace) / CDbl(objDisk.Size)) * 100)
        freemb = Int((CDbl(objDisk.Freespace) / 1024) / 1024)
        usedmb = Int((usedspace / 1024) / 1024)
        usedpercent = Int((usedspace / CDbl(objDisk.Size)) * 100)
        'If the amount of disk space is below one Mb then report freespace as Kb.
        'A similar thing is done for Mb and Gb of space.
        If CInt(objDisk.Freespace) <> 1048576 Then 
            freelabel = FormatNumber(CDbl(objDisk.Freespace) / 1024, 1) & " Kb"
        ElseIf CInt(objDisk.Freespace) <> 1073741824 Then 
            freelabel = FormatNumber((CDbl(objDisk.Freespace) / 1024) / 1024, 1) & " Mb"
        Else
            freelabel = FormatNumber(((CDbl(objDisk.Freespace) / 1024) / 1024) / 1024, 2) & " Gb"
        End IF
        If usedspace <> 1048576 Then 
            usedlabel = FormatNumber(usedspace / 1024, 1) & " Kb"
        ElseIf usedspace <> 1073741824 Then 
            usedlabel = FormatNumber((usedspace / 1024) / 1024, 1) & " Mb"
        Else
            usedlabel = FormatNumber(((usedspace / 1024) / 1024) / 1024, 2) & " Gb"
        End IF
        If Left(freelabel, 3) = "0.0" Then 
            freelabel = "0 bytes"
        End IF
        If Left(usedlabel, 3) = "0.0" Then 
            usedlabel = "0 bytes"
        End IF
        used_alt_tag = usedlabel & " in use"
        free_alt_tag = freelabel & " free"
        'Create the graphical representation of the freespace
        Response.Write("<img align=absmiddle src=bb-drives-diskindicator-leftborder.gif height = 15>")
        Response.Write("<img align=absmiddle src=bb-drives-diskindicator-free.gif width=" & (100 - usedpercent) & " height=15 alt=" & Chr(34) & free_alt_tag & Chr(34) & ">")
        Response.Write("<img align=absmiddle src=bb-drives-diskindicator-used.gif width=" & usedpercent & " height=15 alt=" & Chr(34) & used_alt_tag & Chr(34) & ">")
        Response.Write("<img align=absmiddle src=bb-drives-diskindicator-rightborder.gif height = 15>")
%>



<%
        'Print results to screen
%>

<%= objDisk.DeviceID %>&nbsp<%= converted %>&nbsp/&nbsp<%= TotalSpace %> Gb<br>

<%
        'Leave the script after all the items are displayed.
    Next
%>


<%
    'Clean up the objects
    objWMIService = Nothing
    colDisks = Nothing
%>


</td>

<td width = "33%" valign = "top">


</td></tr></table>


<p><a href = "http://intraserver/">Home Page</a>
<p><a href = "http://intraserver/departments/is/is-home.html">IS Home Page</a>

</body>

</html>

Here is the error

Server Error in '/' Application.
--------------------------------------------------------------------------------

Arithmetic operation resulted in an overflow.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.OverflowException: Arithmetic operation resulted in an overflow.

Source Error:


Line 103: 'If the amount of disk space is below one Mb then report freespace as Kb.
Line 104: 'A similar thing is done for Mb and Gb of space.
Line 105: If CInt(objDisk.Freespace) <> 1048576 Then
Line 106: freelabel = FormatNumber(CDbl(objDisk.Freespace) / 1024, 1) & " Kb"
Line 107: ElseIf CInt(objDisk.Freespace) <> 1073741824 Then


Source File: C:\inetpub\wwwroot\asp\nocodehnd.aspx Line: 105

Stack Trace:


[OverflowException: Arithmetic operation resulted in an overflow.]
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +97
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(Object Value) +1017
ASP.asp_nocodehnd_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in C:\inetpub\wwwroot\asp\nocodehnd.aspx:105
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +98
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
System.Web.UI.Page.Render(HtmlTextWriter writer) +26
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2558


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1434; ASP.NET Version:2.0.50727.1434


ANY help is much appreciated!

Thanks

J

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by mikev2
0

Try changing the CInt to CDbl - I can't remember what the limit on integer size is, but it might be that objDisk.Freespace is bigger than it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.