Okay I have an application, which is to demonstrate the use of a created class. I have a previous and next button which cycles through the array. However I need the user to be able to create a new instance of the object then as they cycle through they see their new object. I am stuck on this part. I've tried a few things for my button create event but I have been getting an unhandled can't convert to 1 dimensional array among other things. Any tips and help would be appreciated.
Code:
Public Class frmMain Inherits System.Windows.Forms.Form Private m_objName(2) As Course ' Client object Private m_intPosition As Integer = 0 ' current account Private Sub frmMain_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim intCount As Integer ' counter variable ' array of course names Dim strCourseName() As String = _ New String() {"Science", "History", "Math"} ' array of course numbers Dim strCourseNumber() As String = _ New String() {"S123", "H123", "M123"} 'array of start date Dim strStartDate() As String = _ New String() {"2/27/07", "2/28/07", "3/1/07"} 'array of start date Dim strEndDate() As String = _ New String() {"4/10/07", "4/11/07", "4/12/07"} ' loop and create more course objects For intCount = 0 To m_objName.GetUpperBound(0) ' create new object and store into Client array m_objName(intCount) = New Course(strCourseName(intCount), _ strCourseNumber(intCount), strStartDate(intCount), _ strEndDate(intCount)) Next End Sub Private Sub btnNext_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnNext.Click m_intPosition += 1 ' increment position ' if position is last (top) object If m_intPosition > m_objName.GetUpperBound(0) Then m_intPosition = 0 ' set to first position in array DisplayInformation() ' display information Else DisplayInformation() End If End Sub Private Sub btnPrev_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnPrev.Click m_intPosition -= 1 ' decrement position ' if position is last (bottom) object If m_intPosition < 0 Then ' set to last position in array m_intPosition = m_objName.GetUpperBound(0) DisplayInformation() Else DisplayInformation() ' display information End If End Sub ' display information Private Sub DisplayInformation() ' use m_intPosition as index for each object txtCourseName.Text = m_objName(m_intPosition).Name txtCourseNumber.Text = m_objName(m_intPosition).Number txtCourseStart.Text = _ Convert.ToString(m_objName(m_intPosition).Start) txtCourseEnd.Text = _ Convert.ToString(m_objName(m_intPosition).CEnd) End Sub ' DisplayInformation Private Sub btnCreate_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnCreate.Click End Sub End Class ' frmMain
Comment