Results 1 to 8 of 8

Thread: Stupid VB Math Question(makes me fea like a newbie)

  1. #1
    Deathfrog
    Guest
    ok, i know its dumb to ask, but how do i take a selected number from a listbox (EG List1.text would have it) and add it to annother listbox number and show the results in a label or textbox? i have been trying at this for about 2 hours now and nothing i have tried has worked.
    Thanx

    EDL, Archarzel

  2. #2
    Banned
    Join Date
    Feb 2001
    Location
    Back to sh*tland
    Posts
    294
    It looks simple, but it seems you are not telling the whole story. Anyway, supposing that the text proprety has only numbers (no spaces):

    Code:
    text1.text=cint(list1.text)+cint(list2.text)
    I think this is it.

  3. #3
    Banned
    Join Date
    Feb 2001
    Location
    Back to sh*tland
    Posts
    294
    Code:
    CCur	Any valid expression to	Currency
    CDbl	Any valid expression to	Double
    CInt	Any valid expression to	Integer
    CLng	Any valid expression to	Long
    CSng	Any valid expression to	Single
    Try other functions if the number isn't integer.

  4. #4
    Deathfrog
    Guest
    well, i tried that, but it does the same thing, just puts in annother umber, 2+2 makes 22.

  5. #5
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Are you sure you used the explicit casting functions the Goodreams mentioned? You are getting a string concatenation rather than an integer addition by the looks of it. The text property contains string data - make sure you cast this to a numeric data type like integer before you add it. Use code just like Goodreams suggested, but with your control names.
    Harry.

    "From one thing, know ten thousand things."

  6. #6
    Hyperactive Member
    Join Date
    Nov 2000
    Location
    Mexico City
    Posts
    306
    Try this:

    text1.text=val(list1.text) + val(list2.text)

    This must work.
    If things were easy, users might be programmers.

  7. #7
    Deathfrog
    Guest
    Allright! it works, thanks

  8. #8
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Shouldn't use val, it isn't local aware, use the functions Goodreams posted.

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