Module CurrencyFormatting Public Function Currency(amount As Double, width As Integer, Optional minus As String = "-") As String ' Ensure width and minus parameters are valid If width <= 0 OrElse minus Is Nothing OrElse String.IsNullOrEmpty(minus) Then Throw New ArgumentException("width must be a positive integer and minus a non-empty string") End If ' Convert amount to a double Dim sign As String Try amount = CDbl(amount) Catch ex As InvalidCastException Throw New InvalidCastException("amount must be a valid number", ex) End Try ' Determine the sign of the amount If amount < 0 Then sign = minus amount = -amount Else sign = New String(" "c, minus.Length) End If ' Format the amount with two decimal places Dim amountStr As String = Math.Abs(amount).ToString("F2") ' If the formatted amount is less than the width, pad with spaces to the left If amountStr.Length < width Then amountStr = New String(" "c, width - amountStr.Length) + amountStr End If ' Format as currency Dim currencyStr As String = "$" + amountStr + sign Return currencyStr End Function Sub Main() ' Example calls to the currency formatting function Dim formattedAmount1 As String = Currency(123.456, 10) Dim formattedAmount2 As String = Currency(-78.9, 12, "NEG") Dim formattedAmount3 As String = Currency(0, 8) ' Output the results Console.WriteLine(formattedAmount1) ' Output: $ 123.46 Console.WriteLine(formattedAmount2) ' Output: $ 78.90NEG Console.WriteLine(formattedAmount3) ' Output: $ 0.00 ' Wait for user input before closing Console.WriteLine("Press any key to exit...") Console.ReadKey() End Sub End Module