By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,743 Members | 1,072 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,743 IT Pros & Developers. It's quick & easy.

Snagged on New Create Object

geo039
P: 47
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.

Expand|Select|Wrap|Line Numbers
  1. Public Class frmMain
  2.     Inherits System.Windows.Forms.Form
  3.  
  4.     Private m_objName(2) As Course     ' Client object
  5.     Private m_intPosition As Integer = 0 ' current account
  6.  
  7. Private Sub frmMain_Load(ByVal sender As System.Object, _
  8.         ByVal e As System.EventArgs) Handles MyBase.Load
  9.  
  10.         Dim intCount As Integer ' counter variable
  11.  
  12.         ' array of course names
  13.         Dim strCourseName() As String = _
  14.            New String() {"Science", "History", "Math"}
  15.  
  16.         ' array of course numbers
  17.         Dim strCourseNumber() As String = _
  18.            New String() {"S123", "H123", "M123"}
  19.  
  20.         'array of start date 
  21.         Dim strStartDate() As String = _
  22.            New String() {"2/27/07", "2/28/07", "3/1/07"}
  23.  
  24.         'array of start date 
  25.         Dim strEndDate() As String = _
  26.            New String() {"4/10/07", "4/11/07", "4/12/07"}
  27.  
  28.         ' loop and create more course objects
  29.         For intCount = 0 To m_objName.GetUpperBound(0)
  30.  
  31.             ' create new object and store into Client array
  32.             m_objName(intCount) = New Course(strCourseName(intCount), _
  33.                strCourseNumber(intCount), strStartDate(intCount), _
  34.                strEndDate(intCount))
  35.         Next
  36.     End Sub
  37.  
  38.     Private Sub btnNext_Click(ByVal sender As System.Object, _
  39.         ByVal e As System.EventArgs) Handles btnNext.Click
  40.  
  41.         m_intPosition += 1 ' increment position
  42.  
  43.         ' if position is last (top) object
  44.         If m_intPosition > m_objName.GetUpperBound(0) Then
  45.             m_intPosition = 0    ' set to first position in array
  46.             DisplayInformation() ' display information
  47.         Else
  48.             DisplayInformation()
  49.         End If
  50.  
  51.     End Sub
  52.  
  53.     Private Sub btnPrev_Click(ByVal sender As System.Object, _
  54.         ByVal e As System.EventArgs) Handles btnPrev.Click
  55.  
  56.         m_intPosition -= 1 ' decrement position
  57.  
  58.         ' if position is last (bottom) object
  59.         If m_intPosition < 0 Then
  60.  
  61.             ' set to last position in array
  62.             m_intPosition = m_objName.GetUpperBound(0)
  63.             DisplayInformation()
  64.         Else
  65.             DisplayInformation() ' display information
  66.         End If
  67.  
  68.     End Sub
  69.  
  70.     ' display information
  71.     Private Sub DisplayInformation()
  72.  
  73.         ' use m_intPosition as index for each object
  74.         txtCourseName.Text = m_objName(m_intPosition).Name
  75.         txtCourseNumber.Text = m_objName(m_intPosition).Number
  76.         txtCourseStart.Text = _
  77.            Convert.ToString(m_objName(m_intPosition).Start)
  78.         txtCourseEnd.Text = _
  79.            Convert.ToString(m_objName(m_intPosition).CEnd)
  80.  
  81.  
  82.     End Sub ' DisplayInformation
  83.  
  84.     Private Sub btnCreate_Click(ByVal sender As System.Object, _
  85.         ByVal e As System.EventArgs) Handles btnCreate.Click
  86.  
  87.  
  88.  
  89.     End Sub
  90. End Class ' frmMain
Mar 1 '07 #1
Share this Question
Share on Google+
1 Reply


kenobewan
Expert 2.5K+
P: 4,871
I believe that you will need to store the arrays values, in a file or db table, then update and reload page binding data to arrays.
Mar 4 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.