Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 12th, 2006, 10:07 PM
dez dez is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 3 dez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 10 sec
Reputation Power: 0
Times Table

Hi I am trying to print the 10 times table but can't get the code to work?

Cheers

...Dez...

Reply With Quote
  #2  
Old June 13th, 2006, 04:41 AM
D.O.M.I.N.A.T.O.R's Avatar
D.O.M.I.N.A.T.O.R D.O.M.I.N.A.T.O.R is offline
Kingpin contributor
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Nov 2005
Location: P.E, RSA
Posts: 1,051 D.O.M.I.N.A.T.O.R User rank is First Lieutenant (10000 - 20000 Reputation Level)D.O.M.I.N.A.T.O.R User rank is First Lieutenant (10000 - 20000 Reputation Level)D.O.M.I.N.A.T.O.R User rank is First Lieutenant (10000 - 20000 Reputation Level)D.O.M.I.N.A.T.O.R User rank is First Lieutenant (10000 - 20000 Reputation Level)D.O.M.I.N.A.T.O.R User rank is First Lieutenant (10000 - 20000 Reputation Level)D.O.M.I.N.A.T.O.R User rank is First Lieutenant (10000 - 20000 Reputation Level)D.O.M.I.N.A.T.O.R User rank is First Lieutenant (10000 - 20000 Reputation Level)D.O.M.I.N.A.T.O.R User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 2 h 12 m 16 sec
Reputation Power: 201
Quote:
Originally Posted by dez
Hi I am trying to print the 10 times table but can't get the code to work?

Cheers

...Dez...


Post your attempted code, and errors if any.
__________________
Fitness & Diet resources Career Descriptions Boat Cruises
All code that is posted by me has not been tested, and it should only be interpreted as a guideline to a solution. There is no guarantee that any of my code samples will work as provided, and should be customized to suite the required need.

Reply With Quote
  #3  
Old June 13th, 2006, 06:21 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,932 sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 6 Days 22 h 36 m 35 sec
Reputation Power: 1243
Quote:
Originally Posted by dez
Hi I am trying to print the 10 times table but can't get the code to work?

Cheers

...Dez...

I agree with D.O.M.I.N.A.T.O.R, it is a good idea to post your code along with descriptions of any errors or unexpected output to illustrate your problem and your attempt to solve it.

Without knowing exactly what you are trying to achieve, or if you have indeed attempted it yourself, I will demonstrate how to calculate the 10 times table using a For..Next Loop:
Code:
Private Sub Command1_Click()
Dim counter As Integer
Dim iterations As Integer
iterations = 1
For counter = 10 To 100 Step 10
Debug.Print iterations & " x 10 = " & counter
iterations = iterations + 1
Next
End Sub
Comments on this post
D.O.M.I.N.A.T.O.R agrees: Good effort.

Reply With Quote
  #4  
Old June 18th, 2006, 06:09 AM
dez dez is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 3 dez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 10 sec
Reputation Power: 0
Hey thanks guys, I suppose what I am really trying to do is ask the user what table they want printed. Then print it out on a form up to 10X. Then include a continue box and if the user clicks on continue then the next 10 times (i.e. 11X, 12X..up to...20X) are printed and so on.
My code is just a poor variation of what you already have shown me..

Function Times()
Dim counter As Integer
Dim iterations As Integer
Dim start As String

start = InputBox("Enter the times table you want printed.")
iterations = 1
For counter = start To 100 Step start
Debug.Print iterations & " X " & start; " = " & counter
iterations = iterations + 1
Next
End Function

Cheers and thank you

...Dez...

Reply With Quote
  #5  
Old June 18th, 2006, 03:25 PM
Nocturns2 Nocturns2 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 60 Nocturns2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 34 m 23 sec
Reputation Power: 3
The code sample you're showing will only render iterations of the 10 times table in increments of 10.

Try the following code. Create a textbox control or button for the user to select the times table they want and pass the value to the Times function. And you can have another to button to perform the task again by submitting the same value to the times function.

