Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4084096
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:23:47+00:00 2026-05-20T18:23:47+00:00

When a student logs in I load a dashboard for them giving them an

  • 0

When a student logs in I load a dashboard for them giving them an idea of where they are at in the housing reservation process. No matter what I do though it always seems to trigger the Else condition, even though I have an Exit For in the For..Next loop. Here is the code in question:

Public Sub Initialize_Dashboard()
    Dim term As String = CStr(Session("term"))
    Dim year As String = CStr(Session("year"))
    Dim people_code_id As String = CStr(Session("people_code_id"))
    Dim class_level As String = CStr(Session("class"))
    ' %%%%%% Show the resident's name and whether they have a room. %%%%%%
    Dim dbroom As New pbu_housingEntities
    Dim queryStudent = From p In dbroom.Residents _
                       Where p.people_code_id = people_code_id _
                       Join b In dbroom.Buildings On p.building Equals b.id _
                       Join r In dbroom.Rooms On p.room Equals r.id
                       Select p, b, r

    lblName.Text = CStr(Session("name"))
    If queryStudent.Count.Equals(0) Then
        lblRegistered.Text = "We do not have you currently registered for campus housing."
    Else
        lblRegistered.Text = "You are currently registered for " & queryStudent.First.b.building_name & " " & queryStudent.First.r.room1 & "."
    End If

    ' Initiate variables to check for class settings.
    Dim dbConfig As New pbu_housingEntities
    Dim whatdatest = From p In dbConfig.Configs
    Dim whatdatee = From p In dbConfig.Configs

    ' Add in a check for contract signatures.
    Dim dbContracts As New pbu_housingEntities
    Dim clcexists = From p In dbContracts.Signatures _
                    Where p.StudentID = people_code_id _
                    And p.ContractType = "clc" _
                    Order By p.ID Descending _
                    Select p
    Dim rhcexists = From p In dbContracts.Signatures _
                    Where p.StudentID = people_code_id _
                    And p.ContractType = "rhc" _
                    Order By p.ID Descending _
                    Select p
    ' Shows or hides the buttons for contracts based on whether signatures exist.
    Dim clcfirst = clcexists.FirstOrDefault()
    Dim rhcfirst = rhcexists.FirstOrDefault()
    If clcfirst Is Nothing Then
        pnlSignCLC.Visible = True
    Else
        pnlSignCLC.Visible = False
    End If
    If rhcfirst Is Nothing Then
        pnlSignRHC.Visible = True
    Else
        pnlSignRHC.Visible = False
    End If

    ' Determine if the student is eligible to register for class.
    Dim classes() As String = {"FR%", "SO", "JR", "SR", "SR5"}
    For Each value As String In classes
        ' Pull in the dates the student should be able to register for this class, compare them to the current date.
        Dim current_value = value
        If class_level = current_value Then
            Response.Write("hello")
            whatdatest = From p In dbConfig.Configs _
                         Where p.Description = current_value + "OD" _
                         Select p

            whatdatee = From p In dbConfig.Configs _
                        Where p.Description = current_value + "CD" _
                        Select p

            ' If the current date is within their registration period...
            If Date.Now >= whatdatest.First.dateValue And Date.Now <= whatdatee.First.dateValue Then
                Dim person_name As String = CStr(Session("person_name")) ' Must stay here or will conflict.
                Dim hasroom = From p In dbConfig.Residents _
                              Where p.person_name = person_name _
                              Where p.semester = term _
                              Where p.year = year _
                              Select p
                ' If they have signed their contracts, lets let them register for a room.
                If hasroom.Count.Equals(0) AndAlso clcfirst IsNot Nothing AndAlso rhcfirst IsNot Nothing Then
                    pnlBegin.Visible = True
                    btnBegin.Enabled = True

                    ' If they are already registered for a room, let them delete their reservation.
                ElseIf clcfirst IsNot Nothing AndAlso rhcfirst IsNot Nothing Then
                    pnlDelete.Visible = True
                    btnDelete.Enabled = True
                Else

                    ' In any other situation, we don't need to do anything.
                    ' There really shouldn't be any other situation.

                End If
                ' What to do if the current date is not within the room reservation window.
                Exit For
            Else
                Dim class_name As String
                Select Case current_value
                    Case "FR%"
                        class_name = "Freshman"
                    Case "SO"
                        class_name = "Sophmore"
                    Case "JR"
                        class_name = "Junior"
                    Case "SR"
                        class_name = "Senior"
                    Case "SR5"
                        class_name = "Fifth year Senior"
                End Select
                lblError.Text = "You are currently a " & current_value & ". You will be eligible to reserve a room between" _
                    & whatdatest.First.dateValue & " and " & whatdatee.First.dateValue & ". Please come back during those dates. Thanks!"
            End If
            Exit For
        Else
            ' What to do if the user isn't assigned a class level at all!
            lblError.Text = "Oops...Something might be wrong with our records. We don't have you registered for classes. Please contact Dave Mackey, x4543."
        End If
    Next

