При попытке открыть форму показывает ошибку Object variable not set (Error 91). И указывает на строку SheetChoise.Show
Visual Basic |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| Private Sub OptionButton1_Change()
If OptionButton1.Value = True Then 'Проверка выбора пользователя
TextBox1.Enabled = False 'Включаем возможность ввода
SheetChoise.Show 'Показываем форму выбора листа
End If
If OptionButton1.Value = True Or OptionButton2.Value = True And OptionButton3.Value = True Or OptionButton4.Value = True Then 'Проверяем выбор пользователя
CommandButton1.Enabled = True 'Включаем кнопку
End If
End Sub |
|
Код окна SheetChoise:
Visual Basic |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
| Dim arraylength As Integer
Dim matrix() As Integer
Private Sub CommandButton1_Click()
'Ïåðåìåííûå äëÿ õðàíåíèÿ äàííûõ î ìàññèâå è òåêóùåì ïîëîæåíèè âíóòðè åãî
Dim RowCount As Integer
Dim ColumnCount As Integer
'Ïðèñâîåíèå íà÷åíèé ïåðåìåííûõ
RowCount = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
ColumnCount = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
If (RowCount = ColumnCount) Then
arraylength = RowCount - 1 'Ñîõðàíåíèå ðàçìåðíîñòè ìàññèâà â ãëîáàëüíóþ ïåðåìåííóþ
ReDim matrix(arraylength, arraylength) 'Ïåðåîïðåäåëåíèå ðàçìåðíîñòè ìàññèâà
For infeksj = 0 To arraylength
For infeksi = 0 To arraylength
If IsNumeric(WorksheetFunction.CountA(infeksi + 2, infeksj + 2)) = False Then
'Ñîîáùåíèå îøèáêè è ïðîâåðêà âûáðàííîãî ïîëüçîâàòåëåì âàðèàíòà
If MsgBox("Îøèáêà. Ìàññèâ çàïîëíåí íåïðàâèëüíî." & vbNewLine & "Õîòèòå ëè âíåñòè èçìåíåíèÿ â ðàáî÷åé îáëàñòè?", vbYesNo) = vbYes Then
Application.Visible = True
End If
Exit For
Exit For
Else
matrix(infeksi, infeksj) = ActiveSheet.Cells(infeksi + 2, infeksj + 2).Value 'Ïðèñîâåíèÿ çíà÷åíèÿ ÿ÷åéêè ìàññèâà ñîîòâåòñòâóþùåãî çíà÷åíèÿ èç ëèñòà
End If
Next
Next
End If
End Sub
Private Sub CommandButton2_Click()
ThisWorkbook.Sheets.Add 'Äîáàâëåíèå íîâîãî ëèñòà
Application.Visible = True 'Ïîêàç ãëàâíîãî îêíà
ListBox1.Clear 'Î÷èùàåì ñïèñîê
Dim s As Worksheet 'Îáúÿâëåíèå ïåðåìåííîé îòâåòñòâåííîé çà òåêóùèé ëèñò
For Each s In ActiveWorkbook.Worksheets 'Ïåðåáîð âñåõ ëèñòîâ è äîáàâëåíèå èõ â ñïèñîê
ListBox1.AddItem s.Name
Next
End Sub
Private Sub ListBox1_Change()
Sheets(ListBox1.List(ListBox1.ListIndex.Selected)).Select 'Âûáèðàåì àêòèâíûé ëèñò
End Sub
Private Sub UserForm_Initialize()
Dim sheet As Worksheet 'Îáúÿâëåíèå ïåðåìåííîé îòâåòñòâåííîé çà òåêóùèé ëèñò
For Each s In ActiveWorkbook.Worksheets 'Ïåðåáîð âñåõ ëèñòîâ è äîáàâëåíèå èõ â ñïèñîê
ListBox1.AddItem sheet.Name
Next
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Application.Visible = False 'Ñêðûâàåì ãëàâíîå îêíî
End Sub |
|
А также при попытке открыть другое окно выдает ошибку Type mismatch (Error 13). И указывает на строку ArrayForm.Show
Visual Basic |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| Private Sub CommandButton1_Click()
If OptionButton2.Value = True And OptionButton3.Value = True Or OptionButton4.Value = True Then
If IsNull(TextBox1.Text) = False And IsNumeric(TextBox1.Value) = True Then
arraylength = TextBox1.Value - 1 ' Çàïèñü ðàçìåðà ìàññèâà â ïåðåìåííóþ
ReDim matrix(arraylength, arraylength) 'Ïåðåîïðåäåëåíèå ðàçìåðíîñòè ìàññèâà
Randomize
For infeksi = 0 To arraylength 'Çàïîëíåíèå ìàññèâà ñëó÷àéíûìè ÷èñëàìè
For infeksj = 0 To arraylength
matrix(infeksi, infeksj) = Int((max - min + 1) * Rnd + min)
Next
Next
If OptionButton3.Value = True Then 'Ïðîâåðêà âûáðàííûõ ïàðàìåòðîâ
ArrayForm.Show 'Ïîêàçûâàåì ôîðìó âûâîäà ìàññèâà
ElseIf OptionButton3.Value = True Then
Application.Visible = True 'Ïîêàçûâàåì ðàáî÷åãî îêíà Excel
End If
Else
MsgBox " ïîëå ââîäà ìîãóò áûòü òîëüêà ÷èñëà!" & vbNewLine & "Ïðîâåðüòå äàííûå è ïîâòîðèòå ïîïûòêó" 'Âûâîä ñîîáùåíèÿ îá îøèáêå
End If
End If
End Sub |
|
Код окна ArrayForm:
Visual Basic |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
| Dim arraylength As Integer
Dim matrix() As Integer
Private Sub CommandButton1_Click()
'Ïåðåìåííûå ñ÷åò÷èêè
Dim tempnumber As Integer
Dim temp As Integer
temp = 0
tempnumber = 0
'Ïðîâåðÿåì ïî ñòîëáöàì çíà÷åíèÿ ýëåìåíòîâ ìàññèâà è 0
For infeksj = 0 To arraylength
For infeksi = 0 To arraylength
If matrix(infeksi, infeksj) = 0 Then
temp = temp + 1
End If
Next
'Åñëè â ñòîëáöååñòü 0 óâåëè÷èâàåì êîëè÷åñòâî ñòîëáöîâ ñîäåðæàùèõ 0 íà 1
If temp >= 1 Then
tempnumber = tempnumber + 1
temp = 0
End If
Next
MsgBox "Êîëèåñòâî ñòîëáöîâ ñîäåðæàùèõ íóëåâîå çíà÷åíèå: " & tempnumber 'Âûâîä ðåçóëüòàòà
tempnumber = 0
End Sub
Private Sub CommandButton2_Click()
'Ïåðåìåííûå ñ÷åò÷èêè
Dim temprow As Integer
Dim tempnumber As Integer
Dim temp As Integer
temptow = InputBox("Ââåäèòå íîìåð ñòðîêè äëÿ êîòîðîé âûïîëíÿòü äåéñòâèå.")
tempnumber = 1
temp = 0
matrix = MainForm.GetArray
'Ïðîâåðÿåì âååäåííîå ïîëüçîâàòåëåì çíà÷åíèå íà ñîîòâåòñòâèå òðåáîâàíèÿì
If IsNumeric(temprow) = True And temprow <= arraylength Then
'Ñ÷èòàåì ïðîèçâåäåíèå âñåõ ýëåìåíòîâ ïîñëå ïåðâîãî íóëåâîãî çíà÷åíèÿ
For infeksi = 0 To arraylength
'ïðîâåðÿåì ñòðîêó íà íóæíûå çíà÷åíèÿ
If matrix(temprow, infeksi) = 0 Then
temp = temp + 1
End If
'Åñëè áûëî íàéäåíî íóæíîå çíà÷íåíèå íà÷èíàåì íàõîäèòü ïðîèçâåäåíèå
If temp > 0 Then
tempnumber = tempnumber * matrix(temprow, infeksi)
End If
Next
'Ïðîâåðêà íà íàëè÷èå õîòÿáû îäíîãî íóëåîãî çíà÷åíèÿ
If temp >= 1 Then
MsgBox "Ïðîèçâåäåíèå ýëåìåíòîâ ïîñëå íóäåâîãî çíà÷åíèÿ â ñòðîêå " & temp & " ðàâíî tempnumber"
Else
MsgBox "Èçâèíèòå ñ ñòðîêå " & temp & ", íå íàéäåíî íå îäíîãî çíà÷åíèÿ ðàâíîãî 0."
End If
tempnumber = 1
temp = 0
End If
End Sub
Private Sub CommandButton3_Click()
ChoiseForm.Show 'Îòîáðàæåíèå îêíà âûáîðà
End Sub
Private Sub UserForm_Initialize()
arraylength = MainForm.GetArrayLength
matrix = MainForm.GetArray
Dim temp As String
ListBox1.ColumnCount = arraylength 'Ìåíÿåì êîëè÷åñòâî ñòîëáöîâ
'Ôîðìèðîâàíèå îòîáðàæåíèÿ ìàññèâà
'Randomize
For infeksi = 0 To arraylength
For infeksj = 0 To arraylength
If infeksj < arraylength Then
'matrix(infeksi, infeksj) = Int((max - min + 1) * Rnd + min)
temp = temp + matrix(infeksi, infeksj) & ";"
Else
temp = temp + matrix(infeksi, infeksj)
End If
Next
ListBox1.AddItem temp
Next
End Sub |
|
Подскажите, что не так? И как то решить?
Думаю исходный файл вряд ли понадобится, но все же прикреплю