Top

Simple multiplication table


.NET Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  0.0 (of 0 scores)
Date Added  Oct 13, 2009
Last Updated  Oct 13, 2009
Tags  application  basic  console  multiplication  multiply  table  time  times  vb.net  visual 

Introduction



Only 8 .NET snippets? Guess I better put at least SOMETHING into it. Anyways, this is a simple console application, put it in a new console application project (I use Microsoft Visual Basic 2008 Express Edition).

It'll ask you for a number and then generate a multiplication table based on that number.

I know it's not the most advanced stuff in the world.. but hey, someone could learn from it (comments were included).

PS: For loops rock. Why does mIRC not have them?

Grab the Code

Module Module1
 
    Sub Main()
 
        ' Declare variables.
        Dim tablenum, var As Double
 
        ' Start of the Do loop that allows us to continually input new numbers.
        Do
 
            ' Ask user for an input and set tablenum to it.
            Console.Write("Enter the number you want to see multiplications for: ")
            tablenum = Console.ReadLine()
 
            ' Check if the number is going to cause an overflow and crash the program.
            If (tablenum >= 999999999999999999) Then
                Console.WriteLine("That number is too long - please use a smaller one...")
                Console.WriteLine(" ")
 
                ' If everything is OK, procede to output the multiplication table.
            Else
                Console.WriteLine(" ")
 
                ' A basic for loop that will output the line 12 times. 
                '"Next" automatically increases var by one on each iteration.
                For var = 1 To 12
                    Console.WriteLine(var & " * " & tablenum & " = " & var * tablenum & ".")
                Next
                Console.WriteLine(" ")
            End If
 
            ' Make it loop endlessly so that the user can keep inputting numbers until they close the program.
        Loop Until 1 = 2
    End Sub
 
End Module

Comments

  (11)  RSS
^Neptune
Comments: 598
 
.NET Snippet:  Simple multiplication table
Posted on Oct 13, 2009 11:02 am
Oh man, hawkee needs colour highlighting.. it's not as easy to read on here.
jonesy44
Comments: 1,856
 
.NET Snippet:  Simple multiplication table
Posted on Oct 13, 2009 4:47 pm
It isn't, nor is it properly equipped for GUI vb.net scripts. And i love your infinite logic, "Loop Until 1 = 2" Is it bad that that made me lol :P
jonesy44
Comments: 1,856
 
.NET Snippet:  Simple multiplication table
Posted on Oct 13, 2009 4:50 pm
Just fyi; you can use
Code:
Console.WriteLine("{0} * {1} = {2}", var, tablenum, var*tablenum)
instead of
Code:
                    Console.WriteLine(var & " * " & tablenum & " = " & var * tablenum & ".")
sometimes it's a little easier, your choice really though
^Neptune
Comments: 598
 
.NET Snippet:  Simple multiplication table
Posted on Oct 13, 2009 6:45 pm
How does that work?
mountaindew
Comments: 1,826
 
.NET Snippet:  Simple multiplication table
Posted on Oct 13, 2009 6:59 pm
I believe tablenum is being dimmed as a variant since you didn't specify a type, unless that's different in .NET than VB6. Looks like they should be integers too:
Code:

Dim tablenum As Integer, var As Integer

And rather than doing the Do...Loop Until 1 = 2, you can just do Do...Loop
Hawkee
Comments: 1,039
 
.NET Snippet:  Simple multiplication table
Posted on Oct 14, 2009 1:28 am
I fixed the code highlighting for vb.net snippets. Thanks for catching that.
jonesy44
Comments: 1,856
 
.NET Snippet:  Simple multiplication table
Posted on Oct 14, 2009 5:36 pm
{x} is replaced by the word x commas after if you see me? so {0} is the first, {1} the next, etc.
Hawkee
Comments: 1,039
 
.NET Snippet:  Simple multiplication table
Posted on Oct 14, 2009 7:58 pm
Not sure what you mean jonesy.
mountaindew
Comments: 1,826
 
.NET Snippet:  Simple multiplication table
Posted on Oct 15, 2009 5:54 am
He was referring to his previous comment:
Quote:

Just fyi; you can use
Code:

Console.WriteLine("{0} * {1} = {2}", var, tablenum, var*tablenum)

instead of
Code:

Console.WriteLine(var & " * " & tablenum & " = " & var * tablenum & ".")

sometimes it's a little easier, your choice really though
jonesy44
Comments: 1,856
 
.NET Snippet:  Simple multiplication table
Posted on Oct 15, 2009 1:39 pm
Sorry, yeah i was adding to my previous comment.
`Green
Comments: 34
 
.NET Snippet:  Simple multiplication table
Posted on Oct 18, 2009 10:56 am
well been a long time since ive been on here. and it seems the population for hawkee has dropped a lot. and at least you added VB codes area here :) but i use windows form applications. much better i think. and good to see you all again :)

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom