1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

(Practically) Infinite Loop

Discussion in 'C#' started by nickcherryjiggz, Apr 15, 2006.

  1. #1
    For a school project, I'm currently working on a ticket sales website to service a baseball team. I apologize if I'm being an idiot and making some incredibly obvious blunder, but I've looked at this code for the past 30 minutes and I'm baffled. All the page is supposed to do (at the moment) is run a query on the database, then go through the results until the number of seats together is equal to the number of seats desired (if a customer wants a quantity of 3 tickets, the page will search until 3 adjacent seats are returned). I have the loop set to run until either the end of the file has been reached or the search has been satisfied and seatstogether is equal to quantity. For some reason, though, the loop always runs to the end of the file, even if seatstogether is greater than quantity. I have the page set to display the status of each variable for each iteration and it is quite clear that seatstogether > quantity, but even when run in the if statement embedded in the loop, it returns false. Stranger yet, when I set quantity to a constant, say 3, before the loop, it works perfectly. I just have no clue what is wrong at this point. Any help is greatly appreciated. Here's the website...just choose a quantity and search for tickets.
    http://ist210.3c.ist.psu.edu/teams/team13/tickets.asp?GameNum=48
    here is the significant code...


    Dim GameNum, Quantity, SectionAbb
    GameNum = Request.Form("gamenum")
    Quantity = Request.Form("quantity")
    SectionAbb = Request.Form("section")
    Dim SectionMin, SectionMax, SeatsTogether, TempSection(15), TempRow(15), TempSeat(15), TempPrice(15)
    SeatsTogether = 1
    SEMrush
    If SectionAbb = "DC" Then
    SectionMin = 101
    SectionMax = 109
    ElseIf SectionAbb = "FB" Then
    SectionMin = 201
    SectionMax = 204
    ElseIf SectionAbb = "BB" Then
    SectionMin = 301
    SectionMax = 305
    ElseIf SectionAbb = "OR" Then
    SectionMin = 401
    SectionMax = 402
    End If

    objRS.Open "SELECT S.Section, S.Row, S.Seat, S.Price FROM Games G JOIN Tickets T ON G.Game_Num = T.Game_Num JOIN Seats S ON T.Seat_Num = S.Seat_Num WHERE G.Game_Num = " & GameNum & " AND S.Section >= " & SectionMin & " AND S.Section <= " & SectionMax & "AND T.Sold = 0 ORDER BY S.Row, S.Section, S.Seat", objConn

    Do While SeatsTogether <= Quantity And Not objRS.EOF
    TempSection(SeatsTogether) = objRS("Section")
    TempRow(SeatsTogether) = objRS("Row")
    TempSeat(SeatsTogether) = objRS("Seat")
    TempPrice(SeatsTogether) = objRS("Price")


    Response.Write "SeatsTogether : " & SeatsTogether & "<BR>"
    Response.Write "Quantity : " & Quantity & "<BR>"
    If SeatsTogether <= Quantity Then
    Response.Write SeatsTogether & " <= " & Quantity & "<BR>"
    Else
    Response.Write SeatsTogether & " > " & Quantity & "<BR>"
    End If
    Response.Write "TempSection(" & SeatsTogether & ") : " & TempSection(SeatsTogether) & "<BR>"
    Response.Write "TempRow(" & SeatsTogether & ") : " & TempRow(SeatsTogether) & "<BR>"
    Response.Write "TempSeat(" & SeatsTogether & ") : " & TempSeat(SeatsTogether) & "<BR>"
    Response.Write "------------------------------------<BR>"


    If SeatsTogether = 1 Then
    SeatsTogether = SeatsTogether + 1
    ElseIf TempSection(SeatsTogether) = TempSection(SeatsTogether - 1) And TempRow(SeatsTogether) = TempRow(SeatsTogether - 1) And TempSeat(SeatsTogether) = 1 + TempSeat(SeatsTogether - 1) Then
    SeatsTogether = SeatsTogether + 1
    Else
    SeatsTogether = 1
    End If

    objRS.MoveNext
    Loop
     
    nickcherryjiggz, Apr 15, 2006 IP
    SEMrush
  2. DangerMouse

    DangerMouse Peon

    Messages:
    275
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try using the CInt function on your int variables:

    ...If CInt(SeatsTogether) <= CInt(Quantity) Then...
    Code (markup):
    Good luck!
     
    DangerMouse, Apr 19, 2006 IP