Public Class BookingForm Private bookedTimes As New Dictionary(Of String, Boolean) Private Sub BookingForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' 初始化bookedTimes字典 bookedTimes.Add("11:00-13:00", False) bookedTimes.Add("13:00-15:00", False) bookedTimes.Add("15:00-17:00", False) End Sub Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged Dim selectedTime As String = ListBox1.SelectedItem.ToString() If bookedTimes(selectedTime) Then ' 时间段已经被预订,禁用提交按钮并显示提示 btnSubmit.Enabled = False MessageBox.Show(selectedTime & " has already been booked.") Else ' 时间段可以预订,启用提交按钮并将标志设置为已预订 btnSubmit.Enabled = True bookedTimes(selectedTime) = True End If End SubEnd Class给定关键词不在字典中怎么改?
时间: 2024-02-14 16:08:52 浏览: 161
在vb.net里怎么实现一个类似Windows10系统里自带的记事本程序的全部功能_(1).txt
你可以使用Dictionary类的ContainsKey方法来检查字典中是否存在指定的关键词。例如,如果你要检查"9:00-11:00"是否在字典中,可以这样做:
```
If Not bookedTimes.ContainsKey("9:00-11:00") Then
' 字典中不存在该关键词,进行相应处理
End If
```
在这个例子中,你可以根据需要进行处理,例如向字典中添加该关键词,或者显示一个错误消息提示用户该时间段不可预订。
阅读全文