How to replace label with dates - vb.net

I am using Visual Basic 2010. My question can best explained by these images.
I would like to know how to make the labels appear as dates depending on what the DateTimePicker is set on. For Example:
This is what the code looks now that I have solved my issue.
Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged
Me.Label14.Text = CStr(Me.MonthCalendar1.SelectionRange.Start)
Me.Label13.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(6))
Me.Label12.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(1))
Me.Label11.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(2))
Me.Label10.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(3))
Me.Label9.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(4))
Me.Label15.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(5))
End Sub

I don't have Visual Studio installed on this computer, so I can't give you the exact code, so I will try to explain it.
In the code of the event for the DateTimePicker, you have to calculate for each label the difference in days of the week from your date to the date you want to show (Wednesday to Saturday - 3 days (and you have a little error in the images - you have to switch Wednesday with Tuesday), Thursday to Saturday - 2 days, and so on...).
After that, you subtract (or add, if the day is after the chosen date) the referential date with the corresponding value from above, and you get the date needed. Now you only have to show the result in the label.

Found the answer to my own question.
To retrieve a date and display it in a label:
In the File menu, click New Project.
The New Project dialog box appears.
Click Windows Forms Application and then click OK.
Add a Label control to the form, leaving the default name Label1.
Remove the text from the Text property of the Label control.
Add a MonthCalendar control to the form, leaving the default name MonthCalendar1.
Double-click the MonthCalendar control to enter the default event handler in the Code Editor.
In the MonthCalendar1_DateChanged event handler, add the following code to add items to the list:
Me.Label1.Text = CStr(Me.MonthCalendar1.SelectionRange.Start)
Return to Designer view and add a DateTimePicker control to the form, leaving the default name DateTimePicker1.
Double-click the DateTimePicker control to enter the default event handler in the Code Editor.
In the DateTimePicker_ValueChanged event handler, add the following code to add items to the list:
Me.Label1.Text = CStr(Me.DateTimePicker1.Value)
Press F5 to run the program.
When the form appears, click a date in the MonthCalendar control and verify that the date is displayed in the label.
Click the drop-down arrow of the DateTimePicker control and select a date.
The date and time are displayed in the label.

Related

AfterUpdate On ComboBox: Display selection without requiring other action

I have a form with a combo box that has approval codes in it.
I created an AfterUpdate event so that when the user selects the approval code today's date will be placed in another field.
The problem is when I tab out of the combo box the date doesn't display in the field unless I click in that field or save the record.
I know I can do a Me.Refresh after the code, but I don't want to save the record until the user is done with everything they need to input.
Private Sub AppArch_AfterUpdate()
Me.DATE_RCVD_ARCH = Date
End Sub
Must reference textbox name so if field and textbox have same name, then your existing code should work and new value display immediately. Apparently that is not the case. I always name controls different from field, like tbxDateRA. Then code can be:
Me.tbxDateRA = Date
or
Me!tbxDateRA = Date
but use the first to trigger intellisense tips.

How can I set my ComboBox to allow the user to type in the first few characters and then automatically select the item by pressing ENTER?

