2016-08-07 3 views
2

그래서 배열에 항목을 추가하고 배열의 모든 항목을 텍스트 상자에 반환하려고합니다. 누군가 내가 뭘 잘못하고 있다고 말할 수 있습니까? 버튼을 클릭하면 오류가 발생하거나 system.string[]이 표시되거나 전체 또는 일부 항목이 하나만 표시됩니다. edit1 : 여기에 업데이트 된 코드가 있습니다. 당신이 당신의 strletters 문자열에서 'A'와 'B'는 다른 어떤 문자가있는 경우모든 배열 내용을 텍스트 상자에 표시

Public Class Form1 
    Dim x As Integer = 0 
    Dim strencode As String 
    Dim strletters As String 
    Dim strholder(0 To 999) As String 


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
     strletters = TextBox1.Text 
     Label2.Text = x.ToString 
     If TextBox1.TextLength < x Then 
      x = 0 

     End If 


     If TextBox1.TextLength <> 0 Then 
      If TextBox1.TextLength < x Then 
       x = 0 
      End If 



      Do Until x = TextBox1.TextLength 
       If TextBox1.TextLength < x Then 
        x = 0 
       End If 
       If TextBox1.TextLength <> 0 Then 
        If strletters.Substring(x, 1) = "A" Then 
         strholder(x) = "346," 
         x = x + 1 
        ElseIf strletters.Substring(x, 1) = "B" Then 
         strholder(x) = "917," 
         x = x + 1 
        End If 




       End If 
      Loop 


pause: 





      Dim i As Integer 
      For i = 0 To (x - 1) 
       TextBox2.Text = (strholder(i)) 
      Next 

     End If 
    End Sub 

End Class 
+0

어떤 코드 줄에 어떤 오류 메시지가 표시됩니까? – dbmitch

+0

코드에서 수행해야하는 작업보다는 기능/동작으로 달성하려는 작업을 이해하는 데 필요한 초기 "상태"/ 최종 "상태"를 추가해야합니다. – Sehnsucht

+0

이 줄을 다음으로 업데이트하십시오. TextBox2.Text & = strholder (i) – EJD

답변

0

귀하의 Do Until 블록은 무기한 계속 될 것이다. 쉽게 String.Join를 사용하여 strholder 배열의 출력을 연결할 수 있습니다, 또한

Do Until x = TextBox1.TextLength 
    ' Some conditions 
    ' Some more conditions   
    x = x + 1 ' Increment regardless 
Loop 

: 항상 x 값을 증가해야

TextBox2.Text = String.Join(String.Empty, strholder) 

업데이트 : 여기

가있는 코드입니다 다른 방법의 몇 가지 ...

Public Class Form1 
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
     ' Converting a string to a char array 
     Dim charArray() As Char = TextBox1.Text.ToCharArray 
     ' Converting a string to a string array 
     Dim stringArray() As String = TextBox1.Text.Select(Function(c) c.ToString).ToArray 

     ' Concatenate using a For Each loop 
     For Each ch In charArray ' or stringArray 
      ' do something with each ch... 
      TextBox2.Text &= ch ' Concatenate using the & operator 
      'TextBox2.Text += ch ' Concatenate using the + operator 
     Next 

     ' Converting a char array back to a string 
     TextBox2.Text = String.Join(String.Empty, charArray) 
     ' Converting a string array back to a string, method 1 
     TextBox2.Text = String.Join(String.Empty, stringArray) 
     ' Converting a string array back to a string, method 2 
     TextBox2.Text = stringArray.Aggregate(Function(final, sCh) final & sCh) 

     ' In your case you could just simply... 
     TextBox2.Text = TextBox1.Text.Replace("A"c, "346,").Replace("B"c, "917,") 
    End Sub 
End Class 

마찬가지로 연결 연산자를 선택하는 경우 살펴보기 this

관련 문제