Results 1 to 10 of 10

Thread: trimming a number

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118

    Question

    I am making an inventory program and the numbers entered will be of varying lengths. I need to remove the last two digits on the right of the number, but can't use the Left function since the length of the numbers will change over time.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I don't think theres a problem with that:
    Code:
    var=left(var,len(var)-2)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Guest

    Thumbs up Ok this ones easy

    If using vb 5 or 6 then use the Right function.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Jethro, are you sure that's a good idea?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Guest

    Of course

    The Right function works fine if you know the exact number of characters you want to extract. If a fraction maybe a string extract based around the point, this allows variable character extraction.

    Am using vb5, so don't know if any bad effects in 4 or below, and am waiting to complete work today at this site to load 6. But persumably the Right function works the same in 6 as it does in 5.

    Why have you found a problem with it?

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    It wont solve his problem:
    123456 -> 1234
    not
    3456

    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118

    why?

    If I do this and put in 12345, it returns 1234.
    Private Sub Command1_Click()
    Dim Var
    Var = Text1.Text
    Var = Left(Var, Len(Var) - 2)
    Text2.Text = Var
    End Sub

    This will return 123, what I want.
    Private Sub Command1_Click()
    Dim Var
    Var = Val(Text1.Text)
    Var = Left(Var, Len(Var) - 2)
    Text2.Text = Val(Var)
    End Sub
    Am I doing the Val() right? I only need whole numbers.

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    so that's what you want:
    Code:
    Text2.Text=int(text1.text/100)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9
    Guest

    Thumbs up Ok this is confused

    You stated you wanted to extract the last two digits, are you really saying you want to extract the full amount excluding the fractions

    If so the data would be something like

    1234.56

    In vb6 use the split function in vb5 use instr and mid functions, or kedamans approach.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118

    Thanks Kedaman

    Thank you, both ways will work for me. Sorry for the confusing wording. I should have gave an example.

Posting Permissions

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



Click Here to Expand Forum to Full Width