Question Formatting & converting DATES

jjstccean

New member
Joined
Nov 3, 2017
Messages
1
Programming Experience
Beginner
I'm new to VB.net coming from MS-Access and need help with this problem: I'm keeping a list of people phoning me and I'm hoping to generate a "CallNumber" with text coming from a FirstName And LastName respectively. I'm faced with a CAST DATE problems - any assistance will be greatly appreciated. Thank you.

THIS IS HOW I've DONE IT IN ACCESS.

Private Sub LastName_Exit(Cancel As Integer)
    If Me.LastName = "" Then
        Exit Sub
    Else
        Me.ClientNo.SetFocus
        Me.ClientNo = Left(Me.FirstName, 1) & Left(Me.LastName, 1) & Format(Me.ContactDate, "ddmmyyyy")
        Me.BusAddress.SetFocus
    End If
End Sub

VB.NET
    Private Sub dtPhoned_Leave(sender As Object, e As EventArgs) Handles dtPhoned.Leave
        Dim nameF As String = txtFirstName.Text
        Dim nameL As String = txtLastName.Text
        txtCallNumber.Text = Microsoft.VisualBasic.Left(nameF, 1) + Microsoft.VisualBasic.Left(nameL, 1) + dtPhoned.ToString("ddmmyyyy")
    End Sub
 
Last edited by a moderator:
m is minute, M is month: Custom Date and Time Format Strings | Microsoft Docs

Other tips: You can also use nameF.Substring(0, 1), thought string need to be at least given length, but maybe that should be validated first anyway - or txtFirstName.Text.Substring(0, 1) if you don't need to reuse the nameF variable. The variable type in such case can also be inferred; Dim nameF = "some string".
 
Back
Top