Предмет: Информатика, автор: 11max

Задача в VBA
Дана строка S и число N. Преобразовать строку S в строку длины N следующим образом: если длина строки S больше N, то отбросить первые символы, если длина строки S меньше N, то в ее начало добавить символы "." (точка).


11max: вот то, что у меня не получается
Sub str_4()
Dim a, k, b
Dim i, n
a = InputBox("slovo")
b = InputBox("bykva")
n = 0
For i = 1 To Len(a)
k = Mid(a, i, 1)
n = n + 1
Next i
If n > b Then a = Mid(a, i, 0) Else: a = "." + a
MsgBox a
End Sub

Ответы

Автор ответа: Аноним
1
Sub str_4()
On Error GoTo Handler

Dim S As String
Dim N As Integer

S = InputBox("Stroka?")
N = InputBox("Chislo?")

If Len(S) > N Then S = Right(S, N)

While Len(S) < N
S = "." + S
Wend

MsgBox (S)
End

Handler:
MsgBox "Oshibka!"

End Sub
Автор ответа: Аноним
0
Sub aaa()
    s = InputBox("Введите строку")
    n = CInt(InputBox("Введите длину N"))
    m = Len(s)
    If m > n Then
        s = Right(s, n)
    Else
        If m < n Then s = String(n - m, ".") + s
    End If
    MsgBox "Результат: " + s, vbInformation
End Sub

Похожие вопросы
Предмет: Английский язык, автор: lovestep2006
Помогите сделать краткий пересказ этого текста на английском:
Christmas is Christian holiday that celebrates the birth of Jesus Christ. For millions of Christians throughout the world it is the happiest and the busiest time of the year. No one knows the exact date of Christ's birth but most Christians celebrate Christmas on December 25. The word Christmas comes from Christes masse, an early English phrase that means Mass of Christ.
People of different countries celebrate Christmas in various ways. People in the United States and Canada decorate their homes with Christmas trees, wreaths and ornaments. City streets are filled with coloured lights; the sound of bells and Christmas carols can be heard everywhere.
Children write letters to Santa Claus and tell him what presents they would like to get. Many department stores hire people to wear a Santa Claus costume and listen to children's requests. People send Christmas cards to relatives and friends. Many companies give presents to their employees.
A Christmas tree is one of the main symbols of Christmas in most homes. Relatives and friends may join in trimming the tree with lights, tinsel, and colourful ornaments. Presents are placed under the tree. On Christmas Eve or Christmas morning, families open their presents.
Many children believe that Santa Claus arrives on Christmas Eve in a sleigh pulled by a reindeer and brings presents. Some children hang up stockings so Santa Claus can fill them with candy, fruit and other small gifts.
In many parts of the United States and Canada groups of people walk from house to house and sing Christmas carols. Some people give singers money or small gifts or invite them for a warm drink.
Many people attend church services on Christmas Eve or Christmas morning. They listen to readings from Bible and singing Christmas carols.
A traditional Christmas dinner consists of stuffed turkey, ь mashed potatoes, cranberry sauce and a variety of other dishes. Some families have ham or roast goose instead of turkey. Pumpkin pie, plum pudding, and fruitcake are favourite desserts.
Предмет: Математика, автор: nataboklan