VBA – domaci 2 uradjen

Posted: oktobar 17, 2011 in Uncategorized
Oznake:, , ,

VBA – domaci 2 uradjen

1. Zadatak
Function D1(Ulaz As String) As String
Dim I As Integer, J As Integer, JeliHex As Boolean, Sum As Integer, BrojHex As String
JeliHex = False
BrojHex = „“
Sum = 0
For I = 1 To Len(Ulaz)
If Mid(Ulaz, I, 1) Like „[0-9]“ Or Mid(Ulaz, I, 1) Like „[A-F]“ Then
BrojHex = BrojHex & Mid(Ulaz, I, 1)
End If
Next
If Len(BrojHex) = Len(Ulaz) And Len(BrojHex) <> 0 Then
JeliHex = True
End If
If JeliHex = False Then
For J = 1 To Len(Ulaz)
If Mid(Ulaz, J, 1) Like „[0-9]“ Then
Sum = Sum + 1
End If
Next
D1 = „String ne predstavlja heksadecimalni zapis, a broj cifara u stringu je“ & “ “ & Sum
End If
If JeliHex = True Then
D1 = „String predstavlja heksadecimalni zapis i njegova dekadna vrijednost je“ & “ “ & CLng(„&H“ & Ulaz)
End If
End Function

2.Zadatak
Function D2(S1 As String, S2 As String) As String
Dim I As Integer, S3 As String
S3 = „“
For I = 1 To Len(S1)
If Mid(S1, I, 1) Like „[A-Z]“ Then
S3 = S3 + Mid(S1, I, 1)
End If
Next
For I = 1 To Len(S2)
If Mid(S2, I, 1) Like „[A-Z]“ Then
S3 = S3 + Mid(S2, I, 1)
End If
Next
D2 = S3
End Function

3. Zadatak
Sub D3()
Dim I As Integer, J As Integer
Dim Opseg As Range

Set Opseg = Worksheets(„Sheet1“).Range(„A1:C4“)

For I = 1 To Opseg.Rows.Count
For J = 1 To Opseg.Columns.Count
If Opseg.Cells(I, J).Value < 0 Then
Opseg.Cells(I, J).Value = Opseg.Cells(I, J).Value + 1
End If

If Opseg.Cells(I, J).Value > 0 Then
Opseg.Cells(I, J).Value = Opseg.Cells(I, J).Value – 3

End If
Next
Next

End Sub

Advertisements

Zatvoreno za komentare.