2013-10-31 4 views
0

나는 다음과 같은 코드로 프로그램이 있습니다묶지 않고 변수를 함께 추가하는 방법은 무엇입니까?

Dim Var1 as string = textbox1.text 

Dim Var2 as string = textbox2.text 

Dim Var3 as string = textbox3.text 

Dim EndVar as string = Var1 + Var2 + Var3 

은 사용자가 내가 EndVar 6 동일 할 세 가지 텍스트 상자 변수, 2, 3을 하나 입력 가정 수 있습니다,하지만 어떻게 나에게 123 제공 나에게 6 달러를 줄거야?

답변

0

당신은 int 형을 요약 한 후 문자열로 다시 변환하는 그들 각각을 변환 할 수 있습니다 : 당신이 필요로하는 어떤

Dim EndVar as string = (Convert.toInt32(Var1) + Convert.toInt32(Var2) + Convert.toInt32(Var3)).ToString(); 
+0

상자에서 꺼내 자마자 매력을 발휘했습니다. 감사!. – Jayleaf

0

System.Convert.To ... 체크 아웃이 http://msdn.microsoft.com/en-us/library/sf1aw27b.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2

Dim values() As String = { "One", "1.34e28", "-26.87", "-18", "-6.00", _ 
          " 0", "137", "1601.9", Int32.MaxValue.ToString() } 
Dim result As Integer 

For Each value As String In values 
    Try 
     result = Convert.ToInt32(value) 
     Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.", _ 
         value.GetType().Name, value, result.GetType().Name, result) 
    Catch e As OverflowException 
     Console.WriteLine("{0} is outside the range of the Int32 type.", value) 
    Catch e As FormatException 
     Console.WriteLine("The {0} value '{1}' is not in a recognizable format.", _ 
         value.GetType().Name, value) 
    End Try  
Next         
' The example displays the following output: 
' The String value 'One' is not in a recognizable format. 
' The String value '1.34e28' is not in a recognizable format. 
' The String value '-26.87' is not in a recognizable format. 
' Converted the String value '-18' to the Int32 value -18. 
' The String value '-6.00' is not in a recognizable format. 
' Converted the String value ' 0' to the Int32 value 0. 
' Converted the String value '137' to the Int32 value 137. 
' The String value '1601.9' is not in a recognizable format. 
' Converted the String value '2147483647' to the Int32 value 2147483647. 
관련 문제