Click here to Skip to main content
15,886,919 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Object/Structure References Pin
Ed Hill _5_30-Jul-09 6:33
Ed Hill _5_30-Jul-09 6:33 
GeneralRe: Object/Structure References Pin
Johan Hakkesteegt30-Jul-09 21:28
Johan Hakkesteegt30-Jul-09 21:28 
AnswerRe: Object/Structure References Pin
Dave Kreskowiak30-Jul-09 2:19
mveDave Kreskowiak30-Jul-09 2:19 
AnswerRe: Object/Structure References Pin
Ed Hill _5_31-Jul-09 0:27
Ed Hill _5_31-Jul-09 0:27 
Questionhow to search for a word in a book programmatically in dot net? Pin
tadeze29-Jul-09 3:18
tadeze29-Jul-09 3:18 
AnswerRe: how to search for a word in a book programmatically in dot net? Pin
Johan Hakkesteegt29-Jul-09 3:41
Johan Hakkesteegt29-Jul-09 3:41 
QuestionFormat Number in VB 6.0 - Eg. 1 to "One", 222 to "Two Hundred and Twenty Two" Pin
CPK_201129-Jul-09 1:57
CPK_201129-Jul-09 1:57 
AnswerRe: Format Number in VB 6.0 - Eg. 1 to "One", 222 to "Two Hundred and Twenty Two" Pin
Vimalsoft(Pty) Ltd29-Jul-09 2:14
professionalVimalsoft(Pty) Ltd29-Jul-09 2:14 
VB6 huu!!!!! Sigh | :sigh: 2009

huu!!!!! Sigh | :sigh:

why do you attemp to use vb6 in 2009 , microsoft has nothing to do with it again Smile | :) 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]);        // special cases        if (len == 7 && s[2] == '0')  strcat(zzz, hundreds[1]);        if (len == 11 && s[2] == '0')  strcat(zzz, hundreds[2]);      }      else if (rest == 2)       {        if (s[i] == '1')        {          strcat(zzz, tens[s[++i] - '0']);          rest--;        }        else        {          strcat(zzz, twenties[s[i] - '0' - 1]);        }      }      else        strcat(zzz, ones[s[i] - '0' - 1]);    }    if (rest == 1 && ncomma != 0)    {      strcat(zzz, hundreds[ncomma--]);    }  }  return zzz;} // insert a comma every third place from right to help in make_words// returns the modified numeric string and the number of commaschar *insert_comma(long n, int *ncomma){  static char zzz[30];  int i = 0;  char *p = &zzz[sizeof(zzz)-1];   *p = '\0';  *ncomma = 0;  do   {    if (i % 3 == 0 && i != 0)     {      *--p = ',';      ++*ncomma;    }     *--p = (char)('0' + n % 10);    n /= 10;    i++;  } while(n != 0);  return p;} char *int2words(int n){  int nc;  char *ps, *zzz, *minus;  char *buffer;  buffer = (char *) malloc(256);   // save any - sign  if (n < 0)  {    minus = "minus";    n = abs(n);  }  else  {    minus = "";  }   ps = insert_comma(n, &nc);  // ps is the comma modified numeric string, nc is the number of commas  zzz = make_words(ps, nc);   // if there was a - sign add it back  sprintf(buffer,"%s %s", minus, zzz);   return buffer;}// 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]);
        // special cases
        if (len == 7 && s[2] == '0')  strcat(zzz, hundreds[1]);
        if (len == 11 && s[2] == '0')  strcat(zzz, hundreds[2]);
      }
      else if (rest == 2) 
      {
        if (s[i] == '1')
        {
          strcat(zzz, tens[s[++i] - '0']);
          rest--;
        }
        else
        {
          strcat(zzz, twenties[s[i] - '0' - 1]);
        }
      }
      else
        strcat(zzz, ones[s[i] - '0' - 1]);
    }
    if (rest == 1 && ncomma != 0)
    {
      strcat(zzz, hundreds[ncomma--]);
    }
  }
  return zzz;
}

// insert a comma every third place from right to help in make_words
// returns the modified numeric string and the number of commas
char *insert_comma(long n, int *ncomma)
{
  static char zzz[30];
  int i = 0;
  char *p = &zzz[sizeof(zzz)-1];
  
  *p = '\0';
  *ncomma = 0;
  do 
  {
    if (i % 3 == 0 && i != 0) 
    {
      *--p = ',';
      ++*ncomma;
    }
     *--p = (char)('0' + n % 10);
    n /= 10;
    i++;
  } while(n != 0);
  return p;
}

char *int2words(int n)
{
  int nc;
  char *ps, *zzz, *minus;
  char *buffer;
  buffer = (char *) malloc(256);

  // save any - sign
  if (n < 0)
  {
    minus = "minus";
    n = abs(n);
  }
  else
  {
    minus = "";
  }

  ps = insert_comma(n, &nc);
  // ps is the comma modified numeric string, nc is the number of commas
  zzz = make_words(ps, nc);

  // if there was a - sign add it back
  sprintf(buffer,"%s %s", minus, zzz);

  return buffer;
}


Good luck

Vuyiswa Maseko,

Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."

C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/

AnswerRe: Format Number in VB 6.0 - Eg. 1 to "One", 222 to "Two Hundred and Twenty Two" Pin
Tim Carmichael29-Jul-09 2:54
Tim Carmichael29-Jul-09 2:54 
AnswerRe: Format Number in VB 6.0 - Eg. 1 to "One", 222 to "Two Hundred and Twenty Two" Pin
Dave Kreskowiak29-Jul-09 3:54
mveDave Kreskowiak29-Jul-09 3:54 
AnswerRe: Format Number in VB 6.0 - Eg. 1 to "One", 222 to "Two Hundred and Twenty Two" Pin
Christian Graus29-Jul-09 10:51
protectorChristian Graus29-Jul-09 10:51 
QuestionHolding collections in memory, good or bad idea? Pin
Jay Royall28-Jul-09 22:34
Jay Royall28-Jul-09 22:34 
AnswerRe: Holding collections in memory, good or bad idea? Pin
Mycroft Holmes28-Jul-09 23:32
professionalMycroft Holmes28-Jul-09 23:32 
GeneralRe: Holding collections in memory, good or bad idea? Pin
Jay Royall28-Jul-09 23:40
Jay Royall28-Jul-09 23:40 
GeneralRe: Holding collections in memory, good or bad idea? Pin
Ed Hill _5_29-Jul-09 5:05
Ed Hill _5_29-Jul-09 5:05 
GeneralRe: Holding collections in memory, good or bad idea? Pin
Jay Royall29-Jul-09 5:15
Jay Royall29-Jul-09 5:15 
GeneralRe: Holding collections in memory, good or bad idea? Pin
Mycroft Holmes29-Jul-09 14:04
professionalMycroft Holmes29-Jul-09 14:04 
QuestionHow to Import only table wiht out data in sql server 2000 Pin
rajesh_ncc28-Jul-09 20:29
rajesh_ncc28-Jul-09 20:29 
AnswerRe: How to Import only table wiht out data in sql server 2000 Pin
Christian Graus28-Jul-09 21:47
protectorChristian Graus28-Jul-09 21:47 
AnswerRe: How to Import only table wiht out data in sql server 2000 Pin
Mycroft Holmes28-Jul-09 23:33
professionalMycroft Holmes28-Jul-09 23:33 
QuestionHow to Differentiate inputs coming from 2 USB RF ID / USB Keyboard Pin
hermawan.solihin28-Jul-09 17:43
hermawan.solihin28-Jul-09 17:43 
AnswerRe: How to Differentiate inputs coming from 2 USB RF ID / USB Keyboard Pin
Dave Kreskowiak29-Jul-09 1:45
mveDave Kreskowiak29-Jul-09 1:45 
AnswerRe: How to Differentiate inputs coming from 2 USB RF ID / USB Keyboard Pin
Luc Pattyn29-Jul-09 2:15
sitebuilderLuc Pattyn29-Jul-09 2:15 
AnswerRe: How to Differentiate inputs coming from 2 USB RF ID / USB Keyboard Pin
DJ Matthews29-Jul-09 3:09
DJ Matthews29-Jul-09 3:09 
GeneralRe: How to Differentiate inputs coming from 2 USB RF ID / USB Keyboard Pin
hermawan.solihin29-Jul-09 17:26
hermawan.solihin29-Jul-09 17:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.