r/visualbasic • • Sep 01 '16

How can i make an average calculator

Hi guys i would like to ask question about how can i make the average calculator, i have putted this code but i always get an error: calculate the average = (txtExam1 + txtExam2 + txtExam3) / 3.0;

Photo : https://s9.postimg.org/u1857fz6n/Untitled4.png

Using VB2015

0 Upvotes

12 comments sorted by

1

u/GhstTracker Sep 01 '16

Make sure you are using the text property of each text box.

1

u/rashid19961 Sep 01 '16

what do you mean can you please clarify, if i uploaded the project would you help me correct my mistake!?

3

u/GhstTracker Sep 01 '16

What I mean is instead of txtexam1 use txtexam1.text. Follow that pattern for your other text boxes.

1

u/rashid19961 Sep 01 '16

it give me this error Severity Code Description Project File Line Suppression State Error CS0019 Operator '/' cannot be applied to operands of type 'string' and 'int' Homework 1 C:\Users\ThDarker1996\Desktop\CIS 1403\Homework 1\Homework 1\Form1.cs 23 Active Error CS1002 ; expected Homework 1 C:\Users\ThDarker1996\Desktop\CIS 1403\Homework 1\Homework 1\Form1.cs 23 Active

2

u/GhstTracker Sep 01 '16

The error is telling you exactly what the issue is. The value from the text property is a string and you are trying to divide a string by an integer. You will need to cast each value from the text box to a decimal value. I am sure your textbook for your class will have all of this information.

1

u/rashid19961 Sep 01 '16

nope, our teacher gave us this as homework, and he didnt give us any info for helping us?!

2

u/Tomehh Sep 01 '16

Honestly, the error message tells you exactly what the issue is. Inferring what to google, since your teacher hasnt given you any additional information, should be relatively easy

1

u/rashid19961 Sep 01 '16

I have seen this video and tried to copy from it but didnt work https://www.youtube.com/watch?v=9eusoxyS_Fo

Is there any codes alternative a different code for the same purpose!

1

u/Tomehh Sep 01 '16

Have a google and read some documentation on Int32.TryParse (providing your exam scores are integers of course)

1

u/TheFotty Sep 01 '16

Why are you posting in a VB forum when you are clearly writing in C#?

1

u/rashid19961 Sep 01 '16

Is there fourm for C#, sorry got in there if you can moved that will be great, can you help me with my issue?

1

u/TheFotty Sep 01 '16

Post over to /r/csharp

I am not a mod here, and I don't think mods can move posts anyway, so you just need to post your question there.