This is for James Stillman

James on my last question, when all was said and done I ended up using your code but had already gave the points to someone else. I thought I'd ask you just a little more about it and grant you some points. Here is the code you posted.....

This might be a little simpler than using a class and plus it lets you delete a decimal point and then re-enter the decimal point. If you want to reset the textBox you will have to make blDecimal Global to the form and reset it's value to false once the textbox is cleared.

Private Sub Text1_KeyPress(KeyAscii As Integer)
Static blDecimal As Boolean
Dim cValid As String
cValid = "0123456789"
If InStr(cValid, Chr(KeyAscii)) = 0 _
    And KeyAscii <> 32 And KeyAscii <> 8 Then
        If KeyAscii = 46 And blDecimal = False Then  'Check to see if the flag is set to true
            blDecimal = True
        Else
            KeyAscii = 0
        End If
Else
    If Len(Text1.Text) > 0 Then _
    If KeyAscii = 8 And blDecimal = True And Asc(Mid(Text1.Text, Len(Text1.Text))) = 46 Then blDecimal = False
End If
End Sub



'The extra check for char (8) is to look for the delete key Because your users may want to delete the decimal point they have inserted you can delete this if you wish.


I've tested this and it works.

Hope this is of some help

Cheers

James

The line about the global thing and resetting it to false...could you show me this in code??? I ran into a problem while checking error-control. If the users discovers they typed something in wrong and goes back to the specific textbox to re-type something then the decimal no longer works and it kicks out an error. I figure this is what you were referring to when you said make it global. Example????
seeshelleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

James_stillmanCommented:
Right then seeShelle I have reWritten the code completly for you. This time it allows the user to cut and paste into the text box and you do not need to do anything to it. Sorry about the slightly bigger function if the user enters incorrect data then the textbox flickers slightly. But I thought this might be a good way of showing that the text entered was incorrct. It took me a while to write for you but give it a go.

Any questions then write again.

Just paste this code into a project for an example and then place a textBox onm hte form.

Option Explicit

Private strTemp As String

'I had to put this in because if the user wants to cut and paste into the textBox
'Using the right mouse click then it will not fire the keyPress Validation
Private Sub Text1_Change()
    CheckChangedText Text1
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
    strTemp = Text1.Text
End Sub


Private Sub CheckChangedText(textBoxIn As TextBox)
Dim inttemp As Integer
Dim intCount As Integer
Dim intDecimalCount As Integer
Dim cValid As String
cValid = "0123456789 ."

intCount = 0
inttemp = 1
intDecimalCount = 0
If Len(textBoxIn.Text) > 0 Then
    For intCount = 1 To Len(textBoxIn.Text)
        If InStr(cValid, Mid(textBoxIn.Text, intCount, 1)) = 0 Then
            textBoxIn = strTemp
            Exit Sub
        End If
    Next
    Do
    intCount = InStr(inttemp, textBoxIn.Text, Chr(46), vbTextCompare)
    If intCount > 0 Then
        intDecimalCount = intDecimalCount + 1
        inttemp = intCount + 1
    End If
    If intDecimalCount > 1 Then
        textBoxIn.Text = strTemp
        Exit Do
    End If
    Loop While intCount <> 0
End If
Text1.SelLength = 1
Text1.SelStart = Len(Text1.Text)
End Sub


Cheers

James
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
James_stillmanCommented:
Sorry seeShelle Please can you replace the following in the checkChangedText sub:

Text1.SelLength = 1
Text1.SelStart = Len(Text1.Text)

with:

textBoxIn.SelLength = 1
 textBoxIn.SelStart = Len(Text1.Text)
strTemp = textBoxIn.text

Cheers

James ;^)
0
James_stillmanCommented:
PS:
Maybe you want to get togehter sometime you know ...a few beers...a night out then maybe back to mine for ...ahem...coffee if you know what im getting at.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

crazymanCommented:
James i dont think this is a sex site you know...jeez some people
0
James_stillmanCommented:
And Maybe a sorry again Seeshelle.

I would have to explain that I have a bit of a competitive, jealous workmate in work who I have the unfortunate situation of sharing an office with. Every now and again when I forget to lock up my computer he will access it and perform his juvenile little tricks in an attempt to belittle everything that I do in work.

 In a minute, Because he is just reading this you will probably get some ridiculous schol boy comment posted onto the question. I would like to teach him a little lesson, and think I will soon.

I'm sorry that he has intruded into the question but it seems that he has very little to do in work at the moment other than, look over my shoulder at what i'am doing and play little pranks.

if you want a little bit of proof that he is in the same office it will cost 7 points but is at.

http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10290235 

Ok. Just one thing for you Richard(Crazyman). ---BURN IN HELL-- :6<

Cheers

James

0
seeshelleAuthor Commented:
James,
    The cut and paste option would not be neccessary for this program. Just wanted it where if for some stupid reason (we call him Brian) he screws up and needs to go back to one of the textboxes and change his information, then it is possible without causing errors.
0
James_stillmanCommented:
Yep.

But the only Problem Being That If Brian wanted to paste text into the textBox we can easily stop him pressing ctrl+v but we cannot so easily stop him right mouse clicking and pasting from there. Hence I figured this method would be safer.

However if You just want the Groovy function that I wrote Back with changes. Now it has been Changed so you can just Use it Straight.

Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim blDecimal As Boolean
Dim cValid As String
cValid = "0123456789"
If InStr(1, Text1.Text, Chr(46), vbTextCompare) Then blDecimal = True Else blDecimal = False
If InStr(cValid, Chr(KeyAscii)) = 0 _
    And KeyAscii <> 32 And KeyAscii <> 8 And KeyAscii <> 22 Then
    If KeyAscii = 46 And blDecimal = False Then  'Check to see if the flag is set to true
        blDecimal = True
    Else
        KeyAscii = 0
    End If
End If
End Sub


I Hope this is OK.........

And Brian Doesn't Break It


Cheers

James   ;^)
0
seeshelleAuthor Commented:
Thank you James
     This gives me two options to work with now. I'll just have to play with it. Tell you friend that I'm way to old for his advances!!! I do enjoy a beer and cup of coffee on occasion though!! Thanks again for all your help! I'll probably hear from you on occasion. Good Luck with you little pest!
0
crazymanCommented:
James you stilll around????
0
crazymanCommented:
Hello
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.