chamsi09

Untitled

Oct 15th, 2024
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.99 KB | None | 0 0
  1. Imports System
  2.  
  3. Module ApplicationValidation
  4.  
  5.     Sub Main()
  6.         ' Input from user
  7.         Console.Write("Enter city of birth: ")
  8.         Dim cityOfBirth As String = Console.ReadLine()
  9.  
  10.         Console.Write("Enter city where birth certificate was issued: ")
  11.         Dim certificateCity As String = Console.ReadLine()
  12.  
  13.         Console.Write("Enter CNAM paper issue date (yyyy-mm-dd): ")
  14.         Dim issueDateInput As String = Console.ReadLine()
  15.         Dim cnamPaperIssueDate As DateTime
  16.  
  17.         ' Validate the entered date
  18.         If DateTime.TryParse(issueDateInput, cnamPaperIssueDate) Then
  19.             ' Call validation method
  20.             ValidateApplication(cityOfBirth, certificateCity, cnamPaperIssueDate)
  21.         Else
  22.             Console.WriteLine("Invalid date format. Please use yyyy-mm-dd.")
  23.         End If
  24.     End Sub
  25.  
  26.     Function ValidateBirthCertificate(cityOfBirth As String, certificateCity As String) As Boolean
  27.         If cityOfBirth.ToLower() <> certificateCity.ToLower() Then
  28.             Console.WriteLine("Application refused because Birth certificate must be issued in the city of birth.")
  29.             Return False
  30.         End If
  31.         Return True
  32.     End Function
  33.  
  34.     Function ValidateCnamPaper(issueDate As DateTime) As Boolean
  35.         Dim sixMonthsAgo As DateTime = DateTime.Now.AddMonths(-6)
  36.         If issueDate < sixMonthsAgo Then
  37.             Console.WriteLine("Application refused because CNAM paper must be issued within the last six months.")
  38.             Return False
  39.         End If
  40.         Return True
  41.     End Function
  42.  
  43.     Sub ValidateApplication(cityOfBirth As String, certificateCity As String, issueDate As DateTime)
  44.         ' Using AndAlso to ensure short-circuiting
  45.         If ValidateBirthCertificate(cityOfBirth, certificateCity) AndAlso ValidateCnamPaper(issueDate) Then
  46.             Console.WriteLine("Application is valid.")
  47.         Else
  48.             Console.WriteLine("Application is not valid.")
  49.         End If
  50.     End Sub
  51.  
  52. End Module
  53.  
Advertisement
Add Comment
Please, Sign In to add comment