Public Module Program Public Sub Main(args() As string) Function RupeesToWord(ByVal MyNumber) Dim Temp Dim Rupees, Paisa As String Dim DecimalPlace, iCount Dim Hundreds, Words As String Dim place(9) As String place(0) = " Thousand " place(2) = " Lakh " place(4) = " Crore " place(6) = " Arab " place(8) = " Kharab " On Error Resume Next ' Convert MyNumber to a string, trimming extra spaces. MyNumber = Trim(Str(MyNumber)) ' Find decimal place. DecimalPlace = InStr(MyNumber, ".") ' If we find decimal place... If DecimalPlace > 0 Then ' Convert Paisa Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2) 'Paisa = " and " & ConvertTens(Temp) & " Paisa" 'Paisa = "" if Temp >0 then Paisa = " and " & ConvertTens(Temp) & " Paisa" end if ' Strip off paisa from remainder to convert. MyNumber = Trim(Left(MyNumber, DecimalPlace - 1)) End If '=============================================================== Dim TM As String ' If MyNumber between Rs.1 To 99 Only. TM = Right(MyNumber, 2) If Len(MyNumber) > 0 And Len(MyNumber) <= 2 Then If Len(TM) = 1 Then Words = ConvertDigit(TM) RupeesToWord = "Rupees " & Words & Paisa & " Only" Exit Function Else If Len(TM) = 2 Then Words = ConvertTens(TM) RupeesToWord = "Rupees " & Words & Paisa & " Only" Exit Function End If End If End If '=============================================================== ' Convert last 3 digits of MyNumber to ruppees in word. Hundreds = ConvertHundreds(Right(MyNumber, 3)) ' Strip off last three digits MyNumber = Left(MyNumber, Len(MyNumber) - 3) iCount = 0 Do While MyNumber <> "" 'Strip last two digits Temp = Right(MyNumber, 2) If Len(MyNumber) = 1 Then If Trim(Words) = "Thousand" Or _ Trim(Words) = "Lakh Thousand" Or _ Trim(Words) = "Lakh" Or _ Trim(Words) = "Crore" Or _ Trim(Words) = "Crore Lakh Thousand" Or _ Trim(Words) = "Arab Crore Lakh Thousand" Or _ Trim(Words) = "Arab" Or _ Trim(Words) = "Kharab Arab Crore Lakh Thousand" Or _ Trim(Words) = "Kharab" Then Words = ConvertDigit(Temp) & place(iCount) MyNumber = Left(MyNumber, Len(MyNumber) - 1) Else Words = ConvertDigit(Temp) & place(iCount) & Words MyNumber = Left(MyNumber, Len(MyNumber) - 1) End If Else If Trim(Words) = "Thousand" Or _ Trim(Words) = "Lakh Thousand" Or _ Trim(Words) = "Lakh" Or _ Trim(Words) = "Crore" Or _ Trim(Words) = "Crore Lakh Thousand" Or _ Trim(Words) = "Arab Crore Lakh Thousand" Or _ Trim(Words) = "Arab" Then Words = ConvertTens(Temp) & place(iCount) MyNumber = Left(MyNumber, Len(MyNumber) - 2) Else '================================================================= ' if only Lakh, Crore, Arab, Kharab If Trim(ConvertTens(Temp) & place(iCount)) = "Lakh" Or _ Trim(ConvertTens(Temp) & place(iCount)) = "Crore" Or _ Trim(ConvertTens(Temp) & place(iCount)) = "Arab" Then Words = Words MyNumber = Left(MyNumber, Len(MyNumber) - 2) Else Words = ConvertTens(Temp) & place(iCount) & Words MyNumber = Left(MyNumber, Len(MyNumber) - 2) End If End If End If iCount = iCount + 2 Loop RupeesToWord = "Rupees " & Words & Hundreds & Paisa & " Only" End Function ' Conversion for hundreds '***************************************** Private Function ConvertHundreds(ByVal MyNumber) Dim Result As String ' Exit if there is nothing to convert. If Val(MyNumber) = 0 Then Exit Function ' Append leading zeros to number. MyNumber = Right("000" & MyNumber, 3) ' Do we have a hundreds place digit to convert? If Left(MyNumber, 1) <> "0" Then Result = ConvertDigit(Left(MyNumber, 1)) & " Hundreds " End If ' Do we have a tens place digit to convert? If Mid(MyNumber, 2, 1) <> "0" Then Result = Result & ConvertTens(Mid(MyNumber, 2)) Else ' If not, then convert the ones place digit. Result = Result & ConvertDigit(Mid(MyNumber, 3)) End If ConvertHundreds = Trim(Result) End Function ' Conversion for tens '***************************************** Private Function ConvertTens(ByVal MyTens) Dim Result As String ' Is value between 10 and 19? If Val(Left(MyTens, 1)) = 1 Then Select Case Val(MyTens) Case 10 : Result = "Ten" Case 11 : Result = "Eleven" Case 12 : Result = "Twelve" Case 13 : Result = "Thirteen" Case 14 : Result = "Fourteen" Case 15 : Result = "Fifteen" Case 16 : Result = "Sixteen" Case 17 : Result = "Seventeen" Case 18 : Result = "Eighteen" Case 19 : Result = "Nineteen" Case Else End Select Else ' .. otherwise it's between 20 and 99. Select Case Val(Left(MyTens, 1)) Case 2 : Result = "Twenty " Case 3 : Result = "Thirty " Case 4 : Result = "Forty " Case 5 : Result = "Fifty " Case 6 : Result = "Sixty " Case 7 : Result = "Seventy " Case 8 : Result = "Eighty " Case 9 : Result = "Ninety " Case Else End Select ' Convert ones place digit. Result = Result & ConvertDigit(Right(MyTens, 1)) End If ConvertTens = Result End Function Private Function ConvertDigit(ByVal MyDigit) Select Case Val(MyDigit) Case 1 : ConvertDigit = "One" Case 2 : ConvertDigit = "Two" Case 3 : ConvertDigit = "Three" Case 4 : ConvertDigit = "Four" Case 5 : ConvertDigit = "Five" Case 6 : ConvertDigit = "Six" Case 7 : ConvertDigit = "Seven" Case 8 : ConvertDigit = "Eight" Case 9 : ConvertDigit = "Nine" Case Else : ConvertDigit = "" End Select End Function Public Shared Function changeToWords(ByVal numb As [String]) As [String] Dim val As [String] = "", wholeNo As [String] = numb, points As [String] = "", andStr As [String] = "", pointStr As [String] = "" Dim endStr As [String] = "" Try Dim decimalPlace As Integer = numb.IndexOf(".") If decimalPlace > 0 Then wholeNo = numb.Substring(0, decimalPlace) points = numb.Substring(decimalPlace + 1) If Convert.ToInt32(points) > 0 Then andStr = "point" ' just to separate whole numbers from points pointStr = translateCents(points) End If End If val = [String].Format("{0} {1}{2} {3}", translateWholeNumber(wholeNo).Trim(), andStr, pointStr, endStr) Catch End Try Return val End Function Private Shared Function translateWholeNumber(ByVal number As [String]) As [String] Dim word As String = "" Try Dim beginsZero As Boolean = False 'tests for 0XX Dim isDone As Boolean = False 'test if already translated Dim dblAmt As Double = (Convert.ToDouble(number)) 'if ((dblAmt > 0) && number.StartsWith("0")) If dblAmt > 0 Then 'test for zero or digit zero in a nuemric beginsZero = number.StartsWith("0") Dim numDigits As Integer = number.Length Dim pos As Integer = 0 'store digit grouping Dim place As [String] = "" 'digit grouping name:hundres,thousand,etc... Select Case numDigits Case 1 'ones' range word = ones(number) isDone = True Exit Select Case 2 'tens' range word = tens(number) isDone = True Exit Select Case 3 'hundreds' range pos = (numDigits Mod 3) + 1 place = " Hundred " Exit Select 'thousands' range Case 4, 5, 6 pos = (numDigits Mod 4) + 1 place = " Thousand " Exit Select 'millions' range Case 7, 8, 9 pos = (numDigits Mod 7) + 1 place = " Million " Exit Select Case 10 'Billions's range pos = (numDigits Mod 10) + 1 place = " Billion " Exit Select Case Else 'add extra case options for anything above Billion... isDone = True Exit Select End Select If Not isDone Then 'if transalation is not done, continue...(Recursion comes in now!!) word = translateWholeNumber(number.Substring(0, pos)) + place + translateWholeNumber(number.Substring(pos)) 'check for trailing zeros If beginsZero Then word = " and " & word.Trim() End If End If 'ignore digit grouping names If word.Trim().Equals(place.Trim()) Then word = "" End If End If Catch End Try Return word.Trim() End Function Private Shared Function tens(ByVal digit As [String]) As [String] Dim digt As Integer = Convert.ToInt32(digit) Dim name As [String] = Nothing Select Case digt Case 10 name = "Ten" Exit Select Case 11 name = "Eleven" Exit Select Case 12 name = "Twelve" Exit Select Case 13 name = "Thirteen" Exit Select Case 14 name = "Fourteen" Exit Select Case 15 name = "Fifteen" Exit Select Case 16 name = "Sixteen" Exit Select Case 17 name = "Seventeen" Exit Select Case 18 name = "Eighteen" Exit Select Case 19 name = "Nineteen" Exit Select Case 20 name = "Twenty" Exit Select Case 30 name = "Thirty" Exit Select Case 40 name = "Fourty" Exit Select Case 50 name = "Fifty" Exit Select Case 60 name = "Sixty" Exit Select Case 70 name = "Seventy" Exit Select Case 80 name = "Eighty" Exit Select Case 90 name = "Ninety" Exit Select Case Else If digt > 0 Then name = (tens(digit.Substring(0, 1) & "0") & " ") + ones(digit.Substring(1)) End If Exit Select End Select Return name End Function Private Shared Function ones(ByVal digit As [String]) As [String] Dim digt As Integer = Convert.ToInt32(digit) Dim name As [String] = "" Select Case digt Case 1 name = "One" Exit Select Case 2 name = "Two" Exit Select Case 3 name = "Three" Exit Select Case 4 name = "Four" Exit Select Case 5 name = "Five" Exit Select Case 6 name = "Six" Exit Select Case 7 name = "Seven" Exit Select Case 8 name = "Eight" Exit Select Case 9 name = "Nine" Exit Select End Select Return name End Function Private Shared Function translateCents(ByVal cents As [String]) As [String] Dim cts As [String] = "", digit As [String] = "", engOne As [String] = "" For i As Integer = 0 To cents.Length - 1 digit = cents(i).ToString() If digit.Equals("0") Then engOne = "Zero" Else engOne = ones(digit) End If cts += " " & engOne Next Return cts End Function End Sub End Module
Write, Run & Share VB.net code online using OneCompiler's VB.net online compiler for free. It's one of the robust, feature-rich online compilers for VB.net language, running on the latest version 16. Getting started with the OneCompiler's VB.net compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as VB.net
. OneCompiler also has reference programs, where you can look for the sample code to get started with.
OneCompiler's VB.net online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample VB.net program which takes name as input and prints hello message with your name.
Public Module Program
Public Sub Main(args() As string)
Dim name as String = Console.ReadLine() ' Reading input from STDIN
Console.WriteLine("Hello " & name) ' Writing output to STDOUT
End Sub
End Module
Visual Basic is a event driven programming language by Microsoft, first released in the year 1991.
Variable is a name given to the storage area in order to identify them in our programs.
Simple syntax of Variable declaration is as follows
Dim variableName [ As [ New ] dataType ] [ = initializer ]
variableName = value
If condition-expression Then
'code
End If
If(conditional-expression)Then
'code if the conditional-expression is true
Else
'code if the conditional-expression is false
End If
If(conditional-expression)Then
'code if the above conditional-expression is true
Else If(conditional-expression) Then
'code if the above conditional-expression is true
Else
'code if the above conditional-expression is false
End If
If(conditional-expression)Then
'code if the above conditional-expression is true
If(conditional-expression)Then
'code if the above conditional-expression is true
End If
End If
Select [ Case ] expression
[ Case expressionlist
'code ]
[ Case Else
'code ]
End Select
For counter [ As datatype ] = begin To end [ Step step ]
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ counter ]
For Each element [ As datatype ] In group
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ element ]
While conditional-expression
'Code
[ Continue While ]
'Code
[ Exit While ]
'Code
End While
Do { While | Until } conditional-expression
'Code
[ Continue Do ]
'Code
[ Exit Do ]
'Code
Loop
Do
'Code
[ Continue Do ]
'Code
[ Exit Do ]
'Code
Loop { While | Until } conditional-expression
Procedure is a sub-routine which contains set of statements. Usually Procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
Procedures are of two types.
Functions return a value when they are called.
[accessModifiers] Function functionName [(parameterList)] As returnType
'code
End Function
Sub-procedures are similar to functions but they don't return any value.
Sub ProcedureName (parameterList)
'Code
End Sub