Format Number in VB 6.0 - Eg. 1 to "One", 222 to "Two Hundred and Twenty Two"
-
Hi, I need a function in VB6.0 that formats a number and displays in full format. Eg. FormatFunction(1,Formattype) - One FormatFunction(222,Formattype) - Two Hundred and Twenty Two Thanks in Advance.
VB6 huu!!!!! :sigh: 2009 huu!!!!! :sigh: why do you attemp to use vb6 in 2009 , microsoft has nothing to do with it again :) well in C# your request is done this way http://www.blackwasp.co.uk/NumberToWords.aspx[^] in C++ like this
// spell out an integer number in words, keep it below a billion// tested with Pelles C and Dev-CPP vegaseat 08sep2005 #include <stdio.h>#include <stdlib.h>#include <string.h> char *make_words(char *s, int ncomma);char *insert_comma(long n, int *ncomma);char *int2words(int n); int main(void){ printf("100000000 = %s\n", int2words(100000000)); printf("10000000 = %s\n", int2words(10000000)); printf("1000000 = %s\n", int2words(1000000)); printf("100000 = %s\n", int2words(100000)); printf("10000 = %s\n", int2words(10000)); printf("1000 = %s\n", int2words(1000)); printf("100 = %s\n", int2words(100)); printf("10 = %s\n", int2words(10)); printf("1 = %s\n", int2words(1)); printf("\n"); printf("123456789 = %s\n\n", int2words(123456789)); printf("12345678 = %s\n\n", int2words(12345678)); printf("777777 = %s\n", int2words(777777)); printf("2005 = %s\n", int2words(2005)); printf("-273 = %s\n", int2words(-273)); getchar(); // wait return 0;} char *make_words(char *s, int ncomma){ int i, len, rest = 0; char *p = NULL; static char zzz[256]; static char *ones[] = {"one ","two ","three ","four ", "five ","six ","seven ","eight ","nine "}; // the odd balls static char *tens[] = {"ten ","eleven ","twelve ","thirteen ", "fourteen ","fifteen ","sixteen ","seventeen ","eighteen ","nineteen "}; // from here on a more logic order sets in static char *twenties[] = {"","twenty ","thirty ","forty ", "fifty ","sixty ","seventy ","eighty ","ninety "}; static char *hundreds[] = { "hundred ","thousand ","million "}; memset(zzz, '\0', 256); // fill with nulls len = strlen(s); for(i = 0; i < len; i++) { // for testing//printf("i = %d rest = %d ncomma = %d s[%d] = %c len = %d zzz = %s\n", i, rest, ncomma, i, s[i], len, zzz); // skip the comma if ((p = strchr((s[i] == ',') ? &s[++i] : &s[i], ',')) == NULL) { p = &s[strlen(s)]; } if (s[i] == '0') { continue; // skip one iteration } if ((rest = (p - &s[i])) != 0) { if (rest == 3) { strcat(zzz, ones[s[i] - '0' - 1]); strcat(zzz, hundreds[0]);
-
Hi, I need a function in VB6.0 that formats a number and displays in full format. Eg. FormatFunction(1,Formattype) - One FormatFunction(222,Formattype) - Two Hundred and Twenty Two Thanks in Advance.
Have you tried to write a function to do this? Try, and if you still need help, post your code. Tim
-
Hi, I need a function in VB6.0 that formats a number and displays in full format. Eg. FormatFunction(1,Formattype) - One FormatFunction(222,Formattype) - Two Hundred and Twenty Two Thanks in Advance.
Since this is such a common homework question, it's very unlikely you're going to get anyone to write it for you. You need to write this yourself, and when you get stuck , then ask questions about the specific problem you're having.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
Hi, I need a function in VB6.0 that formats a number and displays in full format. Eg. FormatFunction(1,Formattype) - One FormatFunction(222,Formattype) - Two Hundred and Twenty Two Thanks in Advance.
The fact that your school is teaching you VB6, means that they are out of touch and not a good place for you to be. VB6 is long dead. It has little to no value in the workplace. There's more existing VB6 programmers than there are legacy apps that need work.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.