大家好,我在应聘时,给我了一道这样的题,怎样用VB6实现一个N阶行列式的计算?请哪位大侠救救我,不胜感激。我的困难有3个:当在窗体上输入行列式的阶数N后,怎样在窗体上动态显示N×N个输入数据用的文本框?
               怎样用二维数组的形式为N*N个文本框命名?
               怎样写出一个由N阶行列式到N-1阶行列式的递规函数?

解决方案 »

  1.   

    load可以动态增加控件 命名可以用N1N2等啊递规函数?有规律吗?
      

  2.   

    用循环使用Me.Controls("label" + Trim(str(i))).Caption来命名就可以!
      

  3.   

    感觉用表格控件方便一点
    'form1
    'text1 设定行列式的N值
    'text2 设定行列式每个单元格值
    'text3 显示结果
    'command1 设定grid1为N*N的表格
    'command2 计算结果
    'grid1 是MSHFlexGrid控件,把属性里fixed rows 和fixed cols都改为0,双击单元格输入值
    Dim EditRow As Integer, EditCol As Integer
    Private Sub Command1_Click()
    Dim I As Integer
    Grid1.Rows = Val(Text1.Text)
    Grid1.Cols = Val(Text1.Text)
    Grid1.RowHeight(-1) = 600
    Grid1.ColWidth(-1) = 600
    For I = 0 To Grid1.Cols - 1
        Grid1.ColAlignment(I) = 4   ' Center align.
    Next I
    Text2.Width = 600 - 10
    Text2.Height = 600 - 10
    End SubPrivate Sub Command2_Click()
    Dim NAnswer As Double
    Dim Sum1 As Double
    Dim I As Integer, J As Integer, K As Integer
    Text3.Text = ""
    NAnswer = 0
    Sum1 = 1
    For I = 0 To Grid1.Cols - 1
        K = I
        For J = 0 To Grid1.Rows - 1
            If K >= Grid1.Cols Then
                K = 0
            End If
            Sum1 = Sum1 * Val(Grid1.TextMatrix(J, K))
            K = K + 1
        Next J
    NAnswer = NAnswer + Sum1
    Text3 = Text3 & "+" & Sum1
    Sum1 = 1
    Next I
    Sum1 = 1
    For I = 0 To Grid1.Cols - 1
        K = I
        For J = 0 To Grid1.Rows - 1
            If K < 0 Then
                K = Grid1.Cols - 1
            End If
            Sum1 = Sum1 * Val(Grid1.TextMatrix(J, K))
            K = K - 1
        Next J
    NAnswer = NAnswer - Sum1
    Text3 = Text3 & "-" & Sum1
    Sum1 = 1
    Next I
    Text3 = Text3 & "=" & NAnswer
    End SubPrivate Sub Grid1_DblClick()
    EditRow = Grid1.Row
    EditCol = Grid1.Col
    Text2.Left = Grid1.Left + Grid1.CellLeft - 10
    Text2.Top = Grid1.Top + Grid1.CellTop - 10
    Text2.Visible = True
    Text2.SetFocus
    End SubPrivate Sub Text2_LostFocus()
    Grid1.TextMatrix(EditRow, EditCol) = Text2.Text
    Text2.Visible = False
    End Sub
      

  4.   

    在窗体上动态显示N×N个输入数据用的文本框
    Option Explicit
        Public WithEvents TextBoxObj As TextBoxPrivate Sub Form_Load()
    Dim i As Integer
    Dim j As Integer
    Dim mNN As Integer
    mNN = 4                    '在Form中显示4x4TextBox
    Dim TempTop As Integer
    Dim TempLeft As Integer
        TempLeft = 800
        For j = 1 To mNN
            TempTop = 300
            TempLeft = TempLeft + 1070
            For i = 1 To mNN
                Set TextBoxObj = Controls.Add("VB.TextBox", "Text" & j & i)
                With TextBoxObj
                         .Visible = True
                         .Height = 400
                         .Width = 900
                         .Text = "霸王丸" & j & i
                         TempTop = TempTop + 600
                         .Top = TempTop
                         .Left = TempLeft
                End With
            Next
        Next
    End Sub
      

  5.   

    看看我的是不是最简单:
    for i=1 to n*n
        me.Controls("label" + Trim(str(i))).Caption=str(i)
    next i
    这样便可以将所有的框上赋予1到n*n的值,然后你要指定哪一个框的值,即可以用
    me.Controls("label" + Trim(str(i))).Caption=str(i)。