stringvergleich

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von sarasa.

    stringvergleich

    hallo ich hab 2 strings die ich vergleichen möchte

    VB.NET-Quellcode

    1. txtDisplay.AppendText(t)
    2. Dim reboot As String = "[]reboot now"

    habe eine if abfrage versucht zu machen

    VB.NET-Quellcode

    1. if t = reboot then


    aber die funktioniert nicht
    ok ich habe gedacht mit meiner abfrage stimmt was nicht.

    da liegt es wohl am programm....

    hab ein socket chat und wollte vom client an den server z.b reboot senden.
    dort ist eine abfrage :

    eingehender text = reboot then ....

    aber geht nicht :( woran kann es liegen? oder bei welchem ereigniss muss ich die if abfrage machen?

    VB.NET-Quellcode

    1. Private mobjClient As TcpClient
    2. Private marData(1024) As Byte
    3. Private mobjText As New StringBuilder()
    4. Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
    5. If txtSend.Text = "" Then
    6. MsgBox("KEIN TEXT")
    7. Else
    8. Send("[" & My.Settings.uname & "]" & " " & txtSend.Text)
    9. txtSend.Text = ""
    10. End If
    11. End Sub
    12. Private Sub Send(ByVal t As String)
    13. Dim w As New IO.StreamWriter(mobjClient.GetStream)
    14. w.Write(t & vbCr)
    15. w.Flush()
    16. End Sub
    17. Private Sub DoRead(ByVal ar As IAsyncResult)
    18. Dim intCount As Integer
    19. Try
    20. intCount = mobjClient.GetStream.EndRead(ar)
    21. If intCount < 1 Then
    22. MarkAsDisconnected()
    23. Exit Sub
    24. End If
    25. BuildString(marData, 0, intCount)
    26. mobjClient.GetStream.BeginRead(marData, 0, 1024, AddressOf DoRead, Nothing)
    27. Catch e As Exception
    28. MarkAsDisconnected()
    29. End Try
    30. End Sub
    31. Private Sub BuildString(ByVal Bytes() As Byte, ByVal offset As Integer, ByVal count As Integer)
    32. Dim intIndex As Integer
    33. For intIndex = offset To offset + count - 1
    34. If Bytes(intIndex) = 10 Then
    35. mobjText.Append(vbLf)
    36. Dim params() As Object = {mobjText.ToString}
    37. Me.Invoke(New DisplayInvoker(AddressOf Me.DisplayText), params)
    38. mobjText = New StringBuilder()
    39. Else
    40. mobjText.Append(ChrW(Bytes(intIndex)))
    41. End If
    42. Next
    43. End Sub
    44. Private Sub MarkAsDisconnected()
    45. End Sub
    46. Dim sola As String
    47. Private Sub DisplayText(ByVal t As String)
    48. txtDisplay.AppendText(t)
    49. sola = t
    50. If Me.WindowState = FormWindowState.Minimized Then
    51. NotifyIcon1.ShowBalloonTip(5000)
    52. Timer1.Enabled = True
    53. Timer1.Interval = 2000
    54. Timer1.Start()
    55. End If
    56. End Sub
    57. Private Sub VerbindenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VerbindenToolStripMenuItem.Click
    58. Dim newip As String
    59. Dim Addresslist() As IPAddress = Dns.Resolve("x.dyndns.org").AddressList
    60. Dim IPs As IPAddress
    61. For Each IPs In Addresslist
    62. newip = (IPs.ToString)
    63. Next IPs
    64. mobjClient = New TcpClient(newip, 5000)
    65. DisplayText("Connected to host" & vbCrLf)
    66. mobjClient.GetStream.BeginRead(marData, 0, 1024, AddressOf DoRead, Nothing)
    67. Send(My.Settings.uname & " ist jetzt Online")
    68. If mobjClient.Connected Then
    69. VerbindenToolStripMenuItem.Enabled = False
    70. TrennenToolStripMenuItem.Enabled = True
    71. txtSend.ReadOnly = False
    72. btnSend.Enabled = True
    73. End If
    74. End Sub
    75. Private Sub TrennenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrennenToolStripMenuItem.Click
    76. txtSend.ReadOnly = True
    77. btnSend.Enabled = False
    78. VerbindenToolStripMenuItem.Enabled = True
    79. TrennenToolStripMenuItem.Enabled = False
    80. Send(My.Settings.uname & " ist jetzt Offline")
    81. mobjClient.Close()
    82. End Sub
    83. Private Sub EXITToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EXITToolStripMenuItem.Click
    84. txtSend.ReadOnly = True
    85. btnSend.Enabled = False
    86. VerbindenToolStripMenuItem.Enabled = True
    87. TrennenToolStripMenuItem.Enabled = False
    88. Send(My.Settings.uname & " ist jetzt Offline")
    89. mobjClient.Close()
    90. Me.Close()
    91. End Sub
    92. Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
    93. If Me.WindowState = FormWindowState.Minimized Then
    94. ShowInTaskbar = False
    95. NotifyIcon1.Visible = True
    96. End If
    97. End Sub
    98. Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
    99. Me.WindowState = FormWindowState.Normal
    100. NotifyIcon1.Visible = False
    101. ShowInTaskbar = True
    102. Timer1.Stop()
    103. End Sub
    104. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    105. ToolTip1.SetToolTip(btnSend, "Button zum Senden des Text")
    106. NotifyIcon1.BalloonTipText = "Neue Nachricht"
    107. NotifyIcon1.BalloonTipTitle = " Chat"
    108. ToolTip1.SetToolTip(txtSend, "Hier den Text zum Senden eingeben.")
    109. txtSend.ReadOnly = True
    110. btnSend.Enabled = False
    111. End Sub
    112. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    113. NotifyIcon1.Icon = New System.Drawing.Icon(Application.StartupPath & "\h1.ico")
    114. Thread.Sleep(2000)
    115. NotifyIcon1.Icon = New System.Drawing.Icon(Application.StartupPath & "\h.ico")
    116. Thread.Sleep(2000)
    117. End Sub
    118. Private Sub ExitToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem1.Click
    119. Me.Close()
    120. End Sub
    121. End Class


    Edit by Lupus: Es ist nicht nötig, den ganzen Designercode mit reinzubringen, wenn deine Frage nur was mit dem eigentlichen Code zu tun hat!

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Lupus“ ()