Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Array won't read more than one input

dhess62dhess62 Member Posts: 7
I have this code, it needs to accept more than one letter to display as morse code characters. Right now it works well with only ONE letter, If you put more than ONE it doesn't work.

Ideas?

Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
Dim name() As String = {"A", "B", "C", "D"}
Dim code() As String = {". _ ", "_... ", "_ ._.", "_.."}
Dim subscript As Integer
Dim searchFor As String
searchFor = txtInputName.Text

Do While subscript = name.Length _
OrElse searchFor = name(subscript)
subscript = (subscript) + 1

Loop
If subscript < name.Length Then
lblShowCode.Text = code(subscript).ToString
End If

Comments

  • DaiMitnickDaiMitnick Member Posts: 77
    Here you go, I tweaked your code and this way worked for me. Hope this helps, let me know if you've any problem. Dai

    [code]
    Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
    Dim name() As String = {"A", "B", "C", "D"}
    Dim code() As String = {". _ ", "_... ", "_ ._.", "_.."}
    Dim subscript As Integer = -1
    Dim searchFor As String
    searchFor = txtInputName.Text.ToUpper
    Dim strConv As String = ""

    If searchFor.Length > 0 Then
    For i = 0 To searchFor.Length - 1
    subscript = Array.IndexOf(name, searchFor.Substring(i, 1))

    If subscript >= 0 Then
    strConv += code(subscript).ToString
    Else
    strConv += "
  • dhess62dhess62 Member Posts: 7
    Works Perfectly!!

    Thanks :)
Sign In or Register to comment.