Speichern und wieder einlesen ohne...

  • VB.NET

Es gibt 6 Antworten in diesem Thema. Der letzte Beitrag () ist von Lupus.

    Speichern und wieder einlesen ohne...

    Hallo,
    hab da mal ne Frage bezüglich speichern und einlesen.
    Hab ein kleines Game gemacht, und ich müsste hier mehrere Textboxen speichern können. Natürlich sollte das auch wieder eingelesen werden können! Könnte mir hier irgendwie einen Code geben?
    Es sollte unbendingt in einer TXT Datei gespeichert werden, aber automatisch gespeichert werden, da ich nicht will, dass man weis wo es hinspeichert!
    Gibt es eine sicherere Methode etwas zu speichern? Denn ich glaub wenn es in einer TXT Datei ist kann man es öffnen und die Zahlen umbennenen.

    Aber so ein Code zum Speichern und einlesen wäre echt klasse.... Habe VB.Net

    glg samy
    Code zum Speichern und wieder Einlesen gibt es zuhauf im Internet, such mal danach. Dass die Werte geändert werden können, kannst du verhindern, indem du die Daten wie folgend speicherst:
    [Quelle];[Wert]
    Also z.B.:
    TextBox1;Gewonnen,verloren,wasAuchImmer

    Danach kannst du die Daten noch verschlüsseln, eine einfach Methode wäre z.B. Rot13 (nicht sehr sicher, muss es ja aber auch nicht sein, AES o.ä. wird eher Overkill sein). Beim Einlesen arbeitest du dann mit String.Split(Zeile, ";") und hast so die Quelle und den Wert in einem Array. Danach gehst du mit Select Case durch alle TextBoxen die du hast und weist den wert zu.
    Wie wär's mit einem anderen Dateiformat. z.B. .MrSamy-Datei?
    Du kannst das dann noch verschlüsseln:

    VB.NET-Quellcode

    1. Dim Inhalt As String = TextBox1.Text
    2. Inhalt = Inhalt2.Replace(" ", "*")
    3. Inhalt = Inhalt2.Replace("A", "| ")
    4. Inhalt = Inhalt2.Replace("B", "|| ")
    5. Inhalt = Inhalt2.Replace("C", "||\\ ")
    6. Inhalt = Inhalt2.Replace("D", "||\|")
    7. Inhalt = Inhalt2.Replace("E", "||\/")
    8. Inhalt = Inhalt2.Replace("F", "|\\ ")
    9. Inhalt = Inhalt2.Replace("G", "|\|")
    10. Inhalt = Inhalt2.Replace("H", "|\/")
    11. Inhalt = Inhalt2.Replace("I", "I")
    12. Inhalt = Inhalt2.Replace("J", "J")
    13. Inhalt = Inhalt2.Replace("K", "K")
    14. Inhalt = Inhalt2.Replace("L", "L")
    15. Inhalt = Inhalt2.Replace("M", "M")
    16. Inhalt = Inhalt2.Replace("N", "N")
    17. Inhalt = Inhalt2.Replace("O", "O")
    18. Inhalt = Inhalt2.Replace("P", "P")
    19. Inhalt = Inhalt2.Replace("Q", "Q")
    20. Inhalt = Inhalt2.Replace("R", "R")
    21. Inhalt = Inhalt2.Replace("S", "S")
    22. Inhalt = Inhalt2.Replace("T", "T")
    23. Inhalt = Inhalt2.Replace("U", "U")
    24. Inhalt = Inhalt2.Replace("V", "V")
    25. Inhalt = Inhalt2.Replace("W", "W")
    26. Inhalt = Inhalt2.Replace("X", "X")
    27. Inhalt = Inhalt2.Replace("Y", "Y")
    28. Inhalt = Inhalt2.Replace("Z", "Z")
    29. Inhalt = Inhalt2.Replace(".", "+")
    30. Inhalt = Inhalt2.Replace(vbCrLf, "$")
    31. Dim wasweissich As New IO.StreamWriter("deinname.mrsamy")
    32. wasweissich.WriteLine(Inhalt)
    33. wasweissich.Close()


    Und dann auslesen und entschlüsseln:

    VB.NET-Quellcode

    1. Dim Inhalt2 As String
    2. Using keineahnung As New StreamReader("deinname.mrsamy")
    3. Inhalt2 = keineahnung.ReadLine
    4. keineahnung.Close()
    5. End Using
    6. Inhalt = Inhalt.Replace("| ", "A")
    7. Inhalt2 = Inhalt.Replace("|| ", "B")
    8. Inhalt2 = Inhalt.Replace("||\\ ", "C")
    9. Inhalt2 = Inhalt.Replace("||\|", "D")
    10. Inhalt2 = Inhalt.Replace("||\/", "E")
    11. Inhalt2 = Inhalt.Replace("|\\ ", "F")
    12. Inhalt2 = Inhalt.Replace("|\|", "G")
    13. Inhalt2 = Inhalt.Replace("|\/", "H")
    14. Inhalt2 = Inhalt.Replace("I", "I")
    15. Inhalt2 = Inhalt.Replace("j", "J")
    16. Inhalt2 = Inhalt.Replace("k", "K")
    17. Inhalt2 = Inhalt.Replace("l", "L")
    18. Inhalt2 = Inhalt.Replace("m", "M")
    19. Inhalt2 = Inhalt.Replace("n", "N")
    20. Inhalt2 = Inhalt.Replace("o", "O")
    21. Inhalt2 = Inhalt.Replace("p", "P")
    22. Inhalt2 = Inhalt.Replace("q", "Q")
    23. Inhalt2 = Inhalt.Replace("r", "R")
    24. Inhalt2 = Inhalt.Replace("s", "S")
    25. Inhalt2 = Inhalt.Replace("t", "T")
    26. Inhalt2 = Inhalt.Replace("u", "U")
    27. Inhalt2 = Inhalt.Replace("v", "V")
    28. Inhalt2 = Inhalt.Replace("w", "W")
    29. Inhalt2 = Inhalt.Replace("x", "X")
    30. Inhalt2 = Inhalt.Replace("y", "Y")
    31. Inhalt2 = Inhalt.Replace("z", "Z")
    32. Inhalt2 = Inhalt.Replace(" ", "")
    33. Inhalt2 = Inhalt.Replace("+", ".")
    34. Inhalt2 = Inhalt.Replace("*", " ")
    35. Inhalt2 = Inhalt.Replace("$", vbCrLf)
    36. TextBox1.Text = Inhalt2


    So ungefähr geht es. Die Zeichen muss du dann natürlich entsprechend auf dein Spiel ändern.

    Gruß
    Olicrash

    EDIT: Da ist mir wohl einer zuvorgekommen :)

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „olicrash“ ()

    danke danke! also dieses board ist ja echt der hammer!
    so schnell wie hier geantwortet wird, wird das nirgends!

    letzte frage:
    wenn ich nun zb 3 textboxen habe, brauche ich nur
    Dim Inhalt As String = TextBox1.Text
    Dim Inhalt As String = TextBox2.Text
    Dim Inhalt As String = TextBox3.Text
    oben hinzufügen oder?

    glg
    nein. denn dann ist am ende nur noch textbox3.text drin.
    wie wäre eine schleife:


    Verschlüsseln:

    VB.NET-Quellcode

    1. Public Sub Verschlüsseln()
    2. Dim Inhalt(2) As String
    3. Inhalt(0) = TextBox1.Text
    4. Inhalt(1) = TextBox2.Text
    5. Inhalt(2) = TextBox3.Text
    6. Dim 1 As Interger = 0
    7. For i = 0 To i = 2
    8. Inhalt(i) = Inhalt(i).Replace(" ", "*") 'das (i) bitte überall!
    9. Inhalt = Inhalt(i).Replace("A", "| ")
    10. Inhalt = Inhalt2.Replace("B", "|| ")
    11. Inhalt = Inhalt2.Replace("C", "||\\ ")
    12. Inhalt = Inhalt2.Replace("D", "||\|")
    13. Inhalt = Inhalt2.Replace("E", "||\/")
    14. Inhalt = Inhalt2.Replace("F", "|\\ ")
    15. Inhalt = Inhalt2.Replace("G", "|\|")
    16. Inhalt = Inhalt2.Replace("H", "|\/")
    17. Inhalt = Inhalt2.Replace("I", "I")
    18. Inhalt = Inhalt2.Replace("J", "J")
    19. Inhalt = Inhalt2.Replace("K", "K")
    20. Inhalt = Inhalt2.Replace("L", "L")
    21. Inhalt = Inhalt2.Replace("M", "M")
    22. Inhalt = Inhalt2.Replace("N", "N")
    23. Inhalt = Inhalt2.Replace("O", "O")
    24. Inhalt = Inhalt2.Replace("P", "P")
    25. Inhalt = Inhalt2.Replace("Q", "Q")
    26. Inhalt = Inhalt2.Replace("R", "R")
    27. Inhalt = Inhalt2.Replace("S", "S")
    28. Inhalt = Inhalt2.Replace("T", "T")
    29. Inhalt = Inhalt2.Replace("U", "U")
    30. Inhalt = Inhalt2.Replace("V", "V")
    31. Inhalt = Inhalt2.Replace("W", "W")
    32. Inhalt = Inhalt2.Replace("X", "X")
    33. Inhalt = Inhalt2.Replace("Y", "Y")
    34. Inhalt = Inhalt2.Replace("Z", "Z")
    35. Inhalt = Inhalt2.Replace(".", "+")
    36. Inhalt = Inhalt2.Replace(vbCrLf, "$")
    37. Dim wasweissich As New IO.StreamWriter("deinname" & i & ".mrsamy")
    38. wasweissich.WriteLine(Inhalt(i))
    39. wasweissich.Close()
    40. Next i
    41. End Sub


    Das Entschlüsseln:

    VB.NET-Quellcode

    1. Public Sub Entschlüsseln()
    2. Dim Inhalt(2) As String
    3. Dim 1 As Interger = 0
    4. For i = 0 To i = 2
    5. Using keineahnung As New StreamReader("deinname" & i & ".mrsamy")
    6. Inhalt(i) = keineahnung.ReadLine
    7. keineahnung.Close()
    8. End Using
    9. Inhalt(i) = Inhalt(i).Replace("| ", "A") 'das (i) bitte wieder überall setzen
    10. Inhalt2 = Inhalt.Replace("|| ", "B")
    11. Inhalt2 = Inhalt.Replace("||\\ ", "C")
    12. Inhalt2 = Inhalt.Replace("||\|", "D")
    13. Inhalt2 = Inhalt.Replace("||\/", "E")
    14. Inhalt2 = Inhalt.Replace("|\\ ", "F")
    15. Inhalt2 = Inhalt.Replace("|\|", "G")
    16. Inhalt2 = Inhalt.Replace("|\/", "H")
    17. Inhalt2 = Inhalt.Replace("I", "I")
    18. Inhalt2 = Inhalt.Replace("j", "J")
    19. Inhalt2 = Inhalt.Replace("k", "K")
    20. Inhalt2 = Inhalt.Replace("l", "L")
    21. Inhalt2 = Inhalt.Replace("m", "M")
    22. Inhalt2 = Inhalt.Replace("n", "N")
    23. Inhalt2 = Inhalt.Replace("o", "O")
    24. Inhalt2 = Inhalt.Replace("p", "P")
    25. Inhalt2 = Inhalt.Replace("q", "Q")
    26. Inhalt2 = Inhalt.Replace("r", "R")
    27. Inhalt2 = Inhalt.Replace("s", "S")
    28. Inhalt2 = Inhalt.Replace("t", "T")
    29. Inhalt2 = Inhalt.Replace("u", "U")
    30. Inhalt2 = Inhalt.Replace("v", "V")
    31. Inhalt2 = Inhalt.Replace("w", "W")
    32. Inhalt2 = Inhalt.Replace("x", "X")
    33. Inhalt2 = Inhalt.Replace("y", "Y")
    34. Inhalt2 = Inhalt.Replace("z", "Z")
    35. Inhalt2 = Inhalt.Replace(" ", "")
    36. Inhalt2 = Inhalt.Replace("+", ".")
    37. Inhalt2 = Inhalt.Replace("*", " ")
    38. Inhalt2 = Inhalt.Replace("$", vbCrLf)
    39. Next i
    40. TextBox1.Text = Inhalt(0)
    41. TextBox2.Text = Inhalt(1)
    42. TextBox3.Text = Inhalt(2)
    43. End Sub


    Wenn du es dann Verschlüsseln willst, schreibst du: "Verschlüsseln()" in deinen Code; zum entschlüsseln schreibst du "Entschlüsseln()" in deinen Code.

    Gerade geschrieben, bitte testen!

    Mit freundlichen Grüßen
    Olicrash

    Dieser Beitrag wurde bereits 5 mal editiert, zuletzt von „olicrash“ ()

    in dem code is zeile 6 & 7 nen bisschen falsch (er hat versehentlich 1 statt i deklariert, un in der schleife auch nen kleinen denkfehler drin), ersetz sie am besten durch die Zeile:

    VB.NET-Quellcode

    1. For i as integer = 0 To 2