I have a feeling this is a very simple thing that I'm overlooking.
I have two ComboBoxes that allow users to search for/select the record that they want to view. One is filled with Customer Names and the other is filled with Customer Numbers, so the user can look for a particular record by either selecting the Name or Number.
Each ComboBox is filled by a Data Table returned from a SQL Server database.
Each ComboBox has DropDownStyle set to DropDown, AutoCompleteMode set to SuggestAppend and AutoCompleteSource set to ListItems.
The user can either select by clicking the DropDown arrow and then clicking on the item they was or they can begin by typing and the ComboBox narrows the number of items in the list based on the characters the user is typing.
Using the mouse to click on the item in the list that they want works fine...it fires off a routine to retrieve the selected item from the database.
However, when the user types in the desired selection and presses ENTER, nothing happens. They must click the DropDown arrow and click on the item in order for the program to pull the appropriate record.
How do I get the ComboBox to pull the appropriate record when the user hits enter?
I'm using Visual Basic.
From the sounds of it, you need three events.
You need to use a timer to know when the user has stopped typing. To do that, you need one event would be when that field they're typing in has it's value change (<control's name>.TextChanged). That would start/restart a timer ticking (so that the user has a couple seconds to pause before the next event fires).
The next event would be the Tick event for that timer. That event would stop the timer, and then give focus to the right field so that when the user hits ENTER, they're not hitting ENTER in the field they've been typing in. You'll need to write a function to look up the right item in the ComboBox and call that.
Then you'd have a third event, either KeyPress, KeyDown, or KeyUp on the ComboBox itself. I'd lean towards the KeyUp to avoid issues if the user holds ENTER for whatever reason. That'd be what selects the item.
As a final FYI, I'm assuming you're using Visual Studio to write your code. If not, you should, and if you are/once you are, you can select the field you want to work with in the drop-down at the top left of the editor and then look at the associated events in the top right drop-down.
Thank you to JMichael for getting me on the right track with this one. I'm posting my solution here just in case it helps someone who has a similar question in the future:
The code that I added to the ComboBox's SelectionChangeCommitted event needed also to be added to the ComboBox's KeyUp event:
Private Sub cboPolicySearch_KeyUp(sended as Object, e As KeyEventArgs) Handles cboPolicySearch.KeyUp
If e.KeyCode = Keys.Enter Then
GetSelectedPolicySearchRecord()
e.Handled = True
End If
End Sub 'cboPolicySearch_KeyUp
The GetSelectedPolicySearchRecord() sub contained all of the information I needed to call my SQL Stored Procedure to select the data for the record that the user selected in the ComboBox.
Previously, this was only being called from the ComboBox's "SelectionChangeCommitted" event which is executed when the user clicks the drop down and then clicks a policy number from the drop down list.
I needed to add the same call to the GetSelectedPolicySearchRecord in the ComboBox's "KeyUp" event for when the user presses enter.

Visual Basic Can't Type in Listbox

I am using Visual Studio and working in a Windows Form Application. I have added a Listbox on my form. The problem I am having is that when I run my application I can't add any text or even select the Listbox to put my cursor in.
You have to add values or action to listbox before run it,if you run it without value or action absolutely that will give you nothing.
To add a value in listbox,right click on listbox then select "edit items...".
Or you can make a action like : add text to listbox from textbox,do looping,or another...
From the design window from theToolbox add a TextBox and a Button to your form. (The ListBox is already there, right?) Enter the following code to your form in the code window.
'This is the code that runs when the users clicks the button
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'This is the code that copies the text in the text box to the list box
ListBox1.Items.Add(TextBox1.Text)
'This code clears the text in the text box
TextBox1.Text = ""
End Sub
The text in the gray window that appears in light gray and is preceded with an apostrophe are comments; not part of the code.
Now run the program and type in the text box. Click the button and the text you typed will appear in the list box. Now that you have had this brief introduction to Visual Basic . NET try searching for a beginners tutorial. Come back when you have some code that you wrote but doesn't turn out as you thought.

Visual Basic .NET Project - Airline System

I want the 32 radiobuttons individually be able to be linked to a database when I click the 1 button which says "Submit". Meaning when I select 1 radio button and i click the submit button I would like to have a msg saying booking confirmed or something and when i click the submit button it stores it in the database. I have tried to develop something similar to this I tried making normal textboxs being able to store it in a database. How do I link MS Access to Visual Basic in order for the radio buttons to work? Would the Primary Key be the Field called Seats if thats where I want to store the data from that field in the table?
The Form comprises of:
PictureBox - which is an image that is a layout seating plan on a plane.
32 RadioButtons
1 Radio Button = 1 seat ideally
1 Button - When the user has chosen a seat they want they should click a button called "Submit". When the button is clicked I want the seat that the user has clicked on be able to be stored into a table within a database. Once the seat has been stored the next user after the previous one isn't allowed to select that particular seat that someone else has picked. I want this to be a looping process for 32 seats on the airplane until the plane is full.
Would I use a While loop for this to work or would I use an If statement and keep on saying ElseIF in my code?
Any Ideas?
for all radio buttons set seat number as text and then assign the same event handler for CheckedChanged event of all radio buttons and write the following code within that event handler.
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, ...
Dim RB As RadioButton = sender
If RB.Checked Then
'write the code to save the seat number i.e. RB.Text to database
End If
End Sub

All elements of an array cannot be accessed from a for loop in monthCalendar Control - Visual Basic

I have a bit of an issue here with the monthCalendar Control in Visual Basic. What is happening in the program is I have a calendar and a text box. The user selects a date on the calendar, then types in information into the textbox component, then presses the add button. From there the add button sets up a parallel array that contains the selected date and the added string from the text box as a way to add planner information for each date. Then the date is bolded for each time an addition like this has happened.
From there you are suppose to be able to click each bolded date and view the information you added. The issue is this only works on the last added date. For some reason it will only read the last element added to the array. I have the for loop down below. I do not understand why I cannot select any bolded date and view the text added. I have option strict on so I know no data loss is occurring. Also I know the date is being selected and placed into the string each time a date is selected on the calendar because I am displaying it onto a label each time. What is the problem. Is it some logical error I am not catching or is it something else?
Public Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MonthCalendar1.DateChanged
For index As Integer = 0 To intSizeOfSelectedDatesAry - 1
strSelectedDay = CStr(MonthCalendar1.SelectionRange.Start) ' place the selected date into a string
lblError.Text = strSelectedDay
lblError.Visible = True
Dim strAryDate As String = arySelectedDates(index)
If (arySelectedDates(index) = strSelectedDay) Then
lblInstructions.Text = strSelectedDay
lblSelectedDate.Text = aryTextForDates(index)
index = intSizeOfSelectedDatesAry - 1
End If
Next
End Sub