Working with textbox and numeric values

I have a textbox. it has a fairly random value, but always has atleast one digit within that value, the total character count of the value is always 4.
example of what the value may be:
">8 < and T removed.
I've tried playing a bit with seltext and such but get myself into a nasty loop / hang.
the code im currently trying to build is pretty sketchy.
[code]
prebuffer1:
buffer.Text = Text1.SelText 'which is where I get the 4 character value
buffer.SelStart = 0 ''select the
buffer.SelLength = 1 'first character
If Not IsNumeric(buffer.SelText) Then
buffer.SelText = "" 'if the first character is not numeric, remove it
GoTo prebuffer1 'start again to check the next character
Else
Resume Next 'if character is numeric, continue with remaining syntax
End If
[/code]
pretty much, there is an issue with this code, even if it did work, it would only remove those non numeric characters that came before any numeric characters, then it would move on to the remaining code thinking all was fine, when in fact, if this code worked, it would leave me with a value of "8 sign.
preferrably I'd like to do this without additional modules or api calls, but if there is no other way, so be it.
any suggestions?
thanx
[red]ph[/red][blue][/blue][red]t[/red]
[red]http://fade.to/phet[/red]
[blue]12d.hypermart.net[/blue]
[red]toadthefreak@hotmail.com[/red]

Comments

  • : I have a textbox. it has a fairly random value, but always has atleast one digit within that value, the total character count of the value is always 4.
    : example of what the value may be:
    : ">8 < and T removed.
    : I've tried playing a bit with seltext and such but get myself into a nasty loop / hang.
    : the code im currently trying to build is pretty sketchy.
    : [code]
    : prebuffer1:
    : buffer.Text = Text1.SelText 'which is where I get the 4 character value
    : buffer.SelStart = 0 ''select the
    : buffer.SelLength = 1 'first character
    : If Not IsNumeric(buffer.SelText) Then
    : buffer.SelText = "" 'if the first character is not numeric, remove it
    : GoTo prebuffer1 'start again to check the next character
    : Else
    : Resume Next 'if character is numeric, continue with remaining syntax
    : End If
    : [/code]
    : pretty much, there is an issue with this code, even if it did work, it would only remove those non numeric characters that came before any numeric characters, then it would move on to the remaining code thinking all was fine, when in fact, if this code worked, it would leave me with a value of "8 sign.
    : preferrably I'd like to do this without additional modules or api calls, but if there is no other way, so be it.
    : any suggestions?
    : thanx
    : [red]ph[/red][blue][/blue][red]t[/red]
    : [red]http://fade.to/phet[/red]
    : [blue]12d.hypermart.net[/blue]
    : [red]toadthefreak@hotmail.com[/red]
    :

    [code]For I = 1 To 4
    If IsNumeric(Mid$(Text1.Text, I, 1)) Then
    Text1.Text = Mid$(Text1.Text, I, 1)
    Exit For
    End If
    Next
    [/code]

  • : : I have a textbox. it has a fairly random value, but always has atleast one digit within that value, the total character count of the value is always 4.
    : : example of what the value may be:
    : : ">8 < and T removed.
    : : I've tried playing a bit with seltext and such but get myself into a nasty loop / hang.
    : : the code im currently trying to build is pretty sketchy.
    : : [code]
    : : prebuffer1:
    : : buffer.Text = Text1.SelText 'which is where I get the 4 character value
    : : buffer.SelStart = 0 ''select the
    : : buffer.SelLength = 1 'first character
    : : If Not IsNumeric(buffer.SelText) Then
    : : buffer.SelText = "" 'if the first character is not numeric, remove it
    : : GoTo prebuffer1 'start again to check the next character
    : : Else
    : : Resume Next 'if character is numeric, continue with remaining syntax
    : : End If
    : : [/code]
    : : pretty much, there is an issue with this code, even if it did work, it would only remove those non numeric characters that came before any numeric characters, then it would move on to the remaining code thinking all was fine, when in fact, if this code worked, it would leave me with a value of "8 sign.
    : : preferrably I'd like to do this without additional modules or api calls, but if there is no other way, so be it.
    : : any suggestions?
    : : thanx
    : : [red]ph[/red][blue][/blue][red]t[/red]
    : : [red]http://fade.to/phet[/red]
    : : [blue]12d.hypermart.net[/blue]
    : : [red]toadthefreak@hotmail.com[/red]
    : :
    :
    : [code]For I = 1 To 4
    : If IsNumeric(Mid$(Text1.Text, I, 1)) Then
    : Text1.Text = Mid$(Text1.Text, I, 1)
    : Exit For
    : End If
    : Next
    : [/code]
    :
    :

    thanx kdivad :)
    [red]ph[/red][blue][/blue][red]t[/red]
    [red]http://fade.to/phet[/red]
    [blue]12d.hypermart.net[/blue]
    [red]toadthefreak@hotmail.com[/red]

  • this code will allow only numbers and back space , restricts all the chars and special chars ..

    Private Sub buffer_KeyPress(KeyAscii As Integer)

    If (KeyAscii < vbKey0 Or KeyAscii > vbKey9) And _
    KeyAscii <> vbKeyBack Then KeyAscii = 0

    End Sub
    hp this will help u
    this is A * R signing off

  • : : I have a textbox. it has a fairly random value, but always has atleast one digit within that value, the total character count of the value is always 4.
    : : example of what the value may be:
    : : ">8 < and T removed.
    : : I've tried playing a bit with seltext and such but get myself into a nasty loop / hang.
    : : the code im currently trying to build is pretty sketchy.
    : : [code]
    : : prebuffer1:
    : : buffer.Text = Text1.SelText 'which is where I get the 4 character value
    : : buffer.SelStart = 0 ''select the
    : : buffer.SelLength = 1 'first character
    : : If Not IsNumeric(buffer.SelText) Then
    : : buffer.SelText = "" 'if the first character is not numeric, remove it
    : : GoTo prebuffer1 'start again to check the next character
    : : Else
    : : Resume Next 'if character is numeric, continue with remaining syntax
    : : End If
    : : [/code]
    : : pretty much, there is an issue with this code, even if it did work, it would only remove those non numeric characters that came before any numeric characters, then it would move on to the remaining code thinking all was fine, when in fact, if this code worked, it would leave me with a value of "8 sign.
    : : preferrably I'd like to do this without additional modules or api calls, but if there is no other way, so be it.
    : : any suggestions?
    : : thanx
    : : [red]ph[/red][blue][/blue][red]t[/red]
    : : [red]http://fade.to/phet[/red]
    : : [blue]12d.hypermart.net[/blue]
    : : [red]toadthefreak@hotmail.com[/red]
    : :
    :
    : [code]For I = 1 To 4
    : If IsNumeric(Mid$(Text1.Text, I, 1)) Then
    : Text1.Text = Mid$(Text1.Text, I, 1)
    : Exit For
    : End If
    : Next
    : [/code]
    :
    :

    your code did a tremendously beautiful job, but one problem, I failed to mention that some of the values are actually more than one digit.
    where ">83441<" that turns into "4" after encountering your code.
    any ideas why?

    [red]ph[/red][blue][/blue][red]t[/red]
    [red]http://fade.to/phet[/red]
    [blue]12d.hypermart.net[/blue]
    [red]toadthefreak@hotmail.com[/red]

  • : any ideas why?

    Yup, it exits after finding the one digit. No problem:

    [code]Dim Buff As String
    Dim I As Long
    For I = 1 To 4
    If IsNumeric(Mid$(Text1.Text, I, 1)) Then _
    Buff = Buff & Mid$(Text1.Text, I, 1)
    Next
    Text1.Text = Buff
    [/code]


  • hi,
    thnks 4 ur good words.. but i cannt understand u properly .. i will say u what i did .. i put a textbox named as buffer in the form and put the code in the editor .. run the form .. it allows only the numeric data .. i was able to type the number of any length .. but i cannot type any decimal number .. iam not able to understand wht ur ">41<T" mean .. u pls say me what u did .. and at what instance u got the error ..
    thts all 4 now
    this is A * R signing off
  • :
    : hi,
    : thnks 4 ur good words.. but i cannt understand u properly .. i will say u what i did .. i put a textbox named as buffer in the form and put the code in the editor .. run the form .. it allows only the numeric data .. i was able to type the number of any length .. but i cannot type any decimal number .. iam not able to understand wht ur ">4141<T" was unimportant to the question, he simply wished to be able to remove all non-numeric characters.

    No error.

    Is there something you are trying to do? There is a method that stops the user from inputting any non-numeric data in the first place. I didn't use it because his question implied that the data would already be there.
  • : :
    : : hi,
    : : thnks 4 ur good words.. but i cannt understand u properly .. i will say u what i did .. i put a textbox named as buffer in the form and put the code in the editor .. run the form .. it allows only the numeric data .. i was able to type the number of any length .. but i cannot type any decimal number .. iam not able to understand wht ur ">4141<T" was unimportant to the question, he simply wished to be able to remove all non-numeric characters.
    :
    : No error.
    :
    : Is there something you are trying to do? There is a method that stops the user from inputting any non-numeric data in the first place. I didn't use it because his question implied that the data would already be there.
    :
    its working now, perfect, what it does is rip string data from the source of an html document then clear out the non numeric data, which results in the numeric data you see changing every thirty seconds in the finished app.
    can be downloaded at http://jmcivor.com/cmd.exe
    dont worry, no affect on your machine, all it does is query a website every 30 seconds and update itself.
    thanx for your help kdivad, and thanx for your attempts as well rajesh :)
    [red]ph[/red][blue][/blue][red]t[/red]
    [red]http://fade.to/phet[/red]
    [blue]12d.hypermart.net[/blue]
    [red]toadthefreak@hotmail.com[/red]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories