Dobrý den, docela mi hoří termín a já nejsem schopen přijijít na to jak udělat když napíšu do textboxu1 text aby se mi překládal do textboxu2 třeba jako čísla.... Když by bylo dáno že a=1 b=2 c=3 A já napsal acb aby se mi do truhého okna napsalo 132.. Prosím o radu děkuji. :)
Fórum › Visual Basic
Překlad A na 1

je to sice c# ale mel bys to snad pochopit
private Dictionary<char, char> replacements = new Dictionary<char, char>()
{
{'a', '1'},
{'b', '2'},
{'c', '3'},
{'d', '4'},
};
private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox2.Text = "";
foreach (var x in textBox1.Text)
if (replacements.ContainsKey(x))
textBox2.Text += replacements[x];
else
textBox2.Text += x;
}
a doporucuju textbox2 nastavit ReadOnly true
achjo. http://converter.telerik.com/
ps: ten kod co sem poslal je nejjednoduzsi a nejkratsi reseni a dela presne to co chcete. nejake extravagance s IFem z hlediska rozsiritelnosti a separovatelnosti kodu nedoporucuju.
A proč nevyužít Asc hodnoty každého znaku v Text1.Text?
a=64, b=65, c=66...
Private Sub Text1_Change()
Text2.Text = AlphaToNumeric(Text1.Text)
End Sub
Private Function AlphaToNumeric(ByVal Alpha As String, _
Optional ByVal AscDecrement As Integer = 64, _
Optional ByVal CaseSensitive As Boolean = False, _
Optional ByVal BlanksAllowed As Boolean = False) _
As String
Dim i As Integer
Dim tmp As String
Dim tmp2 As String
tmp = Text1.Text
If CaseSensitive = False Then tmp = UCase$(tmp)
If BlanksAllowed = False Then tmp = Replace$(tmp, " ", "")
For i = 1 To Len(tmp)
tmp2 = tmp2 & Round(Asc(Mid$(tmp, i, 1)) - AscDecrement)
Next
AlphaToNumeric = tmp2
i = tmp = tmp2 = Empty
End Function
Podle tohoto by se to mělo překládat.. -_- Byl bych schopen i zaplatit, jen abych to stihl.. :)
#7 Petr Zbořil
Oprava: A=65, B=66, C=67... a=97, b=98, c=99
' Dva textboxy
' v IDE nastavit:
' Text1.MultiLine = True
' Text2.MultiLine = True
Private Sub Text1_Change()
Dim i As Integer
Dim Code As String
Text2.Text = ""
For i = 1 To Len(Text1.Text)
Code = ""
If Mid$(Text1.Text, i, 1) = "a" Then Code = ".-"
If Mid$(Text1.Text, i, 1) = "b" Then Code = "-..."
If Mid$(Text1.Text, i, 1) = "c" Then Code = "-.-."
If Mid$(Text1.Text, i, 1) = " " Then Code = "|"
'...
If Code <> "" Then
Text2.Text = Text2.Text & Code
If i < Len(Text1.Text) And Code <> "|" Then
Text2.Text = Text2.Text & "|"
End If
End If
Next i
End Sub
Tohle je funkční, ale hodně pomalé a amatérské :)
Taky bych určitě průběžně čistil Text1.Text od nepřeložitelných znaků a nadbytečných mezer.

Přidej příspěvek
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
































Uživatelé prohlížející si toto vlákno
Podobná vlákna
Překlad na P4 — založil 16bit
Překlad programu — založil David Kolibřík
Preklad z AJ do CJ PLS — založil Tomáš
Moderátoři diskuze