Write a program in which a text string of Latin letters and auxiliary characters is first entered upon request. It is required to replace in it all the occurrences of the small letter β€œa” by 1, the small letter β€œb” by 22, β€œc” - by 333. In the new line, count the number of digits. The final line and the number of digits to issue on the screen. It turned out just that ... but nothing goes

Dim Len, k,m,n, i As Integer Dim Str, StrNew As String Dim Ch As Char Str = InputBox("Π’Π²Π΅Π΄ΠΈΡ‚Π΅ строку ΠΈΠ· латинских Π±ΡƒΠΊΠ² ΠΈ Π²ΡΠΏΠΎΠΌΠΎΠ³Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹Ρ… символов") For i = 1 To Len 'ΠŸΡ€ΠΎΡ…ΠΎΠ΄ ΠΏΠΎ строкС Str Ch = Mid(Str, i, 1) 'Π’Ρ‹Π΄Π΅Π»Π΅Π½ΠΈΠ΅ ΠΎΡ‡Π΅Ρ€Π΅Π΄Π½ΠΎΠ³ΠΎ символа If Ch = "a" Then k = k + 1 ' Π‘Ρ€Π°Π²Π½Π΅Π½ΠΈΠ΅ символа с Π±ΡƒΠΊΠ²ΠΎΠΉ Π° ΠΈ подсчСт Π²Ρ…ΠΎΠΆΠ΄Π΅Π½ΠΈΠΉ If Ch = "b" Then n = m + 22 ' Π‘Ρ€Π°Π²Π½Π΅Π½ΠΈΠ΅ символа с Π±ΡƒΠΊΠ²ΠΎΠΉ b ΠΈ подсчСт Π²Ρ…ΠΎΠΆΠ΄Π΅Π½ΠΈΠΉ If Ch = "c" Then n = n + 333 ' Π‘Ρ€Π°Π²Π½Π΅Π½ΠΈΠ΅ символа с Π±ΡƒΠΊΠ²ΠΎΠΉ c ΠΈ подсчСт Π²Ρ…ΠΎΠΆΠ΄Π΅Π½ΠΈΠΉ Next i MsgBox(" Число Π²Ρ…ΠΎΠΆΠ΄Π΅Π½ΠΈΠΉ ΠΌΠ°Π»ΠΎΠΉ латинской Π±ΡƒΠΊΠ²Ρ‹ Π° Ρ€Π°Π²Π½ΠΎ ") MsgBox(" Число Π²Ρ…ΠΎΠΆΠ΄Π΅Π½ΠΈΠΉ ΠΌΠ°Π»ΠΎΠΉ латинской Π±ΡƒΠΊΠ²Ρ‹ b Ρ€Π°Π²Π½ΠΎ ") MsgBox(" Число Π²Ρ…ΠΎΠΆΠ΄Π΅Π½ΠΈΠΉ ΠΌΠ°Π»ΠΎΠΉ латинской Π±ΡƒΠΊΠ²Ρ‹ c Ρ€Π°Π²Π½ΠΎ ") End 
  • Hm And where is the replacement in your code? See: Ch = Mid(Str, i, 1) received another character, If Ch = "a" checked if it was not "a" , but what does k = k + 1 go k = k + 1 and what do you really need? And the Len value is not calculated anywhere, where can it be correct? - VladD
  • Something bad for me from such a solution can be solved firstly by a simpler problem, counting only the letters "a" for example - sercxjo

1 answer 1

Len - the word is reserved, you should not declare it, there will be uncertainties.

 Dim S as String, S_new as String, S_clear as String Dim counterA as Integer S = InputBox("Π’Π²Π΅Π΄ΠΈΡ‚Π΅ строку ΠΈΠ· латинских Π±ΡƒΠΊΠ² ΠΈ Π²ΡΠΏΠΎΠΌΠΎΠ³Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹Ρ… символов") ' ЗамСняСм S_new = Replace(S, "a", "1") S_new = Replace(S_new, "b", "22") S_new = Replace(S_new, "c", "333") ' Π£Π±ΠΈΡ€Π°Π΅ΠΌ Ρ†ΠΈΡ„Ρ€Ρ‹ ΠΈΠ· строки S_clear = Replace(S_new, "1", "") S_clear = Replace(S_clear, "2", "") S_clear = Replace(S_clear, "3", "") S_clear = Replace(S_clear, "4", "") S_clear = Replace(S_clear, "5", "") S_clear = Replace(S_clear, "6", "") S_clear = Replace(S_clear, "7", "") S_clear = Replace(S_clear, "8", "") S_clear = Replace(S_clear, "9", "") S_clear = Replace(S_clear, "0", "") ' Π‘Ρ‡ΠΈΡ‚Π°Π΅ΠΌ, Π½Π° сколько ΡƒΠΌΠ΅Π½ΡŒΡˆΠΈΠ»Π°ΡΡŒ Π΄Π»ΠΈΠ½Π° строки ΠΏΡ€ΠΈ ΡƒΠ΄Π°Π»Π΅Π½ΠΈΠΈ Ρ†ΠΈΡ„Ρ€ counterA = Len(S_new) - Len(S_clear) MsgBox("Π˜Ρ‚ΠΎΠ³ΠΎΠ²Π°Ρ строка: " & S_new & "," & vbCrLf & "Число Ρ†ΠΈΡ„Ρ€: " & CStr(counterA)) 

Let me explain: vbCrLf is a line break. Connect different strings with an ampersand ( & )