Задача на типы - VB
Формулировка задачи:
Здравствуйте, задали задачу, но не могу сделать так, чтобы выводились только фамилии и номера групп для всех студентов, имеющих оценки 7,8,9. Помогите пожалуйста подправить что не правильно. Заранее благодарю! Задача 2 вариант.
Решение задачи: «Задача на типы»
textual
Листинг программы
Option Explicit Const r = 90 Const fio = " ФИО студента: ", ng = " Номер группы: ", so = " Средняя оценка: ", vvs = "Вывести все", z = ", " Dim WithEvents cb As CommandButton, WithEvents lb As ListBox, i&, j&, v, s$, l&, t&, w&, h&, ї&, ID& Private Type Student Full_Name As String Group_Number As Long Evaluation As Long End Type Dim Students() As Student Private Sub lb_Click() EnCtrl lb.ListIndex > -1, "cb2" End Sub Private Sub cb_Click() Dim a$, b$, c$, ss As String * 10 Select Case Mid$(cb.Name, 3) Case 1 v = GenFIO a = InputBox(fio & ID, , v(0) & v(1) & v(2)): If a = "" Then Exit Sub b = InputBox(ng, , Rnd * 100 \ 1 + 100): If val(b) = 0 Then Exit Sub c = InputBox(so, , Rnd * 8 \ 1 + 1): If val(c) = 0 Then Exit Sub ReDim Preserve Students(ID) With Students(ID) .Full_Name = a: .Group_Number = b: .Evaluation = c: ID = ID + 1 lb.AddItem a & z & ng & b & z & so & c End With Case 2 With lb i = .ListIndex .RemoveItem .ListIndex .ListIndex = IIf(i > 0, i - 1, IIf(.ListCount > 0, 0, -1)) End With refStudents Case 3 v = Split(0): ReDim Preserve v(lb.ListCount - 1) For i = 0 To UBound(v): RSet ss = Students(i + 1).Evaluation: v(i) = ss & "." & lb.List(i): Next qSort v, 0, i - 1: lb.Clear For i = 0 To UBound(v): lb.AddItem Mid$(v(i), 12): Next: refStudents Case 4 s = cb.Caption: cb.Caption = cb.Tag: cb.Tag = s lb.Clear If cb.Caption = vvs Then For i = 1 To UBound(Students) With Students(i) Select Case .Evaluation Case 7, 8, 9: lb.AddItem .Full_Name & z & ng & .Group_Number & z & so & .Evaluation End Select End With Next EnCtrl 0, "cb1", "cb2", "cb3": Exit Sub Else For i = 1 To UBound(Students) With Students(i) lb.AddItem .Full_Name & z & ng & .Group_Number & z & so & .Evaluation End With Next EnCtrl 1, "cb1", "cb2", "cb3" End If End Select If lb.ListCount > 0 Then EnCtrl 1, "cb3", "cb4" lb_Click End Sub Private Sub Form_Load() With Controls.Add("vb.ListBox", "lb") a l, r, t, r, w, .Width * 8, h, .Height * 4: .Move l, t, w, h .Visible = 1 End With a l, r, t, t + h, i, 1, ID, 1 For Each v In Array("Добавить студента", "Удалить студента", "Сортировать по оценке", "Вывести 7,8,9") With Controls.Add("vb.CommandButton", "cb" & i) a w, .Width, h, .Height: .Move l, t, w, h: a l, l + w + r, i, i + 1 .Caption = v: .Visible = 1 End With Next EnCtrl 0, "cb2", "cb3", "cb4": Controls("cb4").Tag = vvs ApplyFinalProp "Вариант 2" Randomize Timer End Sub Private Function GenFIO() GenFIO = Array(Choose(Rnd * 4 \ 1 + 1, "Каац ", "Цилька ", "Зеев ", "Лысобык ", "Немнихер "), _ Choose(Rnd * 4 \ 1 + 1, "Абрам ", "Яков ", "Моня ", "Давид ", "Гриша "), _ Choose(Rnd * 4 \ 1 + 1, "Иванович", "Петрович", "Сидорович", "Ахмедович", "Мухамедович")) End Function Private Sub ApplyFinalProp(Optional ByVal Caption$): Dim w&, h& For Each v In Me.Controls If v.Left + v.Width > w Then w = v.Left + v.Width If v.Top + v.Height > h Then h = v.Top + v.Height Next With Me: .Width = w + (.Width - .ScaleWidth) + r: .Height = h + (.Height - .ScaleHeight) + r: .Caption = Caption: End With End Sub Private Sub refStudents() Erase Students For ID = 1 To lb.ListCount: ReDim Preserve Students(ID) With Students(ID) v = Split(lb.List(ID - 1), ng): .Full_Name = Left(v(0), InStr(1, v(0), z) - 1) v = Split(v(1), so): .Group_Number = val(v(0)): .Evaluation = val(v(1)) End With Next End Sub Sub qSort(Arr, ByVal mn As Long, ByVal mx As Long) Dim i As Long, l As Long, j As String, s As String i = mn: l = mx: j = Arr((i + l) \ 2) Do Until i > l: Do While Arr(i) < j: i = i + 1: Loop: Do While Arr(l) > j: l = l - 1: Loop If (i <= l) Then s = Arr(i): Arr(i) = Arr(l): Arr(l) = s: i = i + 1: l = l - 1 Loop If mn < l Then qSort Arr, mn, l If i < mx Then qSort Arr, i, mx End Sub Private Sub cb_LostFocus(): LostFocus: End Sub Private Sub lb_LostFocus(): LostFocus: End Sub Private Sub EnCtrl(ByVal val&, ParamArray e()): For Each v In e: Controls(v).Enabled = val: Next: End Sub Private Sub a(ParamArray e()): For ї = 1 To UBound(e) Step 2: e(ї - 1) = e(ї): Next: End Sub Private Sub Form_Activate(): Set lb = Controls("lb"): lb.SetFocus: End Sub Private Sub LostFocus(): On Error Resume Next: Set lb = ActiveControl: Set cb = ActiveControl: End Sub
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д