Results 1 to 3 of 3

Thread: Repeating Errors.

Threaded View

  1. #1

    Thread Starter
    Addicted Member DigitalMyth's Avatar
    Join Date
    Nov 2002
    Location
    England..
    Posts
    169

    Repeating Errors.

    I can either get

    Object reference not set to an instance of an object.

    or

    Value cannot be null. Parameter name: Argument 'Array' is Nothing.





    VB Code:
    1. <%@ Page Language="VB" %>
    2. <%@ import Namespace="System.IO" %>
    3. <%@ import Namespace="System.Data.SqlClient" %>
    4. <script runat="server">
    5.  
    6.     Dim Directorys() as String
    7.     Dim Files as New ArrayList
    8.  
    9.     Sub Page_Load
    10.  
    11.  
    12.         If User.Identity.ISAuthenticated = "false" then
    13.                     If not Request.QueryString("act") = "login" then Response.Redirect( scriptname & "?act=login")
    14.         End if
    15.  
    16.     If Request.QueryString("act") = "explore" then LoadDirs(gethome(Request.ServerVariables("AUTH_USER")))
    17.     If Request.QueryString("act") = "explore" then LoadFiles(gethome(Request.ServerVariables("AUTH_USER")))
    18.  
    19.     End Sub
    20.  
    21.  
    22.     Function Authenticated(username As String, password As String) As Boolean
    23.             Dim dbconnection As Sqlconnection, getuserID as Sqlcommand, userID as SqlDataReader
    24.                 dbconnection = New SqlConnection( "Server=;uid=commline;pwd=;database=" )
    25.                 dbconnection.open()
    26.                     getuserID = New sqlcommand( "Select u_basedir FROM Userfile WHERE u_username = '" & Microsoft.Visualbasic.Lcase(txtuser.text) & "' AND u_password = '" & Microsoft.Visualbasic.Lcase(txtpass.text) & "'", dbconnection )
    27.                     userID = getuserID.ExecuteReader()    
    28.                         If userID.HasRows then
    29.                             While userID.Read()
    30.                                     Return True
    31.                             End While
    32.                         Else
    33.                                     Return False    
    34.                         End if
    35.                 userID.close()
    36.                 dbconnection.close()   
    37.        End Function
    38.  
    39.        Sub TryLogin(sender As Object, e As EventArgs)
    40.             If Authenticated(txtuser.text,txtpass.text) then
    41.    
    42.             Dim ticket as New FormsAuthenticationTicket( txtuser.text, chkrem.checked, 50 )
    43.             Dim encTicket As String = FormsAuthentication.Encrypt(ticket)
    44.             Dim cookie as New HttpCookie(FormsAuthentication.FormsCookieName,encticket)
    45.             Response.Cookies.Add(cookie)
    46.                 response.redirect(scriptname & "?act=summary")
    47.             else    
    48.             Logerror.Visible = true
    49.         End if
    50.        End Sub
    51.  
    52.        Function Scriptname as string
    53.         Dim strURL
    54.         Dim aryURL
    55.         strURL = Request.ServerVariables("SCRIPT_NAME")
    56.         aryURL = Split(strURL, "/", -1, 1)
    57.         scriptname = (aryURL(ubound(aryURL)))
    58.        End Function
    59.  
    60.  
    61.        Function LoadDirs(strcurrentdir as string)
    62.         Dim Directorys() as String
    63.                 Dim i as Integer
    64.                 Directorys = Directory.GetDirectories(strCurrentDir)
    65.                 For i = 0 to ubound(Directorys)
    66.                      Directorys(i) = right(Directorys(i), len(Directorys(i)) - len(strcurrentdir) - 1)
    67.                 next i
    68.        End Function
    69.  
    70.        Function LoadFiles(strCurrentDir as string)
    71.  
    72.         Dim i as integer
    73.         Dim filesstore as Array
    74.         Dim runningfile as FileInfo
    75.                 Dim dir as DirectoryInfo        
    76.                 dir = new DirectoryInfo(strCurrentDir)      
    77.                 filesstore = dir.GetFiles()
    78.         For each runningfile in filesstore
    79.             files.add(runningfile.name)
    80.                 next
    81.         files.TrimToSize()
    82.        End Function
    83.  
    84.  
    85.        Function GetHome(Username as string) as string            
    86.             Dim dbconnection As Sqlconnection, getuserID as Sqlcommand, userID as SqlDataReader
    87.                 dbconnection = New SqlConnection( "Server=;uid=commline;pwd=;database=" )
    88.                 dbconnection.open()
    89.                     getuserID = New sqlcommand( "Select u_basedir FROM Userfile WHERE u_username = '" & Microsoft.Visualbasic.Lcase(username) & "'", dbconnection )
    90.                     userID = getuserID.ExecuteReader()
    91.                     If userID.HasRows then
    92.                     While userID.Read()
    93.                     Return userid( "u_basedir" )                
    94.                     End While  
    95.                     End if
    96.                 userID.close()
    97.                 dbconnection.close()
    98.        End Function
    99.  
    100. </script>
    101.  
    102. <html>
    103. <head>
    104. <STYLE type=text/css>
    105.  BODY {background-image: url(img\back_logo.jpg);
    106.        background-repeat: no-repeat;
    107.        background-position: bottom right
    108.        scrollbar-3dlight-color:#f3f3f3;
    109.        scrollbar-arrow-color:#000000;
    110.        scrollbar-base-color:#cccccc;
    111.        scrollbar-track-color:#f3f3f3;
    112.        scrollbar-darkshadow-color:#f3f3f3;
    113.        scrollbar-highlight-color:#f3f3f3;
    114. </STYLE>
    115. </head>
    116. <body>
    117.  
    118. <% Select Case Request.QueryString("act") %>
    119.  
    120. <% Case "login" %>
    121.  
    122. <form runat="server"><p><font face="Trebuchet MS" size="5"><strong>CLIENT LOGIN</strong></font></p><p><font size="2"><font face="Trebuchet MS">Username:</font><br /></font><asp:TextBox id="txtuser" runat="server"></asp:TextBox></p><p><font face="Trebuchet MS" size="2">Password:</font><br /><asp:TextBox id="txtpass" runat="server" TextMode="Password"></asp:TextBox></p><p><asp:CheckBox id="chkrem" runat="server" Text="Remember me with Cookies?"></asp:CheckBox><br /><br />
    123. <aspanel id="logerror" runat="server" Visible="False" font-names="Trebuchet MS" font-size="X-Small" forecolor="Red" font-bold="True">
    124. Your Password or Username is incorrect.
    125. </aspanel>
    126. </p><p><asp:Button id="login" onclick="trylogin" runat="server" Text="Login" Width="72px"></asp:Button></p></form>
    127.  
    128.  
    129.     <% Case "summary" %>
    130.  
    131. <p><font face="MS Sans Serif" style="font-size: 11pt"><a href="?act=explore">Explore your files in your area</a></p><br> Script: <% Response.Write(ScriptName) %> <br> Version: BETA 0.1 <br> <br> Copyright © Script: <b> <% Response.Write(ScriptName) %> </b> Andrew Simpson 2004-2005
    132.  
    133.     <% Case "explore"
    134.      Dim Temp as String
    135.      Dim m as Integer %>
    136.  
    137.     <% For m = 0 to ubound(Directorys)
    138.  
    139.     response.write(ubound(directorys))
    140.    
    141.     next m %>
    142.  
    143.     <% Case Else
    144.  Response.Redirect( scriptname & "?act=login") %>
    145.  
    146.  
    147.     <% End Select %>
    148. </body>
    149. </html>


    <b>Now i have a feeling that the Directorys arrays and the Files arrays are wiped when it's jumps out of the script section at the top of the file but i'm not sure. </b>

    Can Anyone help??
    Last edited by DigitalMyth; May 28th, 2004 at 06:43 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width