Results 1 to 36 of 36

Thread: 2D Array [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131

    2D Array [RESOLVED]

    I am trying to create an 2D array using these values:

    VB Code:
    1. '                   Boston   Chicago    Dallas  Las Vegas   Los Angeles Miami   Washington D.C  
    2. ' Boston            0        1004       1753    2752        3017        1520    448
    3. ' Chicago           1004     0          921     1780        2048        1397    709
    4. ' Dallas            1753     921        0       1230        1399        1343    1307
    5. ' Las Vegas         2752     1780       1230    0           272         2570    2420
    6. ' Los Angeles       3017     2048       1399    272         0           2716    2646
    7. ' Miami             1520     1397       1343    2570        2716        0       1057
    8. ' Washington D.C.   448      709        1307    2420        2646        1057    0

    Am I starting this out right??
    VB Code:
    1. Dim dblMileage(6, 6) As Double
    2.             dblMileage(0, 0) = 0
    3.             dblMileage(0, 1) = 1004
    Last edited by twisted; Jun 29th, 2004 at 12:51 PM.
    Twisted

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    It doesn't matter which way you populate it, as long as you're accessing it the right way, which depends upon how you populated it! So basically, know what you're doing!


    Somehow, I get the nagging feeling that there is an easier way to do what you're doing, instead of using an array.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Have to use an array! Then I think I'll use a For...Next statement!
    Twisted

  4. #4
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    like this?
    VB Code:
    1. Dim num(,) As Double = { _
    2.       {0, 1004, 1753, 2752, 3017, 1520, 448}, _
    3.       {1004, 0, 921, 1780, 2048, 1397, 709}, _
    4.       {1753, 921, 0, 1230, 1399, 1343, 1307}, _
    5.       {2752, 1780, 1230, 0, 272, 2570, 2420}, _
    6.       {3017, 2048, 1399, 272, 0, 2716, 2646}, _
    7.       {1520, 1397, 1343, 2570, 2716, 0, 1057}, _
    8.       {448, 709, 1307, 2420, 2646, 1057, 0} _
    9.       }
    10.  
    11.       Dim s() As String = {"boston", "chicago", "dallas", "las vegas", "los angeles", "miami", "washington d.c"}
    12.  
    13.       Dim i As Integer
    14.       For i = 0 To 6
    15.          ListView1.Items.Add(s(i))
    16.          Dim j As Integer
    17.          For j = 0 To 6
    18.             ListView1.Items(i).SubItems.Add(num(i, j))
    19.          Next
    20.       Next
    if not, i'm very very very sorry.

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi twisted,

    To answer your original post yes you are on the right track.
    However, you can store values ONLY in the final dimension of an array - in your case in each of the 6 elements of the second dimension. All other elements of all other dimensions are simply numerical references guiding you to the final storage element, so you will not be able to store names in the first dimension.

    Therefore, provided you intend to allocate the names of the cities to specific elements of the array then you are correct.

    i.e. in dblarray(0,1), the 0 wil REFER to Boston as on the left hand, verticle view and the 1 will HOLD the distance relating to Chicago as in the top line horizontal view, etc.

    However, if you have to make provision for adding other cities, then you will need 2 two dimensional arrays.

    dblarray1( , 0) where the 0 will contain the name of a city
    dblarray2( , ) which will act exactly as your present array
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Taxes:

    Is there an easier way to store that kind of information? I am curious to know.

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by mendhak
    Taxes:

    Is there an easier way to store that kind of information? I am curious to know.
    I personally don't think so. There are several other ways but if you look at his various posts, this guy is completing elementery assignments. I doubt if he has even looked at database or spreadsheet access yet. What we are looking at is not STORING the information but ACCESSING it. We are not even considering how it should be displayed or entered. I would hate to suggest to him that he creates a new class to hold the data in a collection

    What are your views?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    That sounds pretty good too, except for the amount of work to be put in, I guess.

    My first guess was to create a class with three properties: FromCity, ToCity, Distance.

    After that, add a bit of logic:

    If FromCity and ToCity are the same, then Distance = 0.

    Also, when calling the function to determine the distance between FromCity and ToCity, it shouldn't matter if FromCity and ToCity have been entered in the correct order. Let the logic do that... that should also eliminate half the entries too.

    Catch my drift?

    But again, I'm not too sure about this. I am going to try this out. If it's too much work, I'll abandon it

  9. #9
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by mendhak
    That sounds pretty good too, except for the amount of work to be put in, I guess.

    My first guess was to create a class with three properties: FromCity, ToCity, Distance.

    If you consider this for a moment, you are going to have to create an instance of the class for each possible combination - in the case of 6 cities that means 25 instances.

    If you have a fixed number of cities, you class properties could be
    FromCity, ToCity1, Distance1, ToCity2, Distance2 etc.

    I think the array approach is better in this case.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  10. #10
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Originally posted by taxes
    I personally don't think so. There are several other ways but if you look at his various posts, this guy is completing elementery assignments. I doubt if he has even looked at database or spreadsheet access yet. What we are looking at is not STORING the information but ACCESSING it. We are not even considering how it should be displayed or entered. I would hate to suggest to him that he creates a new class to hold the data in a collection

    What are your views?
    Yes there is. Just use an array of structs
    \m/\m/

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by taxes
    If you consider this for a moment, you are going to have to create an instance of the class for each possible combination - in the case of 6 cities that means 25 instances.

    If you have a fixed number of cities, you class properties could be
    FromCity, ToCity1, Distance1, ToCity2, Distance2 etc.

    I think the array approach is better in this case.
    Yes, you're right. I just found myself turning it into a collection for this purpose. And I also noticed that it IS a lot of work, and I'm eventually using something similar to an array.

    Ugh.

    concepts.

  12. #12
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by PT Exorcist
    Yes there is. Just use an array of structs
    I would be interested to learn how that would be simpler
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Ok Taxes you seem to know me pretty well and this is my second to last assignment for the semester. Yes I am a VB newb so here goes the questions:

    I am using two ListView boxes with the same cities in each box in the same index order, the user will select one from each (which I can't figure out, right now they can only select one from either) then they will click a menu item call mnuMileage and it will calculate the mileage between the two cities. Now like you said I am doing it right like this:
    VB Code:
    1. Dim dblMileage(6, 6) As Double
    2.             dblMileage(0, 0) = 0
    3.             dblMileage(0, 1) = 1004

    But where do they get the Mileage data from?? I have to set up something where it pulls out the data.

    Say for dblMileage (0,3) that would be from Boston to Dallas.

    dblMileage (0, 3) would equal 1753 but how does it pull out this information and from what??
    Twisted

  14. #14
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    YOU have to decide from where to get the mileage data

    When you are writing the program you have to decide that in dblMileage(x , y), y contains the number of miles between the cities denoted by x and y.

    Now, you can do this in two ways (apart from using a link to the GPS )

    1. You can import the data from a database (which is what you will do when you become more proficient)

    OR

    2. You can write the mileage in yourself at design time. e.g.

    If Boston is your first city and Chicago your second and the mileage is 1004, then when loading your form you include the code:


    dblMileage(0,1)=1004
    dblmileage(1,0)=1004

    etc.

    Now, when the city selections have been made from the two listviews, you obtain the result by:

    dblMileage(x,y)

    Where x= the ListView1.SelectedIndex and
    y= the ListView2.SelectedIndex.

    You have to be careful that you do not change the sort order in the ListView from the order of cities used in the array.

    Is that what you want or have I misunderstood you?

    By the way, unless you are a geographical genius, there is no way you will write a programme which actually CALCULATES the distance between two cities. All you will be doing is to DISPLAY the distance you have previously determined (probably by looking up someone else's figures )
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    That's exactly what I needed to know.

    Also right now I can only select a city from lstDet or lstDep. I want to select a city from each one. Do you know why this is happening? They are two different ListView boxes so I should be able to select an item for each one right.
    Twisted

  16. #16
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by twisted
    That's exactly what I needed to know.

    Also right now I can only select a city from lstDet or lstDep. I want to select a city from each one. Do you know why this is happening? They are two different ListView boxes so I should be able to select an item for each one right.
    You will have to post your selection code. You could be using the same variable for both or you may not be correctly using the SelectedIndexChanged event of the listviews properly.

    Your reference to the array should be something like:
    VB Code:
    1. dblMileage(lstdep.ListView1.SelectedIndices(0),  _
    2. lstdet.ListView1.SelectedIndices(0))
    Last edited by taxes; Jun 26th, 2004 at 03:09 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    I don't have any selection code yet! I just created two ListView boxes and added the Cities to their collection.
    Twisted

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    VB Code:
    1. Private Cities(2) As String
    2.     Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
    3.         If Me.ListView1.SelectedItems.Count > 0 Then
    4.             Cities(0) = Me.ListView1.SelectedItems(0).Text
    5.         End If
    6.     End Sub
    7.     Private Sub ListView2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView2.SelectedIndexChanged
    8.         If Me.ListView1.SelectedItems.Count > 0 Then
    9.             Cities(1) = Me.ListView2.SelectedItems(0).Text
    10.         End If
    11.     End Sub
    12. If Cities(0).Length = 0 Then
    13.     MessageBox.Show("You need to select a Destination City", "Error")
    14.     ElseIf Cities(1).Length = 0 Then
    15.     MessageBox.Show("You need to select a Departure City", "Error")
    16.     End If

    LIKE THIS???
    Twisted

  19. #19
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Yep, that's the correct way to do what you are trying to accomplish.

  20. #20
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    O.K. Let us see your code for adding the cities to the listviews.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    I don't have code for adding the cities to the ListView. I just went into ListView properties and added them through Collection. Is this right??
    Twisted

  22. #22
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by twisted
    I don't have code for adding the cities to the ListView. I just went into ListView properties and added them through Collection. Is this right??
    Sure, that's OK.

    So, are you still having problems selecting a city from each listview?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    VB Code:
    1. Private Sub mnuMileage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuMileage.Click
    2.         '                   Boston   Chicago    Dallas  Las Vegas   Los Angeles Miami   Washington D.C  
    3.         ' Boston            0        1004       1753    2752        3017        1520    448
    4.         ' Chicago           1004     0          921     1780        2048        1397    709
    5.         ' Dallas            1753     921        0       1230        1399        1343    1307
    6.         ' Las Vegas         2752     1780       1230    0           272         2570    2420
    7.         ' Los Angeles       3017     2048       1399    272         0           2716    2646
    8.         ' Miami             1520     1397       1343    2570        2716        0       1057
    9.         ' Washington D.C.   448      709        1307    2420        2646        1057    0
    10.        
    11.         Dim dblMileage(6, 6) As Double
    12.         dblMileage(0, 0) = 0
    13.         dblMileage(0, 1) = 1004
    14.         dblMileage(0, 2) = 1753
    15.         dblMileage(0, 3) = 2752
    16.         dblMileage(0, 4) = 3017
    17.         dblMileage(0, 5) = 1520
    18.         dblMileage(0, 6) = 448
    19.         dblMileage(1, 0) = 1004
    20.         dblMileage(1, 1) = 0
    21.         dblMileage(1, 2) = 921
    22.         dblMileage(1, 3) = 1780
    23.         dblMileage(1, 4) = 2048
    24.         dblMileage(1, 5) = 1397
    25.         dblMileage(1, 6) = 709
    26.         dblMileage(2, 0) = 1753
    27.         dblMileage(2, 1) = 921
    28.         dblMileage(2, 2) = 0
    29.         dblMileage(2, 3) = 1230
    30.         dblMileage(2, 4) = 1399
    31.         dblMileage(2, 5) = 1343
    32.         dblMileage(2, 6) = 1307
    33.         dblMileage(3, 0) = 2752
    34.         dblMileage(3, 1) = 1780
    35.         dblMileage(3, 2) = 1230
    36.         dblMileage(3, 3) = 0
    37.         dblMileage(3, 4) = 272
    38.         dblMileage(3, 5) = 2570
    39.         dblMileage(3, 6) = 2420
    40.         dblMileage(4, 0) = 3017
    41.         dblMileage(4, 1) = 2048
    42.         dblMileage(4, 2) = 1399
    43.         dblMileage(4, 3) = 272
    44.         dblMileage(4, 4) = 0
    45.         dblMileage(4, 5) = 2716
    46.         dblMileage(4, 6) = 2646
    47.         dblMileage(5, 0) = 1520
    48.         dblMileage(5, 1) = 1397
    49.         dblMileage(5, 2) = 1343
    50.         dblMileage(5, 3) = 2570
    51.         dblMileage(5, 4) = 2716
    52.         dblMileage(5, 5) = 0
    53.         dblMileage(5, 6) = 1057
    54.         dblMileage(6, 0) = 448
    55.         dblMileage(6, 1) = 709
    56.         dblMileage(6, 2) = 1307
    57.         dblMileage(6, 3) = 2420
    58.         dblMileage(6, 4) = 2646
    59.         dblMileage(6, 5) = 1057
    60.         dblMileage(6, 6) = 0
    61.  
    62. If Cities(0).Length = 0 Then
    63.     MessageBox.Show("You need to select a Destination City", "Error")
    64.     ElseIf Cities(1).Length = 0 Then
    65.     MessageBox.Show("You need to select a Departure City", "Error")
    66.     End If
    67.     End Sub
    68. Private Cities(2) As String
    69.     Private Sub lstDep_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstDep.SelectedIndexChanged
    70.         If Me.lstDep.SelectedItems.Count > 0 Then
    71.             Cities(0) = Me.lstDep.SelectedItems(0).Text
    72.         End If
    73.     End Sub
    74.     Private Sub lstDet_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstDet.SelectedIndexChanged
    75.         If Me.lstDet.SelectedItems.Count > 0 Then
    76.             Cities(1) = Me.lstDet.SelectedItems(0).Text
    77.         End If
    78.     End Sub

    This is what I have set up! And yes, still problems I can only select one from either.
    Last edited by twisted; Jun 28th, 2004 at 08:50 AM.
    Twisted

  24. #24
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Your immediate problem is that

    If Cities(0).Length = 0 Then
    MessageBox.Show("You need to select a Destination City", "Error")
    ElseIf Cities(1).Length = 0 Then
    MessageBox.Show("You need to select a Departure City", "Error")
    End If

    Is not included in any sub. Presumeably you intemded it to be inserted in the mnuMileage_Click event.

    I do not undetstand why you are not getting an error message during your coding.
    Last edited by taxes; Jun 28th, 2004 at 09:04 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  25. #25

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    I did edit my code to reflect that before you posted but am still getting this error:

    An unhandled exception of type 'System.NullReferenceException' occurred in Mileage Lookup.exe

    Additional information: Object reference not set to an instance of an object.
    VB Code:
    1. If Cities(0).Length = 0 And Cities(1).Length = 0 Then
    2.             MessageBox.Show("You need to select a Departure and Destination City", "Error")
    3.         ElseIf Cities(0).Length = 0 Then
    4.             MessageBox.Show("You need to select a Departure City", "Error")
    5.         ElseIf Cities(1).Length = 0 Then
    6.             MessageBox.Show("You need to select a Destination City", "Error")
    7.         End If
    Twisted

  26. #26

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Maybe this will help!

    SEE ALL MY CODE HERE

    OK here is what I need:

    1) Need to be able to select a city from each ListView

    2) Need to click on View Mileage and it will pull the information from the 2D array.

    These are the two things I am stuck on!
    Twisted

  27. #27
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Let's take this in stages.

    1. Your present code DOES allow you to select one city from each listview and stores them in Cities(0) and Cities(1). What it does not do is leave both the selectied cities marked in the listviews.

    2. Your error arises when one or both city selections are omitted and you have a nul value in Cities().To allow for this your validation code should be;

    [Highlight=VB]
    Dim strError As String =""
    If Cities(0)="" and Cities(1)="" then
    strError=" Departure & Destination Cities""
    ElseIf Cities(0) = "" Then
    strError=" a Departure City"
    ElseIf Cities(1 = "" Then
    strError=" a Destination City"
    End If
    If strError<>"" then
    MesssageBox.Show("You need to enter " & strError, "Error")
    [/vbpode]


    3. To view the mileage just put the desired array value in a Label. Your array reference will be the index numbers of the selecteditem in lstdep and the selecteditem in lstDet (in that order)
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  28. #28

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    dblMileage(lstDep.SelectedItems(0), lstDet.SelectedItems(0))

    I did this and thought it would work but it doesn't!

    Also my Message statment only works the first time. After you select one the count must be greater then 0, I guess. So it only works the first time.
    Twisted

  29. #29

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    I still can't figure it out! I'm trying to write code so it will pull the information from a 2D array of each ListView box index selection.

    Say Boston to Dallas, then the user click View--> Mileage and I want it to display the information in a message box. Like this:

    The total mileage between your selections is: 1753 Miles
    Twisted

  30. #30

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    This isn't right is it? It doesn't pull the values from the 2D array, will it??
    VB Code:
    1. Dim strMileage As String
    2.         strMileage = "lstDep, lstDet"
    3.         If Me.lstDep.SelectedItems.Count < 0 And Me.lstDet.SelectedItems.Count < 0 Then
    4.             MessageBox.Show("The total miles from Departure City to Destination City is" & strMileage, "Total Mileage")
    5.         End If
    Twisted

  31. #31

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Originally posted by taxes
    Hi,

    Let's take this in stages.

    1. Your present code DOES allow you to select one city from each listview and stores them in Cities(0) and Cities(1). What it does not do is leave both the selectied cities marked in the listviews.

    2. Your error arises when one or both city selections are omitted and you have a nul value in Cities().To allow for this your validation code should be;

    [Highlight=VB]
    Dim strError As String =""
    If Cities(0)="" and Cities(1)="" then
    strError=" Departure & Destination Cities""
    ElseIf Cities(0) = "" Then
    strError=" a Departure City"
    ElseIf Cities(1 = "" Then
    strError=" a Destination City"
    End If
    If strError<>"" then
    MesssageBox.Show("You need to enter " & strError, "Error")
    [/vbpode]


    3. To view the mileage just put the desired array value in a Label. Your array reference will be the index numbers of the selecteditem in lstdep and the selecteditem in lstDet (in that order)
    So can you help me with the first one so I can try and do the rest by myself. I can't figure out if my code works without being able to select one item from each ListView. My listviews are named lstDep and lstDet and they both contain the same cities in the same order. Here is what it should look like when it's complete!
    Twisted

  32. #32
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by twisted
    This isn't right is it? It doesn't pull the values from the 2D array, will it??
    VB Code:
    1. Dim strMileage As String
    2.         strMileage = "lstDep, lstDet"
    3.         If Me.lstDep.SelectedItems.Count < 0 And Me.lstDet.SelectedItems.Count < 0 Then
    4.             MessageBox.Show("The total miles from Departure City to Destination City is" & strMileage, "Total Mileage")
    5.         End If
    Sorry, I've been playing tennis for the past 7 hours.

    I am not over familiar with ListViews in this context as I prefer to us DropDownCombo's. This has the advantage of leaving the selected item visible in the combo window. However I am looking it all up.


    What we need to find out is:

    1. How can we leave the selected item of BOTH listviews
    highlighted.?

    2. How can we get the index number of the selecteditem of a
    listview?

    If anyone out there can help it would be appreciated.

    Meanwhile, I will keep looking.


    As the subject of this thread has completely changed now, I have started a new thread entitled ListViews.
    Last edited by taxes; Jun 28th, 2004 at 06:58 PM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  33. #33
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Did you see the quick response to the new thread?


    What you have to do is to change the HideSelection property of the two ListViews to False.


    Then something like

    VB Code:
    1. TextBoxMileage=dblMileage(lstDep.SelectedItems(0).Index, lstDet.SelectedItems(0).Index)


    (With acknowledgments to crptcblade)
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  34. #34

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    OK! Only thing I need to figure out still is how to retrieve data from my 2D array. This is what I want to happen but don't know how to put it into code:

    I want to display a message box saying " The mileage between the cities selected is {value from 2D array}"

    So I'm thinking I need to make this a string:

    dblMileage(lstDep.SelectedItems(0).Index, lstDet.SelectedItems(0).Index)

    So when I make it a string:


    If you have selected a item from lstDep and lstDet, then MessageBox.Show("The mileage between the cities selected is" & strValue, "Mileage")

    Am I hot or very cold?? And if so could someone show me how to make my string with my statement?
    Twisted

  35. #35
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    VB Code:
    1. strValue = dblMileage(lstDep.SelectedItems(0).Index, lstDet.SelectedItems(0).Index).ToString
    I *think* that will do it.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  36. #36

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Pulls the information perfectly. Thanks!
    VB Code:
    1. strValue = dblMileage(lstDep.SelectedItems(0).Index, lstDet.SelectedItems(0).Index).ToString
    2.         MessageBox.Show("The mileage between the two cities is " & strValue, "Mileage")
    Twisted

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