Bosper »
Zdar, moc mi nejde ukol z VBA a tak pěkně prosím o pomoc. Řešení v podstatě mám, jen mi nejde nastavit výstup. (Ta funkce na mě jen zařve takovou tu chybu s #VALUE nebo jak se to jmenuje.)
Zadání:
Write a Public Function named “Reverse” that returns an array with two items (the output will be a row vector with two items) – (1) reverse string so that the last letter will be the first (for instance “school” => "loohcs") and (2) the length of the string. The user can decide whether all letters of the reverse string should be in upper case or whether all letters should be in down case. The function should take two arguments: (1) the string to be converted and (2) a (Boolean) parameter that indicates whether all letters should be in upper case or whether all letters should be in lower case.
A můj kód:
Public Function Reverse(input_string As String, upper_case As Boolean) As Range
Dim char As Integer
Dim reversed As String
char = Len(input_string) 'Length of the string
Dim matrix() As Variant
ReDim matrix(1 To 1, 1 To 2)
matrix(1, 2) = char 'Load it to the second place
'Now we transform the string
If upper_case Then
reversed = UCase(StrReverse(input_string))
Else: reversed = LCase(StrReverse(input_string))
End If
matrix(1, 1) = reversed 'Load it to the first place
Reverse = matrix 'Recognize the function output as the matrix
End Function