Wrox Programmer Forums
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 24th, 2007, 06:47 PM
Registered User
 
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Very Simple code

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

 
Old January 25th, 2007, 07:15 AM
Authorized User
 
Join Date: May 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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






Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2 - simple example code php4ever BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 4 October 30th, 2009 07:40 AM
simple code, solve many problems KeviJay Visual Basic 2005 Basics 2 September 8th, 2008 06:17 AM
Simple file path code Bafa VB Databases Basics 1 July 31st, 2008 02:22 PM
Very Simple code Tal1481 Beginning VB 6 9 January 29th, 2007 11:12 AM
Simple HTML code... rupen HTML Code Clinic 1 October 31st, 2006 06:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.