vb Code:
Original - vb Code
  1.  
  2. 'place in general declaration area (outside a procedure, usually at the top of the module)
  3. public start as integer
  4. public endat as integer
  5. public multiplier as integer
  6.  
  7.  
  8. Function Times (ByVal m) as string
  9. dim multiplicand as integer
  10. dim product as integer
  11. dim s as string
  12. dim cr as string
  13.  
  14.   if (m = multiplier) then
  15.     start = start + 10
  16.     endat = endat + 10
  17.   else
  18.     start = 1
  19.     endat = 10
  20.   end if
  21.  
  22.   multiplier = m
  23.  
  24.   cr = chr(13) & chr(10)
  25.  
  26.   s = ""
  27.  
  28.   for multiplicand = start to endat
  29.     Product = multiplicand * multiplier
  30.     debug.print cstr(multiplicand) & " x " & cstr(multiplier) & " = " & cstr(Product) & cr
  31.     s = s & cstr(multiplicand) & " x " & cstr(multiplier) & " = " & cstr(Product) & cr
  32.   next multiplicand
  33.  
  34.   Times = s
  35.  
  36. End Function

Reply With Quote
  #6  
Old June 19th, 2006, 08:11 PM
dez dez is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 3 dez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 10 sec
Reputation Power: 0
Here is where I am at with this code so far I now want to continue with start+10 ask the question again etc..

Function ContinueTimes()
Dim counter As Integer
Dim iterations As Integer
Dim start As String

start = InputBox("Enter the times table you want printed.")
iterations = 1
For counter = 1 To 10
Debug.Print counter & " X " & start; " = " & counter * start
iterations = iterations + 1
Next
Dim Msg, Style, Title, Response
Msg = "Do you want the next ten?"
Style = vbYesNo
Response = MsgBox(Msg, Style)
If Response = vbNo Then
Exit Function
End If
End Function

Reply With Quote
  #7  
Old June 20th, 2006, 02:39 AM
Nocturns2 Nocturns2 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 60 Nocturns2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 34 m 23 sec
Reputation Power: 3
Using the code I gave you above, if you place the code in the general declaration area of the form module. And you add a textbox to your form and name it UserValue. Then create a buttom and add e=Times(cint(UserValue.text)) to the click event code, (e can be for the return value if you choose to have one).
If the user enters a number in the UserValue and clicks the button, it will call the Times function and pass it the UserValue, which will show the times table for that UserValue in increments of 10, (10 has been hardcoded into the function).
For example, if UserValue = 2 then it will show the following:
1 x 2 = 2
2 x 2 = 4
...
9 x 2 = 18
10 x 2 = 20

If the user clicks the button again, the function with show the continuation for that same UserValue.

11 x 2 = 22
12 x 2 = 24
...
19 x 2 = 38
20 x 2 = 40

, and will continue incrementing in groups of 10 each time the user clicks the button.

Until the user enters a different value in the UserValue textbox, then when they click the button, the function will start with a fresh times table starting from 1 x the UserValue on through to 10 x the UserValue and if they click the button again it will continue with 11 x the UserValue for however many times the button is clicked. As long as the UserValue has not been changed.

This happens because the variables: start, endat, and multiplier have module wide scope. They retain their value after the function ends. And the function can use them and can modify their values.

That said, your code shows that you want to use recursion.

You've already told your function what to do if the user clicks No, but you haven't told it what to do if they click Yes.

Reply With Quote
  #8  
Old November 2nd, 2006, 11:57 AM
aj2009 aj2009 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 2 aj2009 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 42 sec
Reputation Power: 0
Times Table Code

Hi

I just noticed this thread whilst looking for some help myself..

Can anyone tell me how to code a form to calculate a basic times table 1-10 for any given input and then display the outcome on a seperate form? Basically i want a user to be able to input a number in a text box, hit a command button, then the code (loop ??) work out the times table and display this on a seperate form..

Im a newbie to VB and still learning, any advice would be greatly appreciated.

Reply With Quote
  #9  
Old November 3rd, 2006, 08:41 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,932 sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 6 Days 22 h 36 m 35 sec
Reputation Power: 1243
Aj,

In order to be able to display the times table in a different form you first have to declare a global variable. To do this go to Project -> Add Module, accept the default and click Open. You can now open up this module and declare a variable within it, just type Public strUserChoice As Integer

Now, return to form1, add a Textbox and a Command Button and add the following code to the buttons click event:
Code:
strUserChoice = Val(Text1.Text)
Form1.Hide
Form2.Show

Now add a new form to your project (Project -> Add Form, accept the default and click Open).

Drag a textbox onto form2 set its multiline property to True and resize it so that it fills most of the form, you can now add the following code to form2's code behind:
Code:
Private Sub Form_Load()
Text1.Text = ""
Dim intCounter As Integer
For intCounter = 1 To 10
Text1.Text = Text1.Text & intCounter & " X " & strUserChoice & " = " & Val(intCounter) * Val(strUserChoice) & vbCrLf
Next
End Sub

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Times Table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |