Visual Basic结构和变量

时间:2016-11-17 00:29:14

标签: vb.net visual-studio

我正在进行这项任务,我需要在结构中包含一个数组。该数组由文本文件中的导入值组成:

2,3
3,4
4,4
5,5
5,4
6,3
3,6
9,9
10,10
1,5
2,5
3,5
1,4
2,4
3,4
4,4

我收到了这些错误:

Severity    Code    Description Project File    Line    Suppression State
Error   BC30456 'real' is not a member of 'Form1.complexNumber()'.  WindowsApplication3 e:\users\gabe\documents\visual studio 2015\Projects\Lab7_Gabriel_Carnes\WindowsApplication3\Form1.vb    68  Active
Severity    Code    Description Project File    Line    Suppression State
Error   BC30311 Value of type 'Form1.complexNumber' cannot be converted to 'String'.    WindowsApplication3 e:\users\gabe\documents\visual studio 2015\Projects\Lab7_Gabriel_Carnes\WindowsApplication3\Form1.vb    69  Active

我已经尝试将结构移动到方法内而不是表单级别,但是它会给出一个关于无法在方法中的错误。

代码:

Public Class Form1

    Dim Real1, Real2, Imag1, Imag2 As Double

    Dim Answer As String

    Private Structure complexNumber

        Public real As String
        Public imag As String

    End Structure

    ' Dim strValues() As fileInport =
    '        IO.File.ReadAllLines("Input.txt")

    Dim Values(15) As complexNumber

    Dim ValuesString As String

    Dim line, data() As String
    Dim inputs() As String =
            IO.File.ReadAllLines("Input.txt")


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        lblBy.Visible = False
        lblMinus.Visible = False
        lblPlus.Visible = False
        lblTimes.Visible = False
        lblAnswer.Text = ""

        For i As Integer = 0 To 15

            line = inputs(i)
            data = line.Split(","c)
            Values(i).real = data(0)
            Values(i).imag = data(1)


            'Values(i) = (strValues(i))

        Next

    End Sub

    'ALL TEXT FILE VALUE CALCULATIONS

    Private Sub btnFileAdd_Click(sender As Object, e As EventArgs) Handles btnFileAdd.Click

        'ComplexMath.MathFunctions.Add(Values(0).real, Values(0).imag, Values(1).real, Values(1).imag)

        'lstFileResults.Items.AddRange = Values(15)

        ValuesString = Values.real(15)
        TextBox1.Text = Values(15)

        lblBy.Visible = False
        lblTimes.Visible = False
        lblMinus.Visible = False
        lblPlus.Visible = True

    End Sub

    Private Sub btnFileSubtract_Click(sender As Object, e As EventArgs) Handles btnFileSubtract.Click

        lblBy.Visible = False
        lblTimes.Visible = False
        lblPlus.Visible = False
        lblMinus.Visible = True

    End Sub

    Private Sub btnFileMultiply_Click(sender As Object, e As EventArgs) Handles btnFileMultiply.Click

        lblBy.Visible = False
        lblPlus.Visible = False
        lblMinus.Visible = False
        lblTimes.Visible = True

    End Sub

    Private Sub btnFileDivide_Click(sender As Object, e As EventArgs) Handles btnFileDivide.Click

        lblTimes.Visible = False
        lblPlus.Visible = False
        lblMinus.Visible = False
        lblBy.Visible = True

    End Sub

    'ALL USER VALUE CALCULATIONS

    Private Sub btnUserAdd_Click(sender As Object, e As EventArgs) Handles btnUserAdd.Click

        Real1 = Val(txtReal1.Text)
        Real2 = Val(txtReal2.Text)
        Imag1 = Val(txtImag1.Text)
        Imag2 = Val(txtImag2.Text)

        Answer = ComplexMath.MathFunctions.Add(Real1, Imag1, Real2, Imag2)

        lblAnswer.Text = Answer

        lblBy.Visible = False
        lblTimes.Visible = False
        lblMinus.Visible = False
        lblPlus.Visible = True

    End Sub

    Private Sub btnUserSubtract_Click(sender As Object, e As EventArgs) Handles btnUserSubtract.Click

        Real1 = Val(txtReal1.Text)
        Real2 = Val(txtReal2.Text)
        Imag1 = Val(txtImag1.Text)
        Imag2 = Val(txtImag2.Text)

        Answer = ComplexMath.MathFunctions.Subtract(Real1, Imag1, Real2, Imag2)

        lblAnswer.Text = Answer

        lblBy.Visible = False
        lblTimes.Visible = False
        lblPlus.Visible = False
        lblMinus.Visible = True

    End Sub


    Private Sub btnUserMultiply_Click(sender As Object, e As EventArgs) Handles btnUserMultiply.Click

        Real1 = Val(txtReal1.Text)
        Real2 = Val(txtReal2.Text)
        Imag1 = Val(txtImag1.Text)
        Imag2 = Val(txtImag2.Text)

        Answer = ComplexMath.MathFunctions.Multiply(Real1, Imag1, Real2, Imag2)

        lblAnswer.Text = Answer

        lblBy.Visible = False
        lblPlus.Visible = False
        lblMinus.Visible = False
        lblTimes.Visible = True

    End Sub

    Private Sub btnUserDivide_Click(sender As Object, e As EventArgs) Handles btnUserDivide.Click

        Real1 = Val(txtReal1.Text)
        Real2 = Val(txtReal2.Text)
        Imag1 = Val(txtImag1.Text)
        Imag2 = Val(txtImag2.Text)

        Answer = ComplexMath.MathFunctions.Multiply(Real1, Imag1, Real2, Imag2)

        lblAnswer.Text = Answer

        lblTimes.Visible = False
        lblPlus.Visible = False
        lblMinus.Visible = False
        lblBy.Visible = True

    End Sub

End Class

0 个答案:

没有答案