locked
Listboxes and Loops RRS feed

  • Question

  • Hey everyone, right now I'm on a visual basic assignment where I have two listboxes with Workshops in the first and Locations in the second. I'm having some issues trying to figure out first how to make a variable that will store whatever the selections are in each of the two listboxes, then I'm also needing to make a loop that will allow me to go through each combination of the two listbox selection combinations so I can make a calculation on some prices for each combination without having to type out repetitious code for each of these selections. here's an example of what I started with:

    Private Sub btnAddWorkshop_Click(sender As Object, e As EventArgs) Handles btnAddWorkshop.Click
            If lstWorkshop.SelectedIndex = -1 Then
                MessageBox.Show("Please select a workshop from the list", "Workshop Error")
                Exit Sub
            ElseIf Do While lstWorkshop.SelectedIndex = 0 To 4 Then
                If lstLocation.SelectedIndex = -1 Then
                    MessageBox.Show("Please select a location from the list", "Location Error")
                    Exit Sub
                ElseIf Do While lstLocation.SelectedIndex = 0 To 4 Then
                    decLodging = dec_AUSTIN * int_STRESS
                    strWorkshop = "Handling Stress"
                    strLocation = "Austin"
                    lstCosts.Items.Insert(0, "Workshop: " & strWorkshop)
                    lstCosts.Items.Insert(1, "Location: " & strLocation)
                    lstCosts.Items.Insert(2, "Lodging: " & decLodging.ToString("C"))
                    lstCosts.Items.Insert(3, "Workshop Fee: " & dec_STRESS.ToString("C"))
                    lstCosts.Items.Insert(4, "")

    Saturday, March 14, 2020 7:26 PM

Answers

  • This is starting to go in the right direction, however I can't have a DataGridView for the third box, it can only be a listbox. This third (the right side) listbox is getting the output from the far left listbox's Workshop title and the middle listbox's Location while also bringing up the price for registration and the cost for lodging at said location. simply put, this is what prints out on the right listbox if one chooses the Workshop titled "Handling Stress" that takes place in the workshop in "Austin":

    "Workshop:  Handling Stress"

    "Location: Austin"

    ((next part is from a calculation of how many days the workshop is times the lodging fee per day))

    "Lodging:  $285.00"

    "Workshop Fee:  $595.00"

    Hope this clears things up a bit more, apologies if I'm causing any confusion.

    Hi

    OK, try this

    I can't imagine ever using a ListBox for the results like that!

    Option Strict On
    Option Explicit On
    Public Class Form1
      Dim WorkshopCost As New Dictionary(Of String, Double)
      Dim WorkshopDays As New Dictionary(Of String, Integer)
      Dim LodgingCosts As New Dictionary(Of String, Double)
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        With WorkshopCost
          .Add("Stress", 595D)
          .Add("Time", 695)
          .Add("Skills", 995)
          .Add("Negotiation", 1295)
          .Add("Interview", 395)
        End With
        With WorkshopDays
          .Add("Stress", 3)
          .Add("Time", 3)
          .Add("Skills", 3)
          .Add("Negotiation", 5)
          .Add("Interview", 1)
        End With
        With LodgingCosts
          .Add("Austin", 95)
          .Add("Chicago", 125)
          .Add("Dallas", 110)
          .Add("Orlando", 100)
          .Add("Phoenix", 92)
          .Add("Raleigh", 90)
        End With
    
        With ListBox1
          For Each s As String In WorkshopCost.Keys
            .Items.Add(s)
          Next
          .SelectionMode = SelectionMode.One
          .SelectedIndex = -1
        End With
        With ListBox2
          For Each s As String In LodgingCosts.Keys
            .Items.Add(s)
          Next
          .SelectionMode = SelectionMode.One
          .SelectedIndex = -1
        End With
    
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If ListBox1.SelectedIndex < 0 Or ListBox2.SelectedIndex < 0 Then
          MessageBox.Show("Need Workshop and Location to be selected....")
          Exit Sub
        End If
    
        Dim Wshop As String = ListBox1.SelectedItem.ToString
        Dim Loc As String = ListBox2.SelectedItem.ToString
    
        With ListBox3
          .Items.Clear()
          .Items.Add("Workshop: " & Wshop)
          .Items.Add("Location: " & Loc)
          .Items.Add("Lodging:  $" & LodgingCosts(Loc) * WorkshopDays(Wshop))
          .Items.Add("Workshop Fee: $" & WorkshopCost(Wshop))
        End With
      End Sub
    End Class


    Regards Les, Livingston, Scotland

    Monday, March 16, 2020 12:22 AM

All replies

  • Hi

    Hard to understand what you need as there are many undefined variables.

    Here is some code, a stand alone example, that may address some of your questions.

    This example is  bare bones and has no exception handling.

    User selects from both lists and clicks ADD. Detasils put into a DataGridView. The Data is saved on application close and reloaded on application start.

    I suspect this is not what you want, but,it was all I could come up with based on your post.

    Option Strict On
    Option Explicit On
    Public Class Form1
      Dim dt As New DataTable("Freddy")
      Dim WKcosts As New Dictionary(Of String, Double)
      Dim LOCcosts As New Dictionary(Of String, Double)
      Dim FilePath As String = IO.Path.Combine(Application.StartupPath, "Data", "SavedData.xml")
      Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        If Not IO.Directory.Exists(IO.Directory.GetParent(FilePath).FullName) Then
          IO.Directory.CreateDirectory(IO.Directory.GetParent(FilePath).FullName)
        End If
        dt.WriteXml(FilePath)
      End Sub
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        With WKcosts
          .Add("Textiles", 21.3)
          .Add("Roofing", 44.66)
          .Add("Tiling", 33.25)
          .Add("Flower Arrangement", 2.25)
          .Add("Underwear", 1.5)
        End With
        With LOCcosts
          .Add("London", 96.0)
          .Add("Cardiff", 56.0)
          .Add("Aberdeen", 73.25)
          .Add("Austin", 166.9)
          .Add("Glasgow", 111.65)
          .Add("Dallas", 187.7)
          .Add("Ontario", 121.75)
        End With
        With dt
          .Columns.Add("Workshop", GetType(String))
          .Columns.Add("Workshop Fees", GetType(Decimal))
          .Columns.Add("Location", GetType(String))
          .Columns.Add("Location Allowance", GetType(Decimal))
          .Columns.Add("WK  Index", GetType(Integer))
          .Columns.Add("Loc Index", GetType(Integer))
    
        End With
        With ListBox1
          For Each s As String In WKcosts.Keys
            .Items.Add(s)
          Next
          .SelectionMode = SelectionMode.One
          .SelectedIndex = -1
        End With
        With ListBox2
          For Each s As String In LOCcosts.Keys
            .Items.Add(s)
          Next
          .SelectionMode = SelectionMode.One
          .SelectedIndex = -1
        End With
    
        If IO.File.Exists(FilePath) Then dt.ReadXml(FilePath)
        DataGridView1.DataSource = dt
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If ListBox1.SelectedIndex < 0 Or ListBox2.SelectedIndex < 0 Then
          MessageBox.Show("Need Workshop and Location to be selected....")
          Exit Sub
        End If
        dt.Rows.Add(ListBox1.SelectedItem.ToString, WKcosts(ListBox1.SelectedItem.ToString), ListBox2.SelectedItem.ToString, LOCcosts(ListBox2.SelectedItem.ToString), ListBox1.SelectedIndex, ListBox2.SelectedIndex)
      End Sub
    
    End Class


    Regards Les, Livingston, Scotland

    Saturday, March 14, 2020 8:27 PM
  • Alright I left out some of the coding, I apologize. This is all I've gotten so far:

    Public Class Workshop
        'Lounge Lizard Work Shop Calculator
        'Calculates costs for going to Workshops
        'Last Modified 3/12/20
        'Created by

        'Declaring constants for workshop registration fees
        Const dec_STRESS As Decimal = 595D          'Fee for Handling Stress
        Const dec_TIME As Decimal = 695D            'Fee for Time Management
        Const dec_SKILLS As Decimal = 995D          'Fee for Supervision Skills
        Const dec_NEGOTIATION As Decimal = 1295D    'Fee for Negotiation
        Const dec_INTERVIEW As Decimal = 395D       'Fee for How to Interview

        'Declaring constants for number of days per workshop
        Const int_STRESS As Integer = 3             'Days for Handling Stress
        Const int_TIME As Integer = 3               'Days for Time Management
        Const int_SKILLS As Integer = 3             'Days for Supervision Skills
        Const int_NEGOTIATION As Integer = 5        'Days for Negotiation
        Const int_INTERVIEW As Integer = 1          'Days for How to Interview

        'Declaring constants for lodging fees per day for each location
        Const dec_AUSTIN As Decimal = 95D           'Daily lodging fee for Austin
        Const dec_CHICAGO As Decimal = 125D         'Daily lodging fee for Chicago
        Const dec_DALLAS As Decimal = 110D          'Daily lodging fee for Dallas
        Const dec_ORLANDO As Decimal = 100D         'Daily lodging fee for Orlando
        Const dec_PHOENIX As Decimal = 92D          'Daily lodging fee for Phoenix
        Const dec_RALEIGH As Decimal = 90D          'Daily lodging fee for Raleigh

        'Declaring variables for calculations and output
        Dim intWorkshopCount As Integer   'Counter for Workshop loop
        Dim intLocationCount As Integer   'Counter for Location loop
        Dim decLodging As Decimal         'Holds lodging cost * days stayed
        Dim decTotal As Decimal           'Holds the total of lodging cost * days stayed + registration fee
        Dim decTotalFees As Decimal       'Holds the grand total (sum of all workshop and lodging fees)
        Dim intDays As Integer            'Holds the amount of days stayed
        Dim strOutWorkshop As String      'Holds the output name of the workshop selected in the Workshop list
        Dim strOutLocation As String      'Holds the output location of the workshop selected in the location list
        Dim strWorkshop As String         'Holds the workshop name based on what index was selected in the list
        Dim strLocation As String         'Holds the location name based on what index was selected in the list


        Private Sub btnAddWorkshop_Click(sender As Object, e As EventArgs) Handles btnAddWorkshop.Click
            If lstWorkshop.SelectedIndex = -1 Then
                MessageBox.Show("Please select a workshop from the list", "Workshop Error")
                Exit Sub
            ElseIf Do While lstWorkshop.SelectedIndex = 0 To 4 Then
                If lstLocation.SelectedIndex = -1 Then
                    MessageBox.Show("Please select a location from the list", "Location Error")
                    Exit Sub
                ElseIf Do While lstLocation.SelectedIndex = 0 To 4 Then
                    decLodging = dec_AUSTIN * int_STRESS
                    strWorkshop = "Handling Stress"
                    strLocation = "Austin"
                    lstCosts.Items.Insert(0, "Workshop: " & strWorkshop)
                    lstCosts.Items.Insert(1, "Location: " & strLocation)
                    lstCosts.Items.Insert(2, "Lodging: " & decLodging.ToString("C"))
                    lstCosts.Items.Insert(3, "Workshop Fee: " & dec_STRESS.ToString("C"))
                    lstCosts.Items.Insert(4, "")
                End If
            End If
        End Sub
    End Class

    I'd add a picture but as my account isn't verified I don't have the ability to, however I have three groupboxes with each groupbox having a listbox in it. The leftmost listbox contains the different workshops, the middle listbox contains the different locations for the workshops, and the right listbox is pretty much left blank, it will display the output of the workshops and locations but no total cost. There are four buttons, but the two most important are an add workshop button (will send the workshop, location, cost of lodging, and cost of workshop registration) to the rightmost listbox. I guess what I'm looking for is a way to loop through the listbox selections to see which ones were selected without typing the same code for each and every combination of listbox selections from the first two.

    Saturday, March 14, 2020 11:37 PM
  • Hi

    Was there any part of the code I posted going in the right direction?

    It does 'send' the user selected details to a datatable actualy which is bound to the DataGroidView for display.

    *

    Please desribe the process start to finish for one 'transaction'

    eg  User selects Dallas and Stress and clicks the button.

    The button handler calculates the total cost as follows:

    595 for workshop, location Dallas, 3 days at 110 : total = 595 + 3 x 110 = 925

    is that representative?


    Regards Les, Livingston, Scotland


    • Edited by leshay Sunday, March 15, 2020 12:42 AM
    Sunday, March 15, 2020 12:41 AM
  • Hi

    Here is an updated code based on your last post. Try it out as a stand alone example and see if it is veering in the direction you want.

    Option Strict On
    Option Explicit On
    Public Class Form1
      Dim dt As New DataTable("Freddy")
      Dim WorkshopCost As New Dictionary(Of String, Double)
      Dim WorkshopDays As New Dictionary(Of String, Integer)
      Dim LodgingCosts As New Dictionary(Of String, Double)
      Dim FilePath As String = IO.Path.Combine(Application.StartupPath, "Data", "SavedData.xml")
      Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        If Not IO.Directory.Exists(IO.Directory.GetParent(FilePath).FullName) Then
          IO.Directory.CreateDirectory(IO.Directory.GetParent(FilePath).FullName)
        End If
        dt.WriteXml(FilePath)
      End Sub
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        With WorkshopCost
          .Add("Stress", 595D)
          .Add("Time", 695)
          .Add("Skills", 995)
          .Add("Negotiation", 1295)
          .Add("Interview", 395)
        End With
        With WorkshopDays
          .Add("Stress", 3)
          .Add("Time", 3)
          .Add("Skills", 3)
          .Add("Negotiation", 5)
          .Add("Interview", 1)
        End With
        With LodgingCosts
          .Add("Austin", 95)
          .Add("Chicago", 125)
          .Add("Dallas", 110)
          .Add("Orlando", 100)
          .Add("Phoenix", 92)
          .Add("Raleigh", 90)
        End With
        With dt
          .Columns.Add("Workshop", GetType(String))
          .Columns.Add("Workshop Fee", GetType(Double))
          .Columns.Add("Location", GetType(String))
          .Columns.Add("Daily Lodging", GetType(Double))
          .Columns.Add("Workshop Days", GetType(Integer))
          .Columns.Add("Total Cost", GetType(Double), "[Workshop Fee] + [Workshop Days] * [Daily Lodging]")
        End With
        With ListBox1
          For Each s As String In WorkshopCost.Keys
            .Items.Add(s)
          Next
          .SelectionMode = SelectionMode.One
          .SelectedIndex = -1
        End With
        With ListBox2
          For Each s As String In LodgingCosts.Keys
            .Items.Add(s)
          Next
          .SelectionMode = SelectionMode.One
          .SelectedIndex = -1
        End With
    
        If IO.File.Exists(FilePath) Then dt.ReadXml(FilePath)
    
        DataGridView1.DataSource = dt
    
        With DataGridView1
          ' just some formatting for DGV
    
          .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
          .DefaultCellStyle.Padding = New Padding(8, 0, 8, 0)
          .DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
          .RowHeadersVisible = False
          .ReadOnly = True
          .SelectionMode = DataGridViewSelectionMode.FullRowSelect
          .AllowUserToAddRows = False
          With .Columns("Workshop Fee").DefaultCellStyle
            .Alignment = DataGridViewContentAlignment.TopRight
            .Format = "$0.00"
            .Padding = New Padding(8, 0, 8, 0)
          End With
          With .Columns("Daily Lodging").DefaultCellStyle
            .Alignment = DataGridViewContentAlignment.TopRight
            .Format = "$0.00"
          End With
          With .Columns("Total Cost").DefaultCellStyle
            .Alignment = DataGridViewContentAlignment.TopRight
            .Format = "$0.00"
          End With
        End With
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If ListBox1.SelectedIndex < 0 Or ListBox2.SelectedIndex < 0 Then
          MessageBox.Show("Need Workshop and Location to be selected....")
          Exit Sub
        End If
    
        Dim Wshop As String = ListBox1.SelectedItem.ToString
        Dim Loc As String = ListBox2.SelectedItem.ToString
    
        dt.Rows.Add(Wshop, WorkshopCost(Wshop), Loc, LodgingCosts(Loc), WorkshopDays(Wshop))
    
      End Sub
      Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        For Each r As DataGridViewRow In DataGridView1.SelectedRows
          DataGridView1.Rows.Remove(r)
        Next
      End Sub
    End Class


    Regards Les, Livingston, Scotland


    • Edited by leshay Sunday, March 15, 2020 2:48 PM Corrected unwanted feature :)
    Sunday, March 15, 2020 2:11 AM
  • Here is a simple code i used to use it with listboxes 

     Sub FillListBox1()
            ListBox1.Items.Clear()
            
            Using conn As New SqlConnection(cs)             
                conn.Open()
                Using command As New SqlCommand
                    command.Connection = conn
                    command.CommandText = "select sum(BI.GrandTotal) as total,
    		                                      sum(BI.GrandTotal - (BI.TotalPayment + JD.Paid)) as remain
    	                                    from JDone JD
                                            inner join BillInfo BI
                                            on JD.CustomerNo = BI.CustomerNo
                                            where BI.Visa = 1 
                                            and JD.JobDone = 0
                                            and BI.CustomerName = @a1"
                              
    
                    command.Parameters.Add("@a1", SqlDbType.NVarChar).Value = TextBox1.Text
                     command.CommandType = CommandType.Text
    
                    Using reader As SqlDataReader = command.ExecuteReader()
                        While reader.Read()
                            Dim tot As String = (reader("total")).ToString
                            Dim item3 As String = String.Format("Total : " + "{0}", tot)
                            ListBox1.Items.Add(item3).ToString()
                                             
                            Dim remi As String = (reader("remain")).ToString
                            Dim item4 As String = String.Format("Remain : " + "{0}", remi)
                            
                            ListBox1.Items.Add(item4).ToString()
                                                    
                            End While 
                    
                    End Using
                End Using
            End Using
    
            Label6.Text = CType((ListBox1.Items.Count()), String)
    
        End Sub
    
        Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
            TextBox1.Text = ""
    
            If ListBox1.SelectedIndex > -1 Then
                TextBox1.Text = CType(ListBox1.SelectedItem.ToString, String)
            End If
            
        End Sub
    
        Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
            FillListBox2()
            FillListBox3()
        End Sub
      

    You can put FillListBox1() in Form load or in any suitable event you want ..... But i have an advice to you try to use DataGridView instead of ListBox , It is a new controller and it is simple to use and you can get your calculation more simple .... This doesn't mean that List Box is bad ,In the beginning of my VB.Net way i depended on it and it helps me a lot .... But DataGridView is more simple and pretty ... you can use something like that simple code with DGV

    in order to get the sum of your calculations

     Dim sum As Double = 0
                        Dim sum1 As Double = 0
                        Dim sum2 As Double = 0
                        Dim sum3 As Double = 0
                        For Each row As DataGridViewRow In DataGridView1.Rows
                            sum3 = sum3 + row.Cells(7).Value.ToString   'for Total salary
                            sum = sum + row.Cells(8).Value.ToString   'for Total discounts values
                            sum1 = sum1 + row.Cells(9).Value.ToString   'for Total holidays values
                            sum2 = sum2 + row.Cells(10).Value.ToString   'for Total bonus values
                        Next
                        txtTotalSalary.Text = sum3
                        txtTotalDiscountsValue.Text = sum
                        txtTotalHolidaysValue.Text = sum1
                        txtTotalBonusValue.Text = sum2

    It is up to you but ... Try to use DGV .........................

    Hope this helps you


    Regards From Egypt


    • Edited by Amr_Aly Sunday, March 15, 2020 7:39 AM
    Sunday, March 15, 2020 7:37 AM
  • This is starting to go in the right direction, however I can't have a DataGridView for the third box, it can only be a listbox. This third (the right side) listbox is getting the output from the far left listbox's Workshop title and the middle listbox's Location while also bringing up the price for registration and the cost for lodging at said location. simply put, this is what prints out on the right listbox if one chooses the Workshop titled "Handling Stress" that takes place in the workshop in "Austin":

    "Workshop:  Handling Stress"

    "Location: Austin"

    ((next part is from a calculation of how many days the workshop is times the lodging fee per day))

    "Lodging:  $285.00"

    "Workshop Fee:  $595.00"

    Hope this clears things up a bit more, apologies if I'm causing any confusion.

    Sunday, March 15, 2020 11:52 PM
  • Also, I can't get the total to show up in the far right listbox, I am not allowed to print the total cost for a certain workshop, just display the cost of lodging and the registration fee cost.
    Sunday, March 15, 2020 11:59 PM
  • This is starting to go in the right direction, however I can't have a DataGridView for the third box, it can only be a listbox. This third (the right side) listbox is getting the output from the far left listbox's Workshop title and the middle listbox's Location while also bringing up the price for registration and the cost for lodging at said location. simply put, this is what prints out on the right listbox if one chooses the Workshop titled "Handling Stress" that takes place in the workshop in "Austin":

    "Workshop:  Handling Stress"

    "Location: Austin"

    ((next part is from a calculation of how many days the workshop is times the lodging fee per day))

    "Lodging:  $285.00"

    "Workshop Fee:  $595.00"

    Hope this clears things up a bit more, apologies if I'm causing any confusion.

    Hi

    OK, try this

    I can't imagine ever using a ListBox for the results like that!

    Option Strict On
    Option Explicit On
    Public Class Form1
      Dim WorkshopCost As New Dictionary(Of String, Double)
      Dim WorkshopDays As New Dictionary(Of String, Integer)
      Dim LodgingCosts As New Dictionary(Of String, Double)
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        With WorkshopCost
          .Add("Stress", 595D)
          .Add("Time", 695)
          .Add("Skills", 995)
          .Add("Negotiation", 1295)
          .Add("Interview", 395)
        End With
        With WorkshopDays
          .Add("Stress", 3)
          .Add("Time", 3)
          .Add("Skills", 3)
          .Add("Negotiation", 5)
          .Add("Interview", 1)
        End With
        With LodgingCosts
          .Add("Austin", 95)
          .Add("Chicago", 125)
          .Add("Dallas", 110)
          .Add("Orlando", 100)
          .Add("Phoenix", 92)
          .Add("Raleigh", 90)
        End With
    
        With ListBox1
          For Each s As String In WorkshopCost.Keys
            .Items.Add(s)
          Next
          .SelectionMode = SelectionMode.One
          .SelectedIndex = -1
        End With
        With ListBox2
          For Each s As String In LodgingCosts.Keys
            .Items.Add(s)
          Next
          .SelectionMode = SelectionMode.One
          .SelectedIndex = -1
        End With
    
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If ListBox1.SelectedIndex < 0 Or ListBox2.SelectedIndex < 0 Then
          MessageBox.Show("Need Workshop and Location to be selected....")
          Exit Sub
        End If
    
        Dim Wshop As String = ListBox1.SelectedItem.ToString
        Dim Loc As String = ListBox2.SelectedItem.ToString
    
        With ListBox3
          .Items.Clear()
          .Items.Add("Workshop: " & Wshop)
          .Items.Add("Location: " & Loc)
          .Items.Add("Lodging:  $" & LodgingCosts(Loc) * WorkshopDays(Wshop))
          .Items.Add("Workshop Fee: $" & WorkshopCost(Wshop))
        End With
      End Sub
    End Class


    Regards Les, Livingston, Scotland

    Monday, March 16, 2020 12:22 AM
  • Hi,

    Have you solved this problem now?

    I think the above reply given by Leshay can provide you with a solution, have you tried it?

    If so, hope you can close this thread by marking the reply as answer as this will help others looking for the same or similar issues down the road.

    ElseIf Do While lstWorkshop.SelectedIndex = 0 To 4 Then
                If lstLocation.SelectedIndex = -1 Then
                    MessageBox.Show("Please select a location from the list", "Location Error")
                    Exit Sub
                ElseIf Do While lstLocation.SelectedIndex = 0 To 4 Then
                    decLodging = dec_AUSTIN * int_STRESS
                    strWorkshop = "Handling Stress"
                    strLocation = "Austin"
    
                End If

    In addition, the use of Do while mentioned above is incorrect, and the condition of If...Then...Else Statement must evaluate to True or False, or to a data type that is implicitly convertible to Boolean.

    If you have anything else about this issue, please feel free to contact us.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 16, 2020 6:08 AM