jhylands

multiplication table - computing homework - first draft

Oct 27th, 2012
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.46 KB | None | 0 0
  1. 'Works but I'm not happy with its speed
  2. Public Class Form1
  3.     Private Sub generate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles generate.Click
  4.         'Define size as integer : this is the size of the table
  5.         Dim size As Integer = 1
  6.         'Retive what the User wants as the size of the table
  7. Tryagain:
  8.         Try
  9.             size = InputBox("what size do you want the multiplication table to be? (Please enter a posative whole number)")
  10.             If size < 1 Then
  11.                 MsgBox("please enter a posative whole number!")
  12.                 GoTo tryagain
  13.             End If
  14.         Catch
  15.             MsgBox("error please enter a posative whole number!")
  16.             GoTo tryagain
  17.         End Try
  18.         'Tell the user the the table is being prossesed and that large tables may take some time
  19.         WebBrowser1.DocumentText = "<h1>Generating table</h1> <p> The program is now generating your multiplication table of " & size & " by " & size & " bare in mind that large tables may cause the program to crash piriodicaly.</p>"
  20.         Me.Refresh()
  21.         'Generate an array that contains the table
  22.         Dim table(size, size) As Integer
  23.         'Fill the table here the 0 array entries are blank because they are used after
  24.         For I = 1 To size
  25.             For n = 1 To size
  26.                 table(I, n) = I * n
  27.             Next
  28.         Next
  29.         'Use the empty cells for the edge of the table
  30.         table(0, 0) = 0
  31.         For I = 1 To size
  32.             table(0, I) = I
  33.             table(I, 0) = I
  34.         Next
  35.         'send the array away to be made and then print what comes back onto the screen
  36.         WebBrowser1.DocumentText() = Formathtmltable(table)
  37.     End Sub
  38.     Function Formathtmltable(ByVal table)
  39.         'Create a variable for the source code and start the code
  40.         Dim source As String = "<html> <body><table boarder='1'>"
  41.         Dim size As int16 = table.getlength(0) - 1
  42.         For I = 0 To size 'for each row
  43.             Source = source & "<tr>"
  44.             For n = 0 To size ' for each collonn
  45.                 Source = source & "<td>" & table(I, n) & "</td>"
  46.             Next
  47.             Source = source & "</tr>"
  48.         Next
  49.         Source = source & "</table></body></ html>"
  50.         Return source
  51.     End Function
  52.  
  53.     ' Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  54.     '   WebBrowser1.Width = Me.Width - 50
  55.     '  WebBrowser1.Height = Me.Height - 100
  56.     'End Sub
  57. End Class
Advertisement
Add Comment
Please, Sign In to add comment