Integer problems :-(

.net , vb6 United States
  • 18 years ago

    How can I do this:


    - Divide a number by two (in a label's caption)
    - And the add it to a label's captions?


    It sound's simple but it just isn't happening


    Any ideas? I suppose it's something like: Label1.caption = label2.caption /2 + label1.caption, but I'm not sure

  • 18 years ago

    dim a as integer
    a = val(label1.caption) / 2


    label2.caption = cstr(val(label1.caption) + a)  


    to be correctly political you must use cstr and val or clng or cint or whatever

  • 18 years ago

    There's a problem, it doesn't take the number away from Label1. Any ideas?

  • 18 years ago

    try attaching everything to a simple variable:


    Dim intNumber as Integer


    intNumber = Label1.caption '// This is what the number to be divided is


    Label1.caption = (intNumber/2) + intNumber


    I am guessing that theres only one label. can you give me a little more in depth look at the structure?


    Hope that helps!

  • 18 years ago

    you seem to be using numbers alot. You've posted a few question's on using integers/numbers and adding/subtracting etc.


    School project?

  • 18 years ago

    I'm making a database to help me understand VB a bit better. I'm quite new to programming but have learnt a lot. Any way...


    Theres a command button, which will take the content of label2 (a number), divide it by two and add it to label1. So its like:


    Label2 / 2 + label1 = Then the answer here.


    But VB always has a trickky little thing to over come .


    Any ideas?

  • 18 years ago

    TIP: Always try and do this and not use just Label1 and let it return a defaul value(.Caption) it will make it harder for you to adapt to .NET if you are going to later on.


    IDEA:
    Assign it to variables.

    Code:

    Dim intNumber as Integer, intAddition as Integer


    intNumber = Label1.Caption
    intAddition = label2.caption


    intnumber = (intnumber/2) + intAddition


    label1.caption = intNumber
    label1.Refresh


    That should work.


    Good Luck!

  • 18 years ago

    Still doesn't work . If it helps, label1 is on a different form (form1).


    So: Label1 is on Form1
         Label2 is on Form2


    it doesn't take the value of label2 (that is divided (/) by 2) from label1.


    Any ideas?

  • 18 years ago

    a=val(label1.caption)/2


    form2.label2.caption = val(label1.caption) + a


  • 18 years ago

    form2.label2.caption = cstr((val(form2.label2.caption)/2) + val(label1.caption))

  • 18 years ago

    Thanks a load!!! I wish I was as good a programmer as you! Lol. Do you know the answer to my other post? The Random number one? Please answer it if you do, this will really help!


    As you can see, integers in VB aren't my strong point! Lol. Thanks!

  • 18 years ago

    kimmy u dont need cstr


    if u want cstr u use:
    form2.label2.caption=str(val(form2.label2.caption)/2 + val(label1.caption))
    else this works anyway
    form2.label2.caption=val(form2.label2.caption)/2 + val(label1.caption)

  • 18 years ago

    Now alpa when u venture onto .NET!! I think Datatypes changes have to be explicitly declared with like cstr() or whatever.  I know you have to in C++, kind of a pain in the butt

  • 18 years ago

    declaring variables, changing variable types, and the like are good programming. VB has this knack of really buggering up programming habits.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“You can stand on the shoulders of giants OR a big enough pile of dwarfs, works either way.”