|
Subject:
|
Very Simple code
|
|
Posted By:
|
Tal1481
|
Post Date:
|
1/24/2007 5:47:05 PM
|
I am a lecturer in ICT and have been roped into teaching VB - only I don't know VB. I can design etc. Anyway I am trying to code a program - the problem statement is this:
Design a program to read ten numbers from a keyboard and display their sum (addition) on the monitor screen.
This is the code I have developed so far - this is the first time ive ever touche a programming language - i know this code is very simple but please dont laugh at me lol.
Private Sub Command1_Click() Dim total As Double Static count As Double Number = Text1.Text
total = 0 count = 1
If count <= 10 Then total = total + Number count = count + 1
ElseIf count > 10 Then Form1.Print "The sum of the 10 numbers is: "; total
End If End Sub
Can any body please tell me where I'm going wrong as I truly do not have a clue.
T
|
|
Reply By:
|
HaveHave2222
|
Reply Date:
|
1/25/2007 6:15:38 AM
|
Something like this
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim intCount As Integer Dim dblTotal As Double Dim strInput As String
For intCount = 1 To 10 strInput = InputBox("Give a number") dblTotal = dblTotal + Convert.ToDouble(strInput) Next intCount
MessageBox.Show(Convert.ToString(dblTotal), "Total") End Sub
End Class
|