Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Works but I'm not happy with its speed
- Public Class Form1
- Private Sub generate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles generate.Click
- 'Define size as integer : this is the size of the table
- Dim size As Integer = 1
- 'Retive what the User wants as the size of the table
- Tryagain:
- Try
- size = InputBox("what size do you want the multiplication table to be? (Please enter a posative whole number)")
- If size < 1 Then
- MsgBox("please enter a posative whole number!")
- GoTo tryagain
- End If
- Catch
- MsgBox("error please enter a posative whole number!")
- GoTo tryagain
- End Try
- 'Tell the user the the table is being prossesed and that large tables may take some time
- 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>"
- Me.Refresh()
- 'Generate an array that contains the table
- Dim table(size, size) As Integer
- 'Fill the table here the 0 array entries are blank because they are used after
- For I = 1 To size
- For n = 1 To size
- table(I, n) = I * n
- Next
- Next
- 'Use the empty cells for the edge of the table
- table(0, 0) = 0
- For I = 1 To size
- table(0, I) = I
- table(I, 0) = I
- Next
- 'send the array away to be made and then print what comes back onto the screen
- WebBrowser1.DocumentText() = Formathtmltable(table)
- End Sub
- Function Formathtmltable(ByVal table)
- 'Create a variable for the source code and start the code
- Dim source As String = "<html> <body><table boarder='1'>"
- Dim size As int16 = table.getlength(0) - 1
- For I = 0 To size 'for each row
- Source = source & "<tr>"
- For n = 0 To size ' for each collonn
- Source = source & "<td>" & table(I, n) & "</td>"
- Next
- Source = source & "</tr>"
- Next
- Source = source & "</table></body></ html>"
- Return source
- End Function
- ' Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- ' WebBrowser1.Width = Me.Width - 50
- ' WebBrowser1.Height = Me.Height - 100
- 'End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment