|
-
Apr 21st, 2010, 07:49 PM
#1
Re: good old arrays
Try this:
Code:
Option Explicit
Private Type Student
strName As String
intMark As Integer
End Type
Dim Students() As Student
Private Sub cmdAddRecord_Click()
Dim iMark As Long
Dim sName As String
Dim i As Long
sName = Trim(txtStudentName.Text)
If sName = "" Then
MsgBox "student name cannot be blank. Please re-enter it"
Exit Sub
End If
iMark = Val(txtStudentMark.Text)
If iMark < 0 Then
MsgBox "student mark cannot be less than zero. Please re-enter it"
Exit Sub
ElseIf iMark > 100 Then
MsgBox "student mark cannot be greater than 100. Please re-enter it"
Exit Sub
End If
If (Not Students) = -1 Then '-- Students() array was not initialized
i = 1
Else
i = UBound(Students) + 1
End If
ReDim Preserve Students(1 To i)
Students(i).strName = sName
Students(i).intMark = iMark
lstNames.AddItem sName
lstMarks.AddItem iMark
End Sub
-
Apr 22nd, 2010, 03:25 AM
#2
Re: good old arrays
 Originally Posted by anhn
Try this:
Code:
Option Explicit
Private Type Student
strName As String
intMark As Integer
End Type
Dim Students() As Student
Private Sub cmdAddRecord_Click()
Dim iMark As Long
Dim sName As String
Dim i As Long
sName = Trim(txtStudentName.Text)
If sName = "" Then
MsgBox "student name cannot be blank. Please re-enter it"
Exit Sub
End If
iMark = Val(txtStudentMark.Text)
If iMark < 0 Then
MsgBox "student mark cannot be less than zero. Please re-enter it"
Exit Sub
ElseIf iMark > 100 Then
MsgBox "student mark cannot be greater than 100. Please re-enter it"
Exit Sub
End If
If (Not Students) = -1 Then '-- Students() array was not initialized
i = 1
Else
i = UBound(Students) + 1
End If
ReDim Preserve Students(1 To i)
Students(i).strName = sName
Students(i).intMark = iMark
lstNames.AddItem sName
lstMarks.AddItem iMark
End Sub
I had already suggested and posted the code for using dynamic array in post #21
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|