Here is the code after I moved the last else clause into a separate If..Then:

 Public Sub Initialize_Dashboard()
    Dim term As String = CStr(Session("term"))
    Dim year As String = CStr(Session("year"))
    Dim people_code_id As String = CStr(Session("people_code_id"))
    Dim class_level As String = CStr(Session("class"))
    ' %%%%%% Show the resident's name and whether they have a room. %%%%%%
    Dim dbroom As New pbu_housingEntities
    Dim queryStudent = From p In dbroom.Residents _
                       Where p.people_code_id = people_code_id _
                       Join b In dbroom.Buildings On p.building Equals b.id _
                       Join r In dbroom.Rooms On p.room Equals r.id
                       Select p, b, r

    lblName.Text = CStr(Session("name"))
    If queryStudent.Count.Equals(0) Then
        lblRegistered.Text = "We do not have you currently registered for campus housing."
    Else
        lblRegistered.Text = "You are currently registered for " & queryStudent.First.b.building_name & " " & queryStudent.First.r.room1 & "."
    End If

    ' Initiate variables to check for class settings.
    Dim dbConfig As New pbu_housingEntities
    Dim whatdatest = From p In dbConfig.Configs
    Dim whatdatee = From p In dbConfig.Configs

    ' Add in a check for contract signatures.
    Dim dbContracts As New pbu_housingEntities
    Dim clcexists = From p In dbContracts.Signatures _
                    Where p.StudentID = people_code_id _
                    And p.ContractType = "clc" _
                    Order By p.ID Descending _
                    Select p
    Dim rhcexists = From p In dbContracts.Signatures _
                    Where p.StudentID = people_code_id _
                    And p.ContractType = "rhc" _
                    Order By p.ID Descending _
                    Select p
    ' Shows or hides the buttons for contracts based on whether signatures exist.
    Dim clcfirst = clcexists.FirstOrDefault()
    Dim rhcfirst = rhcexists.FirstOrDefault()
    If clcfirst Is Nothing Then
        pnlSignCLC.Visible = True
    Else
        pnlSignCLC.Visible = False
    End If
    If rhcfirst Is Nothing Then
        pnlSignRHC.Visible = True
    Else
        pnlSignRHC.Visible = False
    End If

    ' Determine if the student is eligible to register for class.
    Dim classes() As String = {"FR%", "SO", "JR", "SR", "SR5"}
    Dim flag As String = "N"
    For Each value As String In classes
        ' Pull in the dates the student should be able to register for this class, compare them to the current date.
        Dim current_value = value
        If class_level = current_value Then
            flag = "Y"
            Response.Write("hello")
            whatdatest = From p In dbConfig.Configs _
                         Where p.Description = current_value + "OD" _
                         Select p

            whatdatee = From p In dbConfig.Configs _
                        Where p.Description = current_value + "CD" _
                        Select p

            ' If the current date is within their registration period...
            If Date.Now >= whatdatest.First.dateValue And Date.Now <= whatdatee.First.dateValue Then
                Dim person_name As String = CStr(Session("person_name")) ' Must stay here or will conflict.
                Dim hasroom = From p In dbConfig.Residents _
                              Where p.person_name = person_name _
                              Where p.semester = term _
                              Where p.year = year _
                              Select p
                ' If they have signed their contracts, lets let them register for a room.
                If hasroom.Count.Equals(0) AndAlso clcfirst IsNot Nothing AndAlso rhcfirst IsNot Nothing Then
                    pnlBegin.Visible = True
                    btnBegin.Enabled = True

                    ' If they are already registered for a room, let them delete their reservation.
                ElseIf clcfirst IsNot Nothing AndAlso rhcfirst IsNot Nothing Then
                    pnlDelete.Visible = True
                    btnDelete.Enabled = True
                Else

                    ' In any other situation, we don't need to do anything.
                    ' There really shouldn't be any other situation.

                End If
                ' What to do if the current date is not within the room reservation window.
                Exit For
            Else
                Dim class_name As String
                Select Case current_value
                    Case "FR%"
                        class_name = "Freshman"
                    Case "SO"
                        class_name = "Sophmore"
                    Case "JR"
                        class_name = "Junior"
                    Case "SR"
                        class_name = "Senior"
                    Case "SR5"
                        class_name = "Fifth year Senior"
                End Select
                lblError.Text = "You are currently a " & current_value & ". You will be eligible to reserve a room between" _
                    & whatdatest.First.dateValue & " and " & whatdatee.First.dateValue & ". Please come back during those dates. Thanks!"
            End If
            Exit For
        Else

        End If
    Next
    If flag = "N" Then
        ' What to do if the user isn't assigned a class level at all!
        lblError.Text = "Oops...Something might be wrong with our records. We don't have you registered for classes. Please contact Dave Mackey, x4543."
    End If
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:23:47+00:00Added an answer on May 20, 2026 at 6:23 pm

    I think you need to remove this last Else statement

    Else
                ' What to do if the user isn't assigned a class level at all!
                lblError.Text = "Oops...Something might be wrong with our records. We don't have you registered for classes. Please contact Dave Mackey, x4543."
    

    Otherwise you will never get through all the options.

    You need to set a “found” flag to false before the loop, set found to true inside the loop if there is a match, then after the loop set the error if found is still false.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a student and I have a lot of free time on this vacation
I work with my student group on a project : We have some problems
I'm a student looking for resources which can help me further understand how to
I currently am a student worker at a medium sized university. i work for
I an a graduate student of nuclear physics currently working on a data analysis
I am a graduate student of physics and I am working on writing some
I'm a student learning PHP. I basically make the stuff work, but never wondered
I have student.xml file and am parsing this file using SAX Parser and now
I have two student objects. class Student{ int physics; int english; int chemistry; }
I'm a beginning student in CS, and my classes are mostly in Java. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.