CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Creating Arrays

  1. #1
    Join Date
    Mar 2001
    Location
    North Dakota, USA
    Posts
    4

    Creating Arrays

    Just learned the word array and now have to write a program to load into 4 arrays. Problem requests 4 arrays with a range from 1 to 5, for a flight schedule, flight Origin destination and depart time. We are not to use an input file. This is what I have and obviously it doesn't work. You are suppose to be able to input a flight number and the information from the flight will be displayed. Is this really beginner stuff???

    Option Explicit
    'create form-level array
    Dim FlightNum(1 To 5) As String, Orig(1 To 5) As String, Dest(1 To 5) As String
    Dim DeptTime(1 To 5) As String

    Private Sub cmdFlightInfo_Click()
    'Enter a flight number into txtFlight box
    'and on cmdFlightInfo flight schedule will be
    'generated in the picResults if info is available

    'determine amount of flights scheduled

    Dim Flight As String, foundFlag As Boolean, n As Integer
    picResults.Print "Flight"; Tab(10); "Origin"; Tab(20); "Destination";
    picResults.Print Tab(35); "Dept Time"

    foundFlag = False
    Flight = txtFlight.Text
    n = 0
    Do
    n = n + 1
    If Flight Then
    foundFlag = True
    End If
    Loop Until (foundFlag = True) Or (n = 5)
    picResults.Cls
    If foundFlag = False Then
    picResults.Print "Flight Information not available."
    Else
    picResults.Print "FlightNum"; Tab(10); "Orig"; Tab(20); "Dest";
    picResults.Print Tab(35); "DeptTime"
    End If
    End Sub
    Private Sub form_Load()
    'Fill array with flight information
    FlightNum(1) = "117"
    FlightNum(2) = "239"
    FlightNum(3) = "298"
    FlightNum(4) = "326"
    FlightNum(5) = "445"

    Orig(1) = "Tuscon"
    Orig(2) = "LA"
    Orig(3) = "Albany"
    Orig(4) = "Houston"
    Orig(5) = "NewYork"

    Dest(1) = "Dallas"
    Dest(2) = "Boston"
    Dest(3) = "Reno"
    Dest(4) = "NewYork"
    Dest(5) = "Tampa"

    DeptTime(1) = "8:45 a.m."
    DeptTime(2) = "10:15 a.m."
    DeptTime(3) = "1:35 p.m."
    DeptTime(4) = "2:40 p.m."
    DeptTime(5) = "4:20 p.m."


    End Sub





  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Creating Arrays

    The mistake is in the line

    If Flight Then

    It should be

    If Flight = FlightNum(n) Then


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

Featured