Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Write the following program on VBA: Read the name, customer number and te

ID: 3693757 • Letter: P

Question

Please Write the following program on VBA:

Read the name, customer number and telephone number of customers. All these are strings. The length of the name is 25, of the customer number is 8, and telephone is 13. The format is

            Name: <last name, first name>   (Example :   Davis, Paul)

            Phone: dddddddddd                   (Example: 7878881234)

            Customer No.:    dddddd              (Example: 123456)

After reading customer number, add the characters DS at the beginning. It must be converted to DSdddddd. (Example: DS123456)

The telephone number must be converted to (ddd)ddd-dddd.   (Example: (787)888-1234)

The final result will be displayed as

Customer Name:     ************, ************ (there is a space after comma)

Customer Number: ********              (a total of 8 characters)

Customer Phone Number:   (***)***-**** (a total of 13 characters)

Every sub and function must have a heading. The main sub must have a heading that includes the name of the author, a description of the entire program and the date.   In addition, each function’s heading must include the exact description of the task the function performs and the list of input and output data.

Remark. Use pencil, no pen. Write clearly and sequentially in one column. Your program must look exactly as if it was written on the computer. Use comment sign (‘) to state when you need to state what your next statement will perform.

Please show all steps.

Explanation / Answer


' Get customer name function start here
Function getName$()
' define some varible
' get first name and last name according to cell
Dim name As String
Dim last As String
' concat string
name = Range("A1").Value
last = Range("B1").Value
last = last & ", "
name = last & name
' check string length less then 28 and not
If Len(name) > 28 Then
MsgBox ("Name less then 28. Please try again :-")
End If
' return final value here
getName = name
End Function
' Get customer name function end here
  
' Get phone number function start here
' this function use for get user input (phone number)
Function getPhone$()
' define variable here
Dim phone As String
' get first phone number according to cell
phone = Range("C1").Value
' Check string only number and not
If IsNumeric(phone) Then
' check string length less then 13
If Len(phone) > 13 Then
MsgBox ("Phone less then 13. Please try again :-")
' If string length grater then 13 then call again same function
End If
getPhone = phone
Else
MsgBox ("Please enter valid phone number :-")
End If
End Function
' Get phone number function end here
' Get customer number function start here
Public Function getNumber$()
' define varible here
Dim number1 As String
' get customer number according to cell
number1 = Range("D1").Value
' Check string only number and not
If IsNumeric(number1) Then
' If string length grater then 8 then show message
' if you want change length 8 to 6 then replce 8 with 6
If Len(number1) > 8 Then
' If string length gather then 8 then show message
MsgBox ("Number less then 8. Please try again :-")
  
End If
' return value if customer number right
getNumber = number1
Else
' if string not number then show message and call same function again
MsgBox ("Please enter valid customer number :-")
  
End If
End Function
' Convert phone number function start here
' This function convert phone number in this format (787)888-1234
Public Function myPhone$(ByVal str As String)
'replace if any spacial char find
str = Replace(str, ")", "")
str = Replace(str, "(", "")
str = Replace(str, "-", "")
str = Replace(str, ".", "")
r = Replace(str, Space(1), "")
' convert phone number here
Dim strFormatedNumber As String
strFormatedNumber = "(" & Left(r, 3) & ") " & Right(Left(r, 6), 3) & "-" & Right(r, 4)
' return final value here
myPhone = strFormatedNumber
End Function
' Convert customer number function start here
' This function use for add the characters DS at the beginning customer number
Public Function myNumber$(ByVal number As String)
' define DS variable her
Dim insStr As String
insStr = "DS"
' Add insStr with customer number
myNumber = insStr & number
  
End Function
Sub Main()
'Define some varible
Dim name As String
Dim phone As String
Dim number1 As String
'Call user input function here. one by one. name , phone number, customer number
name = getName()
phone = getPhone()
number1 = getNumber()
  
  
  
'call function for check user input valid and not. also convert phoone in other format
phone = myPhone(phone)
' check number and add DS front of string
number1 = myNumber(number1)
' Add final value.
' Change cell according to your requirement
Range("A5").Value = name
Range("C5").Value = phone
Range("D5").Value = number1
End Sub

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote