Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-25-2015, 12:58 AM
Catty Catty is offline I need help in converting vb code to vba Windows 7 32bit I need help in converting vb code to vba Office 2010 32bit
Advanced Beginner
I need help in converting vb code to vba
 
Join Date: Nov 2013
Posts: 39
Catty is on a distinguished road
Unhappy I need help in converting vb code to vba

Hi...

I need help in converting the below vb code to vba. I have been trying for a while now but i am unable to get the conversion to work 100%.


Quote:
Namespace numberstowords

Public Class NumbersToWords
Private Shared ReadOnly specialNames() As String = { "", " thousand,", " million,", " billion,", " trillion,", " quadrillion,", " quintillion," }

Private Shared ReadOnly tensNames() As String = { "", " ten", " twenty", " thirty", " forty", " fifty", " sixty", " seventy", " eighty", " ninety" }

Private Shared ReadOnly numNames() As String = { "", " one", " two", " three", " four", " five", " six", " seven", " eight", " nine", " ten", " eleven", " twelve", " thirteen", " fourteen", " fifteen", " sixteen", " seventeen", " eighteen", " nineteen" }

Private Shared Function convertLessThanOneThousand(ByVal number As Integer) As String
Dim current As String

If number Mod 100 < 20 Then
current = numNames(number Mod 100)
number \= 100
Else
current = numNames(number Mod 10)
number \= 10

current = tensNames(number Mod 10) & current
number \= 10
End If
If number = 0 Then
Return current
End If
Return numNames(number) & " hundred and" & current
End Function

Public Shared Function convert(ByVal number As Integer) As String

If number = 0 Then
Return "zero"
End If

Dim prefix As String = ""

If number < 0 Then
number = -number
prefix = "negative"
End If

Dim current As String = ""
Dim place As Integer = 0

Do
Dim n As Integer = number Mod 1000
If n <> 0 Then
Dim s As String = convertLessThanOneThousand(n)
current = s & specialNames(place) & current
End If


place += 1
number \= 1000
Loop While number > 0

Return (prefix & current).Trim()
End Function
Public Shared Sub Main(ByVal args() As String)
Dim sc As New Scanner(System.in)
Console.WriteLine("Please enter the amount including R:")
Dim total As String = sc.nextLine()
total = total.Replace(" ", "")
Dim rands As String = total.Substring(1, total.LastIndexOf(",", StringComparison.Ordinal) - 1)
Dim cents As String = total & ""
cents = cents.Substring(cents.LastIndexOf(",", StringComparison.Ordinal)+1)

Dim convertedRands As String = convert(Integer.Parse(rands))
convertedRands = convertedRands & " rand and "
If convertedRands.Contains(", rand") Then
convertedRands = convertedRands.Replace(", rand", " rand")
End If
If convertedRands.Contains("hundred and thousand") Then
convertedRands = convertedRands.Replace("hundred and thousand", "hundred thousand")
End If
If convertedRands.Contains("and rand") AndAlso Not convertedRands.Contains("thousand") Then
convertedRands = convertedRands.Replace("and rand", "rand")
End If
If convertedRands.Contains("hundred and rand") Then
convertedRands = convertedRands.Replace("hundred and rand", "hundred rand")
End If
Dim convertedCents As String = convert(Integer.Parse(cents))

Console.WriteLine("Total = " & total)
Console.WriteLine("Rands = " & rands)
Console.WriteLine("Cents = " & cents)
Console.WriteLine("*** " & convertedRands & convertedCents.Replace(" ", "-") & " cents")
Console.WriteLine("*** " & convert(-55))
End Sub

End Class

End Namespace
Reply With Quote
  #2  
Old 08-25-2015, 03:49 AM
macropod's Avatar
macropod macropod is offline I need help in converting vb code to vba Windows 7 64bit I need help in converting vb code to vba Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

See: http://www.vbaexpress.com/kb/getarticle.php?kb_id=285
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting VBA code to ADO Remster Word VBA 2 02-19-2015 03:04 AM
Pasting image captured with a java program 'on to clipboard' into MSWord 2007 is blur tarunkumarreddy Word 0 02-03-2012 09:42 PM
I need help in converting vb code to vba Converting .npp file TJMSmith Word 1 12-30-2011 01:06 AM
Accessing WLL through Java-COM bridge javageek Word 0 07-05-2010 05:39 PM
How Do I Create Excel Web Pages With Java highbids Office 0 04-13-2006 06:53 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:32 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft