Results 1 to 13 of 13

Thread: [RESOLVED] Problem with Numbers

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Canada
    Posts
    297

    Resolved [RESOLVED] Problem with Numbers

    I have a number that appears in a text box, but the number sometimes has a decimal...

    Lets say I have the number 2, sometimes it will show up as 2.(then another number)

    Without writing a huge code saying:
    Code:
    If input.Text = 2.1 Then
    output.Text = 2 
    ElseIf input.Text = 2.2 Then
    output.Text = 2
     ' etc, etc, etc, etc, etc, etc, etc... Long!
    End If
    Is there a way I can just take the number, and remove the decimal, and the number after it?

    The number is always different, could be 2, could be 9, could be anyting.

    Thanks for your help!

  2. #2
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Problem with Numbers

    Perhaps you have to write a trillion lines like that to cover all combinations!!!

    Code:
    output.Text = Int(input.Text)
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  3. #3
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Problem with Numbers

    What about this???
    Code:
    Text1.text=left(text1.text,instr(1,text1.text,".")-1)
    Will this help you???

    -Best wishes
    Akhilesh

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  4. #4
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Problem with Numbers

    If you have 2.7 in the textbox, then if you use the code that anhn had posted,
    Code:
    output.Text = Int(input.Text)
    it will give you the result 3

    Am I right, Anhn..???

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  5. #5
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Problem with Numbers

    No, Int() will always show the first integer equal to or less than the value. So Int(2.7) will return 2.

    However, for negative numbers, the integer part gets bigger because, as noted, Int() always returns the integer <= the number. So Int(-2.7) returns -3.

    Fix() is exactly like Int() for positive numbers, but goes the other way for negatives:

    Int(2.7) = 2
    Int(-2.7) = 3
    Fix(2.7) = 2
    Fix(-2.7) = -2

    Fix() can be said to simply strip off the decimal portion of the number.

  6. #6
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Problem with Numbers

    Thanks for clearing it, Ellis...
    VB6 is not installed in this computer, so I was not able to check it... That's why asked that int() problem... Thanks again...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  7. #7
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Problem with Numbers

    A typo there Ellis: Int(-2.7) = -3 as you mentioned above.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  8. #8
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Problem with Numbers

    Quote Originally Posted by akhileshbc
    Thanks for clearing it, Ellis...
    VB6 is not installed in this computer, so I was not able to check it... That's why asked that int() problem... Thanks again...
    Do you have Excel/Word installed on that computer?
    That is common code for VBA/VB6.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  9. #9
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Problem with Numbers

    Do you have Excel/Word installed on that computer?
    That is common code for VBA/VB6.
    No, this is my testing machine....
    Softwares that I had developed will be tested in here....

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Canada
    Posts
    297

    Re: Problem with Numbers

    Thanks so much foer the help guys!

    Heres my code, I'm getting an identifyer error:
    Code:
    Fix (theDoc.selectSingleNode("//value").Text) = ExternalValue.Caption
    I'm loading the number from a XML file, then putting it in a label... It doesnt seem to be working, whats wrong?

    Thanks

  11. #11
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Problem with Numbers

    Externalvalue.Caption=fix(val(thedoc.Selectsinglenode("//value").Text))

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Canada
    Posts
    297

    Re: Problem with Numbers

    Thank you everyone for your help, I have no solved the issue! Works perfectly!

    Thank you!

  13. #13
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: [RESOLVED] Problem with Numbers

    If your problem is solved, then mark the thread as RESOLVED

    -Best wishes
    Akhilesh

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

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