現在我正在構建一種腳本語言(EngineScript)。目前您只能輸入一個命令/功能(IE:sout "Hello world"
),但我想擴展它。如何在VB.Net中換行後得到文本框的字符
所以我想知道你們是否知道任何代碼,以便在VB2012.Net中將換行後的字符輸入到單獨的變量中。感謝:-)
這裏是我的代碼:
Public Class Form1
Dim strvar0 As String
Dim strvar1 As String
Dim strvar2 As String
Dim strvar3 As String
Dim numvar As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim first4Chars As String = TextBox1.Text.Substring(0, 4)
Dim restOfChars As String = TextBox1.Text.ToString.Substring(5)
Select Case first4Chars
Case "sout"
Select Case restOfChars
Case "box:str0"
TextBox2.Text = strvar0 & vbCrLf & vbCrLf & vbCrLf & vbCrLf & "COMMAND //sout\\ has been successfully used"
Case Else
TextBox2.Text = restOfChars & vbCrLf & vbCrLf & vbCrLf & vbCrLf & "COMMAND //sout\\ has been successfully used"
End Select
Case "str0"
strvar0 = restOfChars
Case Else
TextBox2.Text = "Error".ToString
End Select
End Sub
Private Sub HelpToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles HelpToolStripMenuItem.Click
Dim a As New Help
End Sub
Private Sub RunToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RunToolStripMenuItem.Click
Button1.PerformClick()
End Sub
End Class
...我做的,這是一個Windows窗體
@Jamby當我用你的代碼:
Public Class Form1
Dim strvar0 As String
Dim strvar1 As String
Dim strvar2 As String
Dim strvar3 As String
Dim numvar As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For Each Line In TextBox1.Text.Split(vbNewLine)
Dim first4Chars As String = TextBox1.Text.Substring(0, 4)
Dim restOfChars As String = TextBox1.Text.ToString.Substring(5)
Select Case first4Chars
Case "sout"
Select Case restOfChars
Case "box:str0"
TextBox2.Text = strvar0 & vbCrLf & vbCrLf & vbCrLf & vbCrLf & "COMMAND //sout\\ has been successfully used"
Case Else
TextBox2.Text = restOfChars & vbCrLf & vbCrLf & vbCrLf & vbCrLf & "COMMAND //sout\\ has been successfully used"
End Select
Case "str0"
strvar0 = restOfChars
Case "exit"
Me.Close()
Case "lofi"
Select Case restOfChars
Case "box:str0"
Process.Start(strvar0)
Case Else
Process.Start(restOfChars)
End Select
Case "inet"
Process.Start("iexplore.exe" + restOfChars)
Case Else
TextBox2.Text = "Error".ToString
End Select
Next
TextBox1.Clear()
End Sub
Private Sub HelpToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles HelpToolStripMenuItem.Click
Dim a As New Help
End Sub
Private Sub RunToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RunToolStripMenuItem.Click
Button1.PerformClick()
End Sub
Private Sub MenuStrip1_ItemClicked(sender As Object, e As ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked
End Sub
End Class
它不會產生錯誤,但當我輸入
sout Hello
換行符 sout World
以下應該從我的輸出窗口輸出:
Hello
COMMAND //sout\\ has been successfully used
World
COMMAND //sout\\ has been successfully used
但不是這種情況:
Hello
sout World
COMMAND //sout\\ has been successfully used
幫助!
您錯誤地複製了我的代碼。看看first4Chars As String = Line.Substring(0,4) – Jamby 2013-05-08 07:23:39