1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

VB.net stuff

Discussion in 'Scripting & Programming' started by zxspectrum, Sep 13, 2006.

  1. zxspectrum

    zxspectrum Gigabyte Poster Premium Member

    1,666
    54
    139
    OK folks for a college assignment i have to make a percentage calculator, ive just managed to make a maths one with add , subtract, divide and multiply etc. Now how do i get it so i can just work out 2, 3 and 4 percents, can i just add % into one of the liones of code or is there another way to fo this ?? Please help im not very good at thi:oops: s lol
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  2. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,623
    115
    224
    I don't know VB.net, but in most programming languages the '%' character in an expression means modulo.

    The expression to get a percentage value would be the digits pressed divided by 100.

    So to get 2% of 1000, multiply 1000 by 2/100 - i.e. 0.02

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  3. zxspectrum

    zxspectrum Gigabyte Poster Premium Member

    1,666
    54
    139
    Cheers for that Harry, tho i dont spose you would know how to put that into code would you ??
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  4. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,623
    115
    224
    Er - subtotal_var * (entered_var / 100)
    Or something like that.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  5. zxspectrum

    zxspectrum Gigabyte Poster Premium Member

    1,666
    54
    139
    Harry , a million thanks ill give that a whirl now. Dont spose you want to be my tutor do you , you may as well be, you have been much more use than the one ive got lol
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  6. wizard

    wizard Petabyte Poster

    5,763
    35
    174
    Careful he might charge you £50 an hour for the privilege :D
     
    Certifications: SIA DS Licence
    WIP: A+ 2009
  7. zxspectrum

    zxspectrum Gigabyte Poster Premium Member

    1,666
    54
    139
    Right guys my head is up my bum and tho that may seem a neat trick, believe me its not and its also dark and smelly lol

    Im still struggling with this program.

    Ive sort of tried to modify a code from a book which is as follows
    label3.text = numbers add to: " & str(val(textbox1.tex = val(textbox2.text))

    now doing all that makes a bit of sense to me as it works for one, but i need to make it so that when i click my calculate button i get a percentage score, im trying so that i can enter the amount in textbox 1 and then that it will work out the percentage of the amount depending on the amount of money a user puts in . Example
    1% for up to 50k
    2% for 50 - 100k
    and 3 % for 100k +
    I think in english im trying to say the value if textbox 1 needs to have a percentage worked out ?? Im not doing good here am i lol but i think you get the jist, please help if you can , ive even tried the code above, but with little success as i get build errors????
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  8. zxspectrum

    zxspectrum Gigabyte Poster Premium Member

    1,666
    54
    139
    Right im making a bit of headway here, i can put numbers into the texboxes and when i click on calculate i get true, if all the numbers are the same or false if the numbers are odd, ive also managed to get the result (true/false) to be displayed in the text box whci is what i wanted , so where am i going wrong with the calc button thing , do i amend somthing in proprties, if so where as i cant find anything ????
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  9. phonics3k

    phonics3k Nibble Poster

    97
    1
    32
    Hey zxspectrum,

    I hope this helps you :D

    First of all create a windows forms app and add a button and a textbox, dont change any of the properties and paste the code below in to button1_click event:

    <<< START OF CODE (copy below this line) >>>

    Dim result As Double
    Dim value As Integer

    ' Convert the String to Integer
    value = TextBox1.Text

    If value <= 49999 Then 'If the value is smaller than 49,999 then get 1%
    result = value * 0.01
    ElseIf value >= 50000 And value <= 99999 Then 'Otherwise check that the value is equal or greater than 50,000 and smaller or equal to 99,999 and then get 2%
    result = value * 0.02
    ElseIf value > 99999 Then 'If the value is greater than 99,999 (100,000+) then get 3%
    result = value * 0.03
    End If

    MessageBox.Show("Answer: " & result)

    <<< END OF CODE (stop copying above this line) >>>

    I dont think its the best way of doing it and obviously if you want the calculations to be more precise then change the double to a decimal othwise this works fine.

    You will also find that you can only add whole numbers in the textbox otherwise it will die, if you wanna add numbers with decimals change the Integer to either a double or decimal depending on how precise you wanna be.

    I hope I have been able to answer your questions :D
     
    Certifications: None As Yet
    WIP: MCTS: 70-536 & 70-526
  10. zxspectrum

    zxspectrum Gigabyte Poster Premium Member

    1,666
    54
    139
    Hey Phonics ikll give that a try in a bit, thanks a whole bunch matey, i was getting rather stuck there
     
    Certifications: BSc computing and information systems
    WIP: 70-680

Share This Page

Loading...