I'm new in the vb world(and these forums so please excuse me if i'm posting in the wrong area) and I've done some minor java stuff but I'm just not sure at all on arrays. I have to have the user input or select a flight number and my txtBoxes show the flight info...I have to use arrays though:( I haven't had any problems with other projects in this class but this is due tomorrow and I'm so lost!

here's what I have which isn't much and here's what our teacher wants. I am not sure if any of this stuff is in the correct place on my form? or under my btnDisplay coding...? She said we'll have to end up using For i as integer.getFlights.(something)(0).getUpperbound.? Any help would be appreciated. thanks!

Private Sub frmFlights_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim flights () as schedule
Redim flights (4)

flights(0).number = 117
        flights(0).origin = "Tucson"
        flights(0).destination = "Dallas"
        flights(0).depatrure = "8:45 a.m."
        flights(1).number = 239
        flights(1).origin = "LA"
        flights(1).destinaion = "Boston"
        flights(1).departure = "10:15 a.m."
        flights(2).number = 298
        flights(2).origin = "Albany"
        flights(2).destination = "Reno"
        flights(2).departure = "1:35 p.m."
        flights(3).number = 326
        flights(3).origin = "Houston"
        flights(3).destination = "New York"
        flights(3).departure = "2:40 p.m."
        flights(4).number = 445
        flights(4).orgin = "New York"
        flights(4).destination = "Tampa"
        flights(4).departure = "4:20 p.m."
    End Sub

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

I'm new in the vb world(and these forums so please excuse me if i'm posting in the wrong area) and I've done some minor java stuff but I'm just not sure at all on arrays. I have to have the user input or select a flight number and my txtBoxes show the flight info...I have to use arrays though:( I haven't had any problems with other projects in this class but this is due tomorrow and I'm so lost!

here's what I have which isn't much and here's what our teacher wants. I am not sure if any of this stuff is in the correct place on my form? or under my btnDisplay coding...? She said we'll have to end up using For i as integer.getFlights.(something)(0).getUpperbound.? Any help would be appreciated. thanks!

Private Sub frmFlights_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim flights () as schedule
Redim flights (4)

flights(0).number = 117
flights(0).origin = "Tucson"
flights(0).destination = "Dallas"
flights(0).depatrure = "8:45 a.m."
flights(1).number = 239
flights(1).origin = "LA"
flights(1).destinaion = "Boston"
flights(1).departure = "10:15 a.m."
flights(2).number = 298
flights(2).origin = "Albany"
flights(2).destination = "Reno"
flights(2).departure = "1:35 p.m."
flights(3).number = 326
flights(3).origin = "Houston"
flights(3).destination = "New York"
flights(3).departure = "2:40 p.m."
flights(4).number = 445
flights(4).orgin = "New York"
flights(4).destination = "Tampa"
flights(4).departure = "4:20 p.m."
End Sub

Dim flights () as schedule
Redim flights (4)

wouldn't the following be better ??

dim flights(4) as schedule

I suppose schedule is another class , if so you have to initiate it first on each array element before assigning values

flights(0)=new schedule()

Where do you intend to display the information on your form , what kind of controls are you using ?? TextBoxes , DataGridView ....

Dim flights () as schedule
Redim flights (4)

wouldn't the following be better ??

dim flights(4) as schedule

I suppose schedule is another class , if so you have to initiate it first on each array element before assigning values

flights(0)=new schedule()

Where do you intend to display the information on your form , what kind of controls are you using ?? TextBoxes , DataGridView ....

I'm using a combo box to show the flight numbers to pick from then a display button (btnDisplay) to display the data in 3 txtBoxes(txtOrigin, txtDestination, and txtTime) ----TextBoxes....I'm just not sure of any of the coding with the array....? dim flights(4) as schedule seems like it would be better.

Edited 6 Years Ago by BillyMagnum: n/a

Very well, you first have to define the array , I see that you have done that in the form load , if you compile and run your current code with no errors , next step would be to fill flight numbers in the combox control , that can be done in different ways , but for the sake of better understanding how arrays work , I suggest you loop through the array to add items to combobox

Dim I as integer 
For I = 0 to flights.length -1 ‘ repeat four times
Me.ComboFlightNumbers.Items.Add(flights(i).number) ‘ adds flight  numbers to combobox 
Next 
Me. ComboFlightNumbers.SelectedIndex=0 ‘ show first item , this might cause an error if the combobox is empty

Now to display textboxes information you have to add code to your displaybutton click event , I suggest you use the combobox SelectedIndex Property since it will be the same as the array index you want to display , for example if the SelectedIndex is 1 , the array index you need will be 1 , hence

TextBox1.Text=flights(ComboFlightNumbers.SelectedIndex).origin

You will also have to define the array on top of your code before Form_Load event to allow other form members to access it

Dim flights (4) as schedule
Private Sub frmFlights_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Hope this helped

This article has been dead for over six months. Start a new discussion instead.