locked
Determinant Calculator

    Question

  • Hearing no response from my last request, I proceded to code my matrix deteminant calculator as best I could.  It seems to run, but now I need to get the result visible.  Eventually I want to print the matrix title, matrix input and the determinant value.  Right now I get nothing out.  I will paste my program below.

     

    Can someone help me find out how to procede?

    I need help finding out what is wrong with the following code and to print out the results.

    Imports Microsoft.VisualBasic

    Imports Microsoft.VisualBasic.Strings

    Imports System.Drawing.Graphics

    Imports System.Drawing.Printing

    Public Class Form1

    Dim WithEvents PD As New PrintDocument

    Dim PPD As New PrintPreviewDialog

    Dim LinePrinting As Integer

    Private Sub pbPrint_Click(ByVal sender As System.Object, _

    ByVal e As System.EventArgs) Handles pbPrint.Click

    PPD.Document = PD

    PD.OriginAtMargins = True

    PPD.ShowDialog()

    End Sub

    Private Sub PD_BeginPrint(ByVal sender As Object, ByVal _

    e As System.EventArgs) Handles PD.BeginPrint

    LinePrinting = 0

    End Sub

    Private Sub PD_PrintPage(ByVal sender As Object, ByVal _

    e As PrintPageEventArgs) Handles PD.PrintPage

    Dim YPos As Integer

    Dim MaxY As Integer = e.MarginBounds.Height - _

    TextBox1.Font.Height

    Do

    If LinePrinting >= TextBox1.Lines.Length Then Return

    e.Graphics.DrawString(TextBox1.Lines(LinePrinting), _

    TextBox1.Font, Brushes.Black, 0, YPos)

    LinePrinting += 1

    YPos += TextBox1.Font.Height

    Loop Until YPos >= MaxY

    e.HasMorePages = True

    End Sub

    Public I As Integer : Private J As Integer

    Public Const ArrayDim As Integer = 3

    Public Mat(ArrayDim - 1, ArrayDim - 1) As Double

    Public Foo As Double

    Private Sub TextBox2_KeyPress(ByVal sender As System.Object, _

    ByVal e As System.Windows.Forms.KeyPressEventArgs) _

    Handles TextBox2.KeyPress

    If e.KeyChar = Chr(Keys.Enter) Then

    If Double.TryParse(TextBox2.Text, Foo) Then

    Mat(J, I) = Foo

    If Not (I + 1 = ArrayDim) Then

    I += 1

    Else

    If Not (J + 1 = ArrayDim) Then

    J += 1 : I = 0

    Else

    TextBox2.Visible = False : Label2.Visible = False

    End If

    End If

    Else

    MessageBox.Show("Input Error")

    End If

    TextBox2.Text = String.Empty

    e.Handled = True

    End If

    UpdateLabel()

    End Sub

    Private Sub UpdateLabel()

    Label2.Text = "Enter Data for (" + CStr(J) + "'" + CStr(I) + ")"

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, _

    ByVal e As System.EventArgs) Handles Me.Load

    UpdateLabel()

    End Sub

    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

    End Sub

    End Class

    Public Class Matrix

    Public I As Integer : Public J As Integer

    Public Const ArrayDim As Integer = 3

    Public Mat(ArrayDim - 1, ArrayDim - 1) As Double

    Public Foo As Double

    Private Function Determinant() As Double

    Dim SubMatrix(ArrayDim - 1, ArrayDim - 1) As Matrix

    Dim Total As Double

    For J As Integer = 0 To 2

    Dim subtotal As Double = 0

    subtotal = Mat(0, J) * SubMatrix(0, J).Determinant

    If J Mod 2 <> 0 Then subtotal = subtotal * -1

    Total = Total + subtotal

    Next

    Return Total

    End Function

     

     

     

    End Class

    Sunday, February 24, 2008 7:26 PM

All replies

  • In my previous post "determinant calculator" I seemed to run without errors, but I got no output.  It appears to me it stops just short of activating the determinant function.  I had to create the matrix class to contain the determinant function and I have tried to pass all the required data to that class.  In the past, I have activated code via the buttons in various sub-routines.  I get a  message that functions can not be activated from sub-routines.  I have seen examples where it appears functions execute when just after sub-routines, but that does not work in my case.

     

    How do I get the determinant function to function?

    Sunday, March 09, 2008 8:14 PM