Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change the Code in Visual Basic

Status
Not open for further replies.

Saif_Abc

IS-IT--Management
Apr 7, 2021
27
AE
Hi All,

Can somebody translate this VFP code into Visual Basic, I want to apply this in Microsoft Excel.

Code:
*********************************************************
** Author   : Ramani (Subramanian.G)
**           Â FoxAcc Software / Winners Software
**            [URL unfurl="true"]www.winnersoft.coolfreepages.com[/URL]
** Type    Â : Freeware with reservation to Copyrights
** Warranty : Nothing implied or explicit
** Last modified : June, 2003
*********************************************************
** How to Run..
** 1. Save the following code as Num2Word.PRG
** 2. From within your PRG or Report call it as
** Â Â Â Num2Word(nYourAmount)
*********************************************************
** Modify decimal places suitably, if > 2 decimals required
*********************************************************
** FUNCTION num2word
LPARAMETER amt
amt = ABS(amt)

IF amt > 999999999999.99 && => 1000 billion
   =MESSAGEBOX("Amount exceeds word convertion provision. Contact system administrator", ;
      0+16, "CAUTION. Check total amount !")
ENDIF
IF amt = 0 
   RETURN "Zero Only."
ENDIF

** used by Function numWord
PRIVATE pcWord1, pcWord2, pcWord3, pcWord4, pcWord5, pcWord6, pcWord7, ;
   pcWord8, pcWord9, pcWord10, pcWord11, pcWord12, pcWord13, pcWord14, ;
   pcWord15, pcWord16, pcWord17, pcWord18, pcWord19, pcWord20, pcWord30, ;
   pcWord40, pcWord50, pcWord60, pcWord70, pcWord80, pcWord90
pcWord1 = "One "
pcWord2 = "Two "
pcWord3 = "Three "
pcWord4 = "Four "
pcWord5 = "Five "
pcWord6 = "Six "
pcWord7 = "Seven "
pcWord8 = "Eight "
pcWord9 = "Nine "
pcWord10 = "Ten "
pcWord11 = "Eleven "
pcWord12 = "Twelve "
pcWord13 = "Thirteen "
pcWord14 = "Fourteen "
pcWord15 = "Fifteen "
pcWord16 = "Sixteen "
pcWord17 = "Seventeen "
pcWord18 = "Eighteen "
pcWord19 = "Ninteen "
pcWord20 = "Twenty "
pcWord30 = "Thirty "
pcWord40 = "Forty "
pcWord50 = "Fifty "
pcWord60 = "Sixty "
pcWord70 = "Seventy "
pcWord80 = "Eighty "
pcWord90 = "Ninety "
**
LOCAL lcNumPhrase, lcNumStr

m.lcNumphrase = ""
m.lcNumStr = STR(amt,17,4)

IF VAL(SUBSTR(m.lcNumStr,1,3)) > 0    && Amount in Billions
   m.lcNumphrase = m.lcNumphrase + Numword(SUBSTR(m.lcNumStr,1,3)) + ;
      " Billion "
ENDIF

IF VAL(SUBSTR(m.lcNumStr,4,3)) > 0     && Amount in millions
   m.lcNumphrase = m.lcNumphrase + Numword(SUBSTR(m.lcNumStr,4,3)) + ;
      " Million "
ENDIF

IF VAL(SUBSTR(m.lcNumStr,7,3)) > 0    && Amount in thousands
   m.lcNumphrase = m.lcNumphrase + Numword(SUBSTR(m.lcNumStr,7,3)) + ;
      " Thousand "
ENDIF

IF VAL(SUBSTR(m.lcNumStr,10,3)) > 0    && Amount below thousands
   m.lcNumphrase = m.lcNumphrase + Numword(SUBSTR(m.lcNumStr,10,3))
ENDIF

IF VAL(SUBSTR(m.lcNumStr,14,2)) > 0    && Amount in Decimals
    ** needs tingering depending on digits - Default is 2 decimals
   IF LEN(ALLTRIM(m.lcNumphrase)) > 1
      m.lcNumphrase = ALLTRIM(m.lcNumphrase) + " and "
   ELSE
      m.lcNumphrase = "Zero and "
   ENDIF
   m.lcNumphrase = m.lcNumphrase + SUBSTR(m.lcNumStr,14,2) + "/100"
ENDIF

IF LEN(ALLTRIM(m.lcNumphrase)) > 1
   m.lcNumphrase = ALLTRIM(m.lcNumphrase) + " Only."
ENDIF

RETURN m.lcNumphrase
*********************************************************
** Called by: numtoword() (function  in NUMWORD.PRG)
*********************************************************
FUNCTION numword
   LPARAMETERS tStr

   LOCAL lnStr, lcPhrase, lcStr
   lcPhrase = " "
   lnStr = VAL(tStr)

   ** Hundredth position
   IF lnStr > 99
      lcStr = LEFT(tStr,1)
      lcPhrase = pcWord&lcStr + "Hundred "
   ENDIF

   ** Balance Position
   lnStr = VAL(RIGHT(tStr,2))
   IF BETWEEN(lnStr,1,20)
      lcStr = ALLTRIM(STR(lnStr))
      lcPhrase = lcPhrase + pcWord&lcStr
   ENDIF
   IF BETWEEN(lnStr,21,99)
      IF lnStr > 20
         lcStr = SUBSTR(tStr,2,1)+"0"
         lcPhrase = lcPhrase + pcWord&lcStr 
      ENDIF
      IF RIGHT(tStr,1) > '0'
         lcStr = RIGHT(tStr,1)
         lcPhrase = lcPhrase + pcWord&lcStr 
      ENDIF
   ENDIF   
   RETURN ALLTRIM(lcPhrase)
*********************************************************
* EOF: NUM2WORD.PRG
*********************************************************

Thanks

Saif
 
You may have a better luck asking your question in forum707, but don't be surprised if TT members will help you one step at the time, where most of the work will be done by you.

You can also check how to Convert numbers into words

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top