0

我用购物车表单中的Dim MyCollection As New AudioBooks语句实例化了内存中的一个地方。Public Class ShoppingCart这是我在有声读物Dim StrLearnCalclusInOneDayAB As String中以Public Class AudioBooks表格形式声明我的变量的地方。

If ListBox1.Items.Contains(Me.MyCollection.StrLearnCalclusInOneDayAB)

这是我的主要语法错误,我需要查看 listbox1 以查看有声读物中的变量是否存在。我认为这是错误的,我知道它非常简单。
这是完整的代码。我需要一个 VB 导师,每个问题将支付 5 美元以下是完整的代码。

Public Class ShoppingCart
Dim Tax As Decimal
Dim PB1 As Decimal
Dim AB1 As Decimal
Dim MyCollection As New AudioBooks

'My overall objective is to move the strings from audiobooks and printbooks to shopping cart and calculate the total
'I was instructed to use a module



Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
    Tax = 0.06
End Sub

Private Sub PrintBooksToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintBooksToolStripMenuItem.Click
    'Create an instance of the printbook
    Dim frmPrintBook As New PrintBook

    'Display the form in modal styple
    frmPrintBook.ShowDialog()
End Sub

Private Sub AudioBooksToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AudioBooksToolStripMenuItem.Click
    'Create an instance of the audiobook
    Dim frmAudioBook As New AudioBooks

    'Display the form in modal style
    frmAudioBook.ShowDialog()
End Sub


Public Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    'Dim MyCollection As New AudioBooks
    'I want to run an if else statement which checks Listbox1 to see what books are in the cart and calculates the total
    'I'm having trouble finding these variables(from audiobooks) with intelligsense, 'StrLearnCalclusInOneDayAB' etc.
    'I'm pretty sure I need a new instance of memory from the audio bookcooks class to use the object variables
    'declared in that class.  I'm having trouble getting the syntax right.  Intelligsense only will find the lstboxaudio

    'The book says, form's class-level variables are accessible to statements in the form file,
    'they are not accessible by default to statements outside the form file



    'I want the code to look like this,  only lstboxAudio comes up in Intelligsense, why is this, I want StrLearnCalclusInOneDayAB to
    'Also I'm not sure I'm using contains correctly, hope I was clear

    'I will eventually need to total the books in the cart, why Can't intellisense find the variable?
    'This is my primary question



    If ListBox1.Items.Contains(MyCollection.StrLearnCalclusInOneDayAB) Then

    End If


    Cart.IDidItYourWay = 11.95
    Cart.TheHistoryofScotland = 14.5
    Cart.LearnCalculusInOneDay = 29.95
    Cart.FeelTheStress = 18.5

    Cart.LearnCalculusInOneDayAB = 29.95
    Cart.RelaxationTechniques = 11.5
    Cart.TheScienceOfBodyLanguage = 12.95
    Cart.TheHistoryOfScotlandAB = 14.5
    'I feel I shouldn't have to reference an object to change properties in a class, why must I do that?  
    'This question might not make sense.  
End Sub


Private Sub lblSubtotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblSubtotal.Click

End Sub

结束类

Public Class AudioBooks

Public Sub lstboxAudio_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstboxAudio.SelectedIndexChanged


End Sub

Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'Dim AudioBooks1 As String
    'AudioBooks1 = lstboxAudio.SelectedItem.ToString
    'Save the selected item to a string
    'ShoppingCart.ListBox1.Items.Add(AudioBooks1)
    'shopping cart form, listbox1, items, add, that string of audiobooks

    Dim StrLearnCalclusInOneDayAB As String
    StrLearnCalclusInOneDayAB = lstboxAudio.Items(0).ToString
    'If strLearnCalculusInOneDayAB is selected then add to the shopping cart listbox

    If lstboxAudio.SelectedIndex = 0 Then
        ShoppingCart.ListBox1.Items.Add(StrLearnCalclusInOneDayAB)
    End If
    ' if the selectedindex of lslboxaudio is 0, the string is selected
    'then move it to the shoppingcart

    Dim StrTheHistoryOfScotlandAB As String
    StrTheHistoryOfScotlandAB = lstboxAudio.Items(1).ToString

    If lstboxAudio.SelectedIndex = 1 Then
        ShoppingCart.ListBox1.Items.Add(StrTheHistoryOfScotlandAB)
    End If


    Dim StrTheScienceOfBodyLangAB As String
    StrTheScienceOfBodyLangAB = lstboxAudio.Items(2).ToString

    If lstboxAudio.SelectedIndex = 2 Then
        ShoppingCart.ListBox1.Items.Add(StrTheScienceOfBodyLangAB)
    End If


    Dim StrRelaxationTechniquesAB As String
    StrRelaxationTechniquesAB = lstboxAudio.Items(3).ToString

    If lstboxAudio.SelectedIndex = 3 Then
        ShoppingCart.ListBox1.Items.Add(StrRelaxationTechniquesAB)
    End If

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Me.Close()
End Sub

结束类

4

1 回答 1

0

它与有声读物表单中默认归类为私有的 Dim 语句有关。必须明确声明为公共的。不知道访问级别和静态共享变量动态会创建此问题。

于 2012-11-22T15:29:06.643 回答