none
Coding Help RRS feed

  • Question

  • I am trying to create a program that uses a CSV to check if a range of seats are booked and then displays all the seats that can be chosen with a maximum of 6 seats. If the CSV contains an X the seat is booked and an O means it is free as shown in the screenshot. But the code I create can only checks the data in the first seat and will skip seats to the last in the group. This code is given below:

    Input:
    TextWindow.Clear()
    FilePath = Program.Directory + "/Film.csv" 
    TextWindow.WriteLine("Enter the row you would like to book (A to E)")
    Row = TextWindow.Read()
    currentlinedetails = File.ReadLine(FilePath, linenum)
    Len = Text.GetLength(currentlinedetails) 
    While currentlinedetails <> "" 
      If Row = Text.GetSubText(currentlinedetails, 1, 1) Then 
        Film()    
        Results()
        Validation()
        Loop()
        Goto END
      EndIf
      linenum  = linenum  + 1
      currentlinedetails = File.ReadLine(FilePath, linenum)
    EndWhile

    TextWindow.Clear()
    TextWindow.WriteLine("One or more of these seats are not available")
    END:    


    Sub Film
      While currentlinedetails <> ""  
        Comma = Text.GetIndexOf(currentlinedetails, ",")
        If Comma > 0 Then 
          Data[Array.GetItemCount(Data) + 1] = Text.GetSubText(currentlinedetails, 1, Comma - 1)
        Else 
          Data[Array.GetItemCount(Data) + 1] = Text.GetSubTextToEnd(currentlinedetails, Comma + 1)
          Goto END_While
        EndIf   
        currentlinedetails = Text.GetSubTextToEnd(currentlinedetails, Comma + 1)
      EndWhile
      END_While:
    EndSub

    Sub Results 
        TextWindow.Clear()
        TextWindow.WriteLine("Enter the number of the first seat you want to book (1 To 10)")
            TextWindow.WriteLine("Maximun seats you can book is 6")
        Group = TextWindow.ReadNumber()
      EndSub

      Sub Validation
        If Group < 7 Then
          Goto Continue
        Else 
          TextWindow.WriteLine("Too many seats selected")
          TextWindow.Pause()
          Program.End()
          Goto end1
          Continue:
          Total = 0
          Num = 1
              While Total < 11
            If Data[2 + Total] = "O" Then
              TextWindow.Clear()
              Seat[Num] = "True"
              Total = Total + 1
              Num = Num + 1
            Else
              Seat[Num] = "False"
              Total = Total + 1
              Num = Num + 1
          EndIf
        EndWhile       
    EndIf
    EndSub

    Sub Loop
      current = 1
      line = 0
      Whileloop:
      While Group < 11
        For i = current To Group
          If Seat[i] = "True" Then
            TextWindow.WriteLine("Seats" + Row + current + "-" + Row + Group + " " + "Are Available")
            current = current + 1
            Group = Group + 1
            line = line + 1
            Goto Whileloop
          Else
            current = current + 1
            Group = Group + 1
            Goto Whileloop
          EndIf
        EndFor
      EndWhile
      If line = 0 Then
        TextWindow.Clear()
        TextWindow.WriteLine("No seats available in this row")
        EndIf
      EndSub
    end1:

      
    Monday, March 24, 2014 10:07 PM

Answers

  • Cinema

    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Tuesday, March 25, 2014 12:55 AM
    Answerer
  • Hi there

    Try using TW.writeline to debug your code.

    Input:
    TextWindow.Clear()
    FilePath = Program.Directory + "/Film.csv" 
    TextWindow.WriteLine("Enter the row you would like to book (A to E)")
    Row = TextWindow.Read()
    currentlinedetails = File.ReadLine(FilePath, linenum)
    Len = Text.GetLength(currentlinedetails) 
    
    TextWindow.WriteLine("linenum " + linenum)  'debuging
    TextWindow.Pause()
    
    While currentlinedetails <> "" 

    Notice there's NO value for linenum so therefore currentlinedetails = ""

    Because currentlinedetails = "" the program WILL NOT enter the While loop.

    Therefore the program skips the loop and proceeds to:

    TextWindow.Clear()
    TextWindow.WriteLine("One or more of these seats are not available")
    END:   

    And that's the end of the program.

    Tuesday, March 25, 2014 6:08 PM
    Moderator

All replies

  • Cinema

    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Tuesday, March 25, 2014 12:55 AM
    Answerer
  • Hi there

    Try using TW.writeline to debug your code.

    Input:
    TextWindow.Clear()
    FilePath = Program.Directory + "/Film.csv" 
    TextWindow.WriteLine("Enter the row you would like to book (A to E)")
    Row = TextWindow.Read()
    currentlinedetails = File.ReadLine(FilePath, linenum)
    Len = Text.GetLength(currentlinedetails) 
    
    TextWindow.WriteLine("linenum " + linenum)  'debuging
    TextWindow.Pause()
    
    While currentlinedetails <> "" 

    Notice there's NO value for linenum so therefore currentlinedetails = ""

    Because currentlinedetails = "" the program WILL NOT enter the While loop.

    Therefore the program skips the loop and proceeds to:

    TextWindow.Clear()
    TextWindow.WriteLine("One or more of these seats are not available")
    END:   

    And that's the end of the program.

    Tuesday, March 25, 2014 6:08 PM
    Moderator
  • Hi there

    Try using TW.writeline to debug your code.

    Input:
    TextWindow.Clear()
    FilePath = Program.Directory + "/Film.csv" 
    TextWindow.WriteLine("Enter the row you would like to book (A to E)")
    Row = TextWindow.Read()
    currentlinedetails = File.ReadLine(FilePath, linenum)
    Len = Text.GetLength(currentlinedetails) 
    
    TextWindow.WriteLine("linenum " + linenum)  'debuging
    TextWindow.Pause()
    
    While currentlinedetails <> "" 

    Notice there's NO value for linenum so therefore currentlinedetails = ""

    Because currentlinedetails = "" the program WILL NOT enter the While loop.

    Therefore the program skips the loop and proceeds to:

    TextWindow.Clear()
    TextWindow.WriteLine("One or more of these seats are not available")
    END:   

    And that's the end of the program.

    This could make a nice light Wiki article:

    http://social.technet.microsoft.com/wiki/contents/articles/23330.technet-guru-contributions-for-march.aspx

    Thanks!


    Ed Price, Power BI & SQL Server Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Thursday, March 27, 2014 2:33 AM
    Owner