Thursday, October 28, 2010

Thursday, 10/28/2010

Here is a tutorial done by Evangelos Petroutsos


Dim Payment As Double
Dim LoanIRate As Double
Dim LoanDuration As Integer
Dim LoanAmount As Integer

' Validate amount
If IsNumeric(txtAmount.Text) Then
LoanAmount = Convert.ToInt32(txtAmount.Text)
Else
MsgBox("Please enter a valid amount.")
Exit Sub
End If
' Validate interest rate
If IsNumeric(txtRate.Text) Then
LoanIRate = 0.01 * Convert.ToDouble(txtRate.Text) / 12
Else
MsgBox("Invalid interest rate, please re-enter.")
Exit Sub
End If
'Validate loan's duration
If IsNumeric(txtDuration.Text) Then
LoanDuration = Convert.ToInt32(txtDuration.Text)
Else
MsgBox("Please specifiy the loan's duration as a number of months")
Exit Sub
End If
'If all data were validated, proceed with calculations
Dim payEarly As DueDate
If chkPayEarly.Checked Then
payEarly = DueDate.BegOfPeriod
Else
payEarly = DueDate.EndOfPeriod
End If
Payment = Pmt(LoanIRate, LoanDuration, -LoanAmount, 0, payEarly)
txtPayment.Text = Payment.ToString("#.00")


Here is a rich text editor with lots of dialog boxes dealing with saving, loading etc.


Private Sub FileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.Click

End Sub

Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
txtField.Clear()

End Sub

Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
Try
Dim dlg As OpenFileDialog = New OpenFileDialog
dlg.Title = "Open"
dlg.Filter = "Rich Text Files (*.rtf) | *.rtf"
If dlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
txtField.LoadFile(dlg.FileName)
End If
Catch ex As Exception : End Try
End Sub

Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
Try
Dim dlg As SaveFileDialog = New SaveFileDialog
dlg.Title = "Save"
dlg.Filter = "Rich Text Files (*.rtf) | *.rtf"
If dlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
txtField.SaveFile(dlg.FileName, RichTextBoxStreamType.RichText)
End If
Catch ex As Exception : End Try
End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub

Private Sub EditToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditToolStripMenuItem.Click

End Sub

Private Sub UnoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UnoToolStripMenuItem.Click
txtField.Undo()

End Sub

Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
Try
Dim dlg As FontDialog = New FontDialog
dlg.Font = txtField.Font
If dlg.ShowDialog = System.Windows.Forms.DialogResult.OK Then
txtField.Font = dlg.Font
End If
Catch ex As Exception

End Try
End Sub

Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorToolStripMenuItem.Click
Try
Dim dlg As ColorDialog = New ColorDialog
dlg.Color = txtField.ForeColor
If dlg.ShowDialog = System.Windows.Forms.DialogResult.OK Then
txtField.ForeColor = dlg.Color
End If
Catch ex As Exception

End Try
End Sub


I also did a tutorial on do while loops


Dim Num1 As Integer = 1

Do While Num1 <= 10
MessageBox.Show("the value of the variable is: " & Num1)
Num1 = Num1 + 1
Loop

No comments: