Visual basic написать процедуру для нахождения отрицательных и положительных чисел из строки, состоящий из произвольного набора цифр и букв. *перевести полученное число в его двоичный код *найти максимальное из чисел
Function Bin(s As String, z As Integer) As String Dim c As Integer Dim oct As Integer c = Val(s) Do oc = c Mod 2 c = c \ 2 Bin = Bin & Str(oc) Loop Until c = 0 Bin = StrReverse(Bin) If z = -1 Then Bin = "-" & Bin End Function
Sub z() Dim s As String, s1 As String Dim n As Integer, i As Integer, z As Integer Dim max s = InputBox("Введите строку: ") max = Null i = 1 Do While i <= Len(s) Select Case Mid(s, i, 1) Case 0 To 9 If z = 0 And i > 1 Then z = IIf(Mid(s, i - 1, 1) = "-", -1, 1) Else: z = 1 End If s1 = s1 + Mid(s, i, 1) If i = Len(s) Then GoSub 1 Case Else: If s1 <> "" Then GoSub 1 End Select i = i + 1 Loop MsgBox ("max=" & max) End 1: n = z * Val(s1) MsgBox (n & "; двоичная форма: " & Bin(s1, z)) If IsNull(max) Then max = n If max < n Then max = n z = 0 s1 = "" Return End Sub
Function Bin(s As String, z As Integer) As String
Dim c As Integer
Dim oct As Integer
c = Val(s)
Do
oc = c Mod 2
c = c \ 2
Bin = Bin & Str(oc)
Loop Until c = 0
Bin = StrReverse(Bin)
If z = -1 Then Bin = "-" & Bin
End Function
Sub z()
Dim s As String, s1 As String
Dim n As Integer, i As Integer, z As Integer
Dim max
s = InputBox("Введите строку: ")
max = Null
i = 1
Do While i <= Len(s)
Select Case Mid(s, i, 1)
Case 0 To 9
If z = 0 And i > 1 Then
z = IIf(Mid(s, i - 1, 1) = "-", -1, 1)
Else: z = 1
End If
s1 = s1 + Mid(s, i, 1)
If i = Len(s) Then GoSub 1
Case Else:
If s1 <> "" Then GoSub 1
End Select
i = i + 1
Loop
MsgBox ("max=" & max)
End
1: n = z * Val(s1)
MsgBox (n & "; двоичная форма: " & Bin(s1, z))
If IsNull(max) Then max = n
If max < n Then max = n
z = 0
s1 = ""
Return
End Sub