If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > Getting Information in upperCase

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-08-09, 05:55
firoz.raj firoz.raj is offline
Registered User
 
Join Date: Jan 2009
Posts: 10
Question 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
Reply With Quote
  #2 (permalink)  
Old 08-10-09, 16:15
loquin loquin is offline
Super Moderator
 
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,797
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

Reply With Quote
  #3 (permalink)  
Old 08-14-09, 11:25
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
Why not use a two dimensional array?
__________________
oh yeah... documentation... I have heard of that.

*** What Do You Want In The MS Access Forum? ***
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On