Input Box String

  • VB.NET

Es gibt 11 Antworten in diesem Thema. Der letzte Beitrag () ist von jvbsl.

    Input Box String

    Hallo VB Forum

    Ich habe eine Input Box gemacht in der gesagt wird Bitte geben sie ein Neues Passwort an.

    der code:

    VB.NET-Quellcode

    1. InputBox("Bitte geben sie ein Neues Passwort an", "Neues Passwort")



    So wenn ich jetzt dort "12345" eingebe und dann auf Ok drücke soll er das an die mysql schicken wie lese ich diesen String aus also ihm sage er soll diese 12345 auslesen.
    jvbsl hat irgendwie recht. 1-2 Zeilen waren es dann doch nicht... ;)

    Rudimentäre Inputbox:
    Kochrezept (wie oben schon erwähnt:) )
    1 neue Form
    1 Label
    1 Textbox
    2 Buttons (btOK und btAbbrechen)

    und a bisserl Inhalt:
    inhalt

    VB.NET-Quellcode

    1. Public Class ext_inputbox
    2. Sub New(ByVal prompt As String, ByVal title As String, ByVal defaultresponse As String,
    3. Optional ByVal usePasswordChar As Boolean = False)
    4. InitializeComponent()
    5. If usePasswordChar Then
    6. TextBox1.PasswordChar = PasswordChar
    7. End If
    8. Me.CancelButton = btAbbrechen 'Wird ausgelöst, wenn ESC gedrückt wird
    9. Me.AcceptButton = btOK 'wird bei OK ausgelöst
    10. Label1.Text = prompt
    11. TextBox1.Text = defaultresponse
    12. Me.Text = title
    13. Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedDialog
    14. Me.ShowDialog()
    15. End Sub
    16. Private _title As String
    17. Public Property Title() As String
    18. Get
    19. Return _title
    20. End Get
    21. Set(ByVal value As String)
    22. _title = value
    23. End Set
    24. End Property
    25. Private _prompt As String
    26. Public Property Prompt() As String
    27. Get
    28. Return _prompt
    29. End Get
    30. Set(ByVal value As String)
    31. _prompt = value
    32. End Set
    33. End Property
    34. Private _usepasswordchar As Boolean
    35. Public Property UsePassWordChar() As Boolean
    36. Get
    37. Return _usepasswordchar
    38. End Get
    39. Set(ByVal value As Boolean)
    40. _usepasswordchar = value
    41. End Set
    42. End Property
    43. Private _passwordChar As Char = "*"c
    44. Public Property PasswordChar() As Char
    45. Get
    46. Return _passwordChar
    47. End Get
    48. Set(ByVal value As Char)
    49. _passwordChar = value
    50. End Set
    51. End Property
    52. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btOK.Click
    53. Me.DialogResult = DialogResult.OK
    54. Prompt = TextBox1.Text
    55. Me.Close()
    56. End Sub
    57. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btAbbrechen.Click
    58. Me.DialogResult = DialogResult.Cancel
    59. Prompt = ""
    60. Me.Close()
    61. End Sub
    62. End Class



    Anwendung:

    VB.NET-Quellcode

    1. Dim box As New ext_inputbox("is es so schwer?", "Inputbox ohne viel Aufwand", "Vorgabetext")
    2. box.ShowDialog()
    3. If box.DialogResult = DialogResult.OK Then '...
    4. 'whatever
    5. End If
    6. Dim mpassword As New ext_inputbox("Passworteingabe", "Passwort", "", True)
    7. mpassword.ShowDialog()
    Bilder
    • Unbenannt.JPG

      21,88 kB, 580×238, 314 mal angesehen
    ich hätte das so gemacht:

    VB.NET-Quellcode

    1. Enum eResult
    2. Right
    3. Wrong
    4. Cancel
    5. End Enum
    6. Public Overloads Function ShowDialog(Text As String,Titel As String,DefaultValue As String,Passwort As String)As eResult
    7. lblÜberschrift.Text = Text
    8. Me.Text = Titel
    9. Me.txtPasswort.Text = DefaultValue
    10. Dim res As DialogResult = MyBase.ShowDialog
    11. If res = DialogResult.Cancel Then
    12. Return eResult.Cancel
    13. Else
    14. If MD5(txtPasswort.Text) = Passwort Then
    15. Return eResult.Right
    16. Else
    17. Return eResult.Wrong
    18. End If
    19. End If
    20. End Function
    21. 'TODO: MD5 Hash Funktion

    ist zwar noch länger, aber ich finde den Aufruf dafür recht schön^^
    Ich wollte auch mal ne total überflüssige Signatur:
    ---Leer---