Simple multiplication table

By ^Neptune on Oct 13, 2009

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?

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
Sign in to comment.
`Green   -  Oct 18, 2009

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 :)

 Respond  
jonesy44   -  Oct 15, 2009

Sorry, yeah i was adding to my previous comment.

 Respond  
mountaindew   -  Oct 15, 2009

He was referring to his previous comment: [quote] Just fyi; you can use

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

instead of

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

sometimes it's a little easier, your choice really though [/quote]

 Respond  
Hawkee   -  Oct 14, 2009

Not sure what you mean jonesy.

 Respond  
jonesy44   -  Oct 14, 2009

{x} is replaced by the word x commas after if you see me? so {0} is the first, {1} the next, etc.

 Respond  
Hawkee   -  Oct 14, 2009

I fixed the code highlighting for vb.net snippets. Thanks for catching that.

 Respond  
mountaindew   -  Oct 13, 2009

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:

Dim tablenum As Integer, var As Integer

And rather than doing the Do...Loop Until 1 = 2, you can just do Do...Loop

 Respond  
^Neptune   -  Oct 13, 2009

How does that work?

 Respond  
jonesy44   -  Oct 13, 2009

Just fyi; you can use

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

instead of

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

sometimes it's a little easier, your choice really though

 Respond  
jonesy44   -  Oct 13, 2009

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

 Respond  
^Neptune   -  Oct 13, 2009

Oh man, hawkee needs colour highlighting.. it's not as easy to read on here.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.