Last active
August 29, 2015 14:15
-
-
Save stansidel/244dd812b59666b82e11 to your computer and use it in GitHub Desktop.
Решение задач на VBA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Individual1() | |
Do | |
m = InputBox("Введите номер месяца (1-12)") | |
Loop While m < 1 Or m > 12 | |
Select Case m | |
Case 1 | |
s = "январь" | |
Case 2 | |
s = "февраль" | |
Case 3 | |
s = "март" | |
Case 4 | |
s = "апрель" | |
Case 5 | |
s = "май" | |
Case 6 | |
s = "июнь" | |
Case 7 | |
s = "июль" | |
Case 8 | |
s = "август" | |
Case 9 | |
s = "сентябрь" | |
Case 10 | |
s = "октябрь" | |
Case 11 | |
s = "ноябрь" | |
Case 12 | |
s = "декабрь" | |
End Select | |
MsgBox ("Название месяца " + s) | |
End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Individual2() | |
Do | |
m = InputBox("Введите номер месяца (1-12)") | |
Loop While m < 1 Or m > 12 | |
m = m + 1 | |
If m = 13 Then | |
m = 1 | |
End If | |
Select Case m | |
Case 1 | |
s = "январь" | |
Case 2 | |
s = "февраль" | |
Case 3 | |
s = "март" | |
Case 4 | |
s = "апрель" | |
Case 5 | |
s = "май" | |
Case 6 | |
s = "июнь" | |
Case 7 | |
s = "июль" | |
Case 8 | |
s = "август" | |
Case 9 | |
s = "сентябрь" | |
Case 10 | |
s = "октябрь" | |
Case 11 | |
s = "ноябрь" | |
Case 12 | |
s = "декабрь" | |
End Select | |
MsgBox ("Название следующего месяца " + s) | |
End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Problem1() | |
For k = 1 To 99 | |
Select Case k Mod 10 | |
Case 1 | |
kString = "год" | |
Case 2, 3, 4 | |
kString = "года" | |
Case Else | |
kString = "лет" | |
End Select | |
If ((k > 10) And (k < 20)) Then | |
kString = "лет" | |
End If | |
Cells(k, 1).Value = "Мне " + CStr(k) + " " + kString | |
Next k | |
End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Problem2() | |
y = InputBox("Введите год") | |
Do | |
m = InputBox("Введите номер месяца (1-12)") | |
Loop While m < 1 Or m > 12 | |
Select Case m | |
Case 1, 3, 5, 7, 8, 10, 12 | |
n = 31 | |
Case 2 | |
If y Mod 400 = 0 Or (y Mod 4 = 0 And Not y Mod 100 = 0) Then | |
n = 29 | |
Else | |
n = 28 | |
End If | |
Case Else | |
n = 30 | |
End Select | |
MsgBox ("Количество дней в месяце: " + CStr(n)) | |
End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Problem3() | |
Do | |
m = InputBox("Введите число (0-9)") | |
Loop While m < 0 Or m > 9 | |
Select Case m | |
Case 0 | |
s = "zero" | |
Case 1 | |
s = "one" | |
Case 2 | |
s = "two" | |
Case 3 | |
s = "three" | |
Case 4 | |
s = "four" | |
Case 5 | |
s = "five" | |
Case 6 | |
s = "six" | |
Case 7 | |
s = "seven" | |
Case 8 | |
s = "eight" | |
Case 9 | |
s = "nine" | |
End Select | |
MsgBox ("The digit is called " + s) | |
End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a) k = 6; p=false; d=3; | |
b) k = 235; p=true; d=235; | |
c) k = 71; p=true; d=1; | |
d) k = 7.2; выполнение невозможно - оператор mod работает только с целочисленными значениями | |
e) k = 73; p=true; d=73; | |
p= true | |
d=1 | |
Select Case k mod 10 | |
Case 3,2,7,5 | |
d = k | |
Case 4,8 | |
p = false | |
d =2 | |
Case 9,6 | |
p = false | |
d =3 | |
End Select |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub WarmupExercise() | |
k = InputBox("Enter k") | |
p = True | |
d = 1 | |
Select Case k Mod 10 | |
Case 3, 2, 7, 5 | |
d = k | |
Case 4, 8 | |
p = False | |
d = 2 | |
Case 9, 6 | |
p = False | |
d = 3 | |
End Select | |
MsgBox ("p = " + CStr(p) + "; d = " + CStr(d)) | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment