Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2009
    Posts
    10

    Question Unanswered: Getting Information in upperCase

    Simple made programme for testing purpose.user take input from 1 to nine.and function convert that numeric number into text like one two ...nine.
    function is working fine .but the number in words is not comming in Upper case.Kindly let me know the idea.any help would be highly appreciated.
    Code:
    Public Function NumberToWords(x As Integer) As String 
      Dim Numbers(9) As String 
         Numbers(1) = "One" 
         Numbers(2) = "Two" 
         Numbers(3) = "Three" 
         Numbers(4) = "Four" 
         Numbers(5) = "Five" 
         Numbers(6) = "Six" 
         Numbers(7) = "Seven" 
         Numbers(8) = "Eight" 
         Numbers(9) = "Nine" 
        Select Case Val(x) 
              Case 1: NumberToWords = "One" 
              Case 2: NumberToWords = "Two" 
              Case 3: NumberToWords = "Three" 
              Case 4: NumberToWords = "Four" 
                      MsgBox (NumberToWords) 
              Case 5: NumberToWords = "Five" 
                      MsgBox (NumberToWords) 
              Case 6: NumberToWords = "Six" 
              Case 7: NumberToWords = "Seven" 
              Case 8: NumberToWords = "Eight" 
              Case 9: NumberToWords = "Nine" 
            Case Else: NumberToWords = "" 
          End Select 
      
    End Function 
    
    
    Private Sub TxtAmount_KeyPress(KeyAscii As Integer) 
    KeyAscii = Asc(UCase(Chr(KeyAscii))) 
    End Sub 
    
    Private Sub TxtAmount_LostFocus() 
    Dim Amount As Integer 
    Amount = Val(TxtAmount.Text) 
    TxtPaymentInWords.Text = NumberToWords(Amount) 
    TxtPaymentInWords.SetFocus 
    End Sub 
    
    
    Private Sub TxtPaymentInWords_KeyPress(KeyAscii As Integer) 
    KeyAscii = Asc(UCase(Chr(KeyAscii))) 
    End Sub

  2. #2
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    First - What about zero???

    The NumberToWords code can be simplified to
    Code:
    Public Function NumberToWords(X As Integer) As String 
      Dim Numbers(9) As String 
    
      Numbers(0) = "Zero"
      Numbers(1) = "One"
      Numbers(2) = "Two"
      Numbers(3) = "Three"
      Numbers(4) = "Four"
      Numbers(5) = "Five"
      Numbers(6) = "Six"
      Numbers(7) = "Seven"
      Numbers(8) = "Eight"
      Numbers(9) = "Nine" 
    
      Select Case  X
    
        Case 0 To 9
          NumberToWords = Numbers(X)
    
        Case Else
          NumberToWords = "" 
    
      End Select 
      
    End Function
    Next. The keypress event happens BEFORE any validation or LostFocus event. You are converting any single character to upper case, but that doesn't affect the number. Then, on the lost focus event, you're converting a number to a text string which represents that number, but you're not converting to upper case THEN. That's where you should convert it, or, if it needs to happen earlier, the earliest possible place you could do so is within the NumberToWords function. Replace
    Code:
    NumberToWords = Numbers(X)
    with
    Code:
    NumberToWords = Ucase(Numbers(X))
    Or, for that matter, use upper case words in the Numbers array. "ONE," "TWO," "THREE," ...
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Why not use a two dimensional array?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •