Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Format Text & Numbers

Hi all,

I have a problem with userform textbox formatting. The end result of data
entry is to be shown as 01/01234 or BH/014567 the first two characters is a
claim year (can be 01 for 2001etc or BH for really old claim prefix) and the
last 5 numbers are a file number (always 5 numbers).

Presently the code below allows only numbers for all entries. Another problem
is If I enter 01234 it will display as 00/01234, it should display as
01/00234.

Code to date as follows

Private Sub txtInvClaim_AfterUpdate()
With Me.txtInvClaim
.Value = Format(.Value, "00/00000")
End With
End Sub

Private Sub txtInvClaim_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
Dim OKChar As Boolean
OKChar = True
If Len(Me.txtInvClaim.Value) = 7 Then
OKChar = False
Else
Select Case keyascii
Case Asc("0") To Asc("9")
'ok
Case Else
OKChar = False
End Select
End If
If OKChar = False Then
keyascii = 0
'Beep
End If
End Sub

Any help will be greatly appreciated and many thaxs to all

ViViC

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Format Text & Numbers

Not entirely sure how you want to do it but perhaps you can adapt the
following to your needs -

Private Sub TextBox1_Change()
Dim s As String
Static bExit As Boolean

If Not bExit Then
s = Me.TextBox1.Text
s = Replace(s, "/", "")

If Len(s) 2 Then
s = Left$(s, 2) & "/" & Right$("00000" & Mid$(s, 3, Len(s) - 2), 5)
End If

If TextBox1.Text < s Then
bExit = True
TextBox1.Text = s
End If
End If
bExit = False

End Sub

Regards,
Peter T
"ViViC" <u39049@uwe wrote in message news:7b30a8d533ee4@uwe...
Hi all,

I have a problem with userform textbox formatting. The end result of data
entry is to be shown as 01/01234 or BH/014567 the first two characters is

a
claim year (can be 01 for 2001etc or BH for really old claim prefix) and

the
last 5 numbers are a file number (always 5 numbers).

Presently the code below allows only numbers for all entries. Another

problem
is If I enter 01234 it will display as 00/01234, it should display as
01/00234.

Code to date as follows

Private Sub txtInvClaim_AfterUpdate()
With Me.txtInvClaim
.Value = Format(.Value, "00/00000")
End With
End Sub

Private Sub txtInvClaim_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
Dim OKChar As Boolean
OKChar = True
If Len(Me.txtInvClaim.Value) = 7 Then
OKChar = False
Else
Select Case keyascii
Case Asc("0") To Asc("9")
'ok
Case Else
OKChar = False
End Select
End If
If OKChar = False Then
keyascii = 0
'Beep
End If
End Sub

Any help will be greatly appreciated and many thaxs to all

ViViC



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Format Text & Numbers

Peter your great, it worked perfectly and I add the a small cahnge to turn
the text characters into uppercase. The amount of time spent on this has been
huge. Now for some other small problems
Many thanks again

Vic

Peter T wrote:
Not entirely sure how you want to do it but perhaps you can adapt the
following to your needs -

Private Sub TextBox1_Change()
Dim s As String
Static bExit As Boolean

If Not bExit Then
s = Me.TextBox1.Text
s = Replace(s, "/", "")

If Len(s) 2 Then
s = Left$(s, 2) & "/" & Right$("00000" & Mid$(s, 3, Len(s) - 2), 5)
End If

If TextBox1.Text < s Then
bExit = True
TextBox1.Text = s
End If
End If
bExit = False

End Sub

Regards,
Peter T
Hi all,

[quoted text clipped - 37 lines]

ViViC


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200711/1

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Format Text & Numbers

Sorry Peter,
I was testing code when I found I could enter +, -, * in the first two
characters ie BH/ could show as +*/ should be Alpha or numeric. Maybe it
can't be done. Any help would be appreciated

ViViC


ViViC wrote:
Peter your great, it worked perfectly and I add the a small cahnge to turn
the text characters into uppercase. The amount of time spent on this has been
huge. Now for some other small problems
Many thanks again

Vic

Not entirely sure how you want to do it but perhaps you can adapt the
following to your needs -

[quoted text clipped - 27 lines]

ViViC


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200711/1

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Format Text & Numbers

Here's one approach -

Private Sub TextBox1_Change()
Dim i As Long
Dim s As String
Dim ba() As Byte ' byte-array
Static bExit As Boolean

If Not bExit Then
s = UCase(Me.TextBox1.Text)
's = Replace(s, "/", "") ' redundant

ba = s
s = ""
For i = 0 To UBound(ba) Step 2
If ba(i + 1) = 0 Then
Select Case ba(i)
Case 48 To 57
' digits 0-9
s = s & Chr(ba(i))
Case 65 To 90
''letters only in 1st 2 characters
If i <= 3 Then
s = s & Chr(ba(i))
End If
End Select
End If
Next

If Len(s) 1 Then
s = Left$(s, 2) & "/" & Right$("00000" & Mid$(s, 3, Len(s) - 2), 5)
End If

If TextBox1.Text < s Then
bExit = True
TextBox1.Text = s
End If
End If
bExit = False

End Sub

There's a simple one-liner to "input-mask" to ensure only letters or numbers
with use of RegExp (regular expressions), trouble is it would take me at
least an hour to re-learn the correct syntaxt! I find the byte array method
easy to understand and adapt. As written, user can only input letters or
numbers in first two places, but last five must be numbers only. FYI, if the
string is say "AB" the array will fill with values 65,0,66,0 and hence the
loop with step one with check the subsequent byte in the loop is zero.

I'd be tempted to change the Right$("00000" to "-----", or "?????" then in
the AfterUpdate event (or any routine that later extacts the user input)
replace - or ? with 0.

Regards,
Peter T


"ViViC via OfficeKB.com" <u39049@uwe wrote in message
news:7b3d6516d259d@uwe...
Sorry Peter,
I was testing code when I found I could enter +, -, * in the first two
characters ie BH/ could show as +*/ should be Alpha or numeric. Maybe it
can't be done. Any help would be appreciated

ViViC


ViViC wrote:
Peter your great, it worked perfectly and I add the a small cahnge to

turn
the text characters into uppercase. The amount of time spent on this has

been
huge. Now for some other small problems
Many thanks again

Vic

Not entirely sure how you want to do it but perhaps you can adapt the
following to your needs -

[quoted text clipped - 27 lines]

ViViC


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200711/1





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Format Text & Numbers

Hi Peter,

Works at treat, I have only used VBA for a short time and have always had
trouble understanding array's but I will have sometime up my sleeve in next
week or so. I have been involved in using Access for comparing old payroll
system to new payroll system results which is now live. Just thrown in the
deep end. This is not my normal work programming (Insurance Claims etc is), a
very fast learning curve which is great for me. This project is but a small
part of a very large govt project.

All I can say many thanks for your work & time, it is greatly appreciated

ViVic

Peter T wrote:
Here's one approach -

Private Sub TextBox1_Change()
Dim i As Long
Dim s As String
Dim ba() As Byte ' byte-array
Static bExit As Boolean

If Not bExit Then
s = UCase(Me.TextBox1.Text)
's = Replace(s, "/", "") ' redundant

ba = s
s = ""
For i = 0 To UBound(ba) Step 2
If ba(i + 1) = 0 Then
Select Case ba(i)
Case 48 To 57
' digits 0-9
s = s & Chr(ba(i))
Case 65 To 90
''letters only in 1st 2 characters
If i <= 3 Then
s = s & Chr(ba(i))
End If
End Select
End If
Next

If Len(s) 1 Then
s = Left$(s, 2) & "/" & Right$("00000" & Mid$(s, 3, Len(s) - 2), 5)
End If

If TextBox1.Text < s Then
bExit = True
TextBox1.Text = s
End If
End If
bExit = False

End Sub

There's a simple one-liner to "input-mask" to ensure only letters or numbers
with use of RegExp (regular expressions), trouble is it would take me at
least an hour to re-learn the correct syntaxt! I find the byte array method
easy to understand and adapt. As written, user can only input letters or
numbers in first two places, but last five must be numbers only. FYI, if the
string is say "AB" the array will fill with values 65,0,66,0 and hence the
loop with step one with check the subsequent byte in the loop is zero.

I'd be tempted to change the Right$("00000" to "-----", or "?????" then in
the AfterUpdate event (or any routine that later extacts the user input)
replace - or ? with 0.

Regards,
Peter T

Sorry Peter,
I was testing code when I found I could enter +, -, * in the first two

[quoted text clipped - 15 lines]

ViViC


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200711/1

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I format numbers as text Brenda Excel Worksheet Functions 2 January 19th 10 01:54 AM
format text to numbers Davidm Excel Discussion (Misc queries) 1 June 23rd 09 12:23 PM
Convert numbers from text format to number format merlin68 Excel Discussion (Misc queries) 7 June 20th 07 07:03 PM
Format text to numbers Jamesy Excel Discussion (Misc queries) 3 January 10th 06 07:06 PM
How do i change numbers in text format to number format? Greg New Users to Excel 1 December 14th 04 05:22 PM


All times are GMT +1. The time now is 07:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"