Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Format Number in VB 6.0 - Eg. 1 to "One", 222 to "Two Hundred and Twenty Two"

Format Number in VB 6.0 - Eg. 1 to "One", 222 to "Two Hundred and Twenty Two"

Scheduled Pinned Locked Moved Visual Basic
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CPK_2011
    wrote on last edited by
    #1

    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.

    V T D C 4 Replies Last reply
    0
    • C CPK_2011

      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.

      V Offline
      V Offline
      Vimalsoft Pty Ltd
      wrote on last edited by
      #2

      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]);

      1 Reply Last reply
      0
      • C CPK_2011

        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.

        T Offline
        T Offline
        Tim Carmichael
        wrote on last edited by
        #3

        Have you tried to write a function to do this? Try, and if you still need help, post your code. Tim

        1 Reply Last reply
        0
        • C CPK_2011

          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.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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...

          1 Reply Last reply
          0
          • C CPK_2011

            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.

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups