Results 1 to 5 of 5

Thread: Decimal

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Decimal

    Does anyone know what type of character a decimal is? I'm working on something for VB, and I need to allow a text box to accept only numbers, control characters, and decimals, but I can't figure out what a decimal is classified as.

    Thanks.
    Under the Patronage of Leonidas the Lion|Patron of Imperator of Rome - Dewy - Crazyeyesreaper|American and Proud

  2. #2
    ♔KillZoneGB♔'s Avatar Ducenarius
    Join Date
    Jun 2009
    Location
    Gloucester UK
    Posts
    939

    Default Re: Decimal

    a decimal, i would say is a floating Point base 10 number.

    examples

    1. 10.4 = 10 and 4 tenths.
    2. 120 = one hundred and twenty
    3. 0.01 = one hundredth
    System
    OS: Windows 7 Home Premium 64-bit (TBA Win7 Prof)
    Processor: i7 4820K Ivy E @ 4.4Ghz (Mild OC), MB Sabertooth X79
    Memory: Kingston HyperX Fury Red 16GB DDR3-1600 Dual Kit (TBA to 64GB Quad 8X8GB)
    GPU: NVIDIA GTX 670 Phantom (TBA SLI Nvida xxx)
    Water Cooled


  3. #3
    GrnEyedDvl's Avatar Liberalism is a Socially Transmitted Disease
    Artifex Technical Staff

    Join Date
    Jan 2007
    Location
    Denver CO
    Posts
    23,851
    Blog Entries
    10

    Default Re: Decimal

    Use a KeyPress event, like this one:

    Code:
    
    PrivateSub txtOrder_KeyPress(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtOrder.KeyPress
    Dim keyInput AsString = e.KeyChar.ToString()
    If[Char].IsDigit(e.KeyChar) Then
    ' Digits are OK
    ElseIf e.KeyChar = vbBack Then
    'Backspace is OK
    ElseIf e.KeyChar = "."Then
    'Period is OK
    Else
    e.Handled = True
    'cancel input
    EndIf
    EndSub


  4. #4

    Default Re: Decimal

    Ah, so I can define strings with the e.KeyChar? Very nice! Thanks!
    Under the Patronage of Leonidas the Lion|Patron of Imperator of Rome - Dewy - Crazyeyesreaper|American and Proud

  5. #5
    GrnEyedDvl's Avatar Liberalism is a Socially Transmitted Disease
    Artifex Technical Staff

    Join Date
    Jan 2007
    Location
    Denver CO
    Posts
    23,851
    Blog Entries
    10

    Default Re: Decimal

    Quote Originally Posted by Bolkonsky View Post
    Ah, so I can define strings with the e.KeyChar? Very nice! Thanks!
    With that particular event you can. Each event defines specific arguments that can be checked for conditions.

    Thats what this line defines, obviously the part that matters is KeyPressEventArgs and that is assigned to the variable e:
    PrivateSub txtOrder_KeyPress(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs
    The "sender AsObject" part of that line returns the object that called the event as a variable named sender. So for example if you had multiple buttons firing the same event (using AddHandler) then you would know exactly which object called the event, and can then manipulate things based on that object.

    For example, a form with 2 green buttons on it and this code:

    Code:
    
    PrivateSub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click
    MsgBox(sender.name)
    If sender.backcolor = Color.Green Then
    sender.backcolor = Color.Red
    ElseIf sender.backcolor = Color.Green Then
    sender.backcolor = Color.Green
    EndIf
    EndSub


Posting Permissions

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