QR-Code Reader

  • VB.NET

Es gibt 10 Antworten in diesem Thema. Der letzte Beitrag () ist von Radinator.

    QR-Code Reader

    Hallo Zusammen,

    ich möchte mich ein wenig mit QR-Codes spielen. Ich erzeuge mit folgendem Code einen QR Code und lasse mir diesen dann in einer TextBox anzeigen:

    VB.NET-Quellcode

    1. Imports KeepDynamic.Barcode.Generator
    2. Imports KeepDynamic.BarcodeReader
    3. Public Class Form2
    4. Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    5. Dim barcode As New QRCode()
    6. ' Set QR-Code barcode value in VB.NET
    7. barcode.CodeText = TextBox1.Text
    8. ' Set QR Code module size
    9. barcode.X = 4
    10. ' Set QR Code quiet zone
    11. barcode.BottomMargin = 16
    12. barcode.LeftMargin = 16
    13. barcode.RightMargin = 16
    14. barcode.TopMargin = 16
    15. 'Set QR Code error correction level
    16. barcode.ECL = QRCodeECL.L
    17.  
    18. ' Set QR-Code drawing image format to PNG in VB.NET
    19. barcode.Format = System.Drawing.Imaging.ImageFormat.Png
    20. ' Generate QR-Code barcode & encode to the png image in VB.NET
    21. barcode.drawBarcode("C:\Test\barcode-qrcode-vbnet.png")
    22. PictureBox1.Image = Image.FromFile("C:\Test\barcode-qrcode-vbnet.png")
    23. End Sub


    Das funktioniert auch prima.

    Nun möchte ich diesen erstellen QR-Code wieder zurück in eine TextBox schreiben. Dies versuche ich mit folgendem Code.

    VB.NET-Quellcode

    1. Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    2. Dim barcodeValues As String() = BarcodeReader.read("C:\Test\barcode-qrcode-vbnet.png", KeepDynamic.BarcodeReader.Type.QRCode)
    3. TextBox2.Text = barcodeValues
    4. End Sub


    Leider erhalte ich jetzt immer folgende Fehlermeldung und barcodeValues ist unterstrichen.
    Der Wert vom Typ "1-dimensionales Array von String" kann nicht in "String" konvertiert werden.

    Kann mir eventuell jemand weiterhelfen
    Is ja auch klar...du liest ja den code (is auch richtig) aber speicherst es in einem Array
    Lösung: mach in Zeile #3 aus Dim Barcode AS String() = einfach Dim Barcode As String = ...
    Klammern weglassen

    Lg Radinator
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
    Und was ist die Meldung?
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
    Wenn du @EaranMaleasis Vorschlag ausgeführt hast und es nix bringt, dann schau dir doch bitte den Rückgabewert der Read-Funktion an und schreib und dann bitte was da zurück gegeben wird

    Edit: Hab mir noch ma auf der Hersteller Seite des durchgelesen...also die Read-Funtion gibt wirklich ein String Array zurück. Das Problem ist nicht, wie ich am Anfang geschrieben habe, das in-Array-speichern sondern das in-die-Textbox-schreiben.

    Denn du liest das Bild ein, die Funktion gibt dir auch den Wert schön in dein Array. Aber in Zeile #5 speicherst du in einer TextBox (wo nur Strings reingehören/reinpassen) ein String-Array

    Zur Lösung des Problems musst du nicht die Klammer in Zeile #3 entfernen sondern mit einer For Each/For-Schleife das String Array durchgehen und die Chars in die TextBox "appenden"

    VB.NET-Quellcode

    1. For Each c As Char in barcodeValues
    2. Textbox1.Text &= c
    3. End For


    Lg Radinator

    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell

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

    Danke für die Hilfe.

    Ehrlich gesagt verstehe ich es noch nicht ganz.
    Ich erzeuge mir z.B. folgendem QR Code: 456.
    Dieser wird auch richtig erstellt.
    Möchte ich diesen Code dann lesen, dann steht auch im Barcodevalue der Code 456.
    Wenn ich jetzt die For Each einfüge, erhalte ich gar kein Ergebnis mehr:

    VB.NET-Quellcode

    1. For Each c As Char in barcodeValues
    2. Textbox1.Text &= c
    3. End For



    Habe es jetzt mal wie folgt gemacht:

    VB.NET-Quellcode

    1. Dim barcodeValues() As String = BarcodeReader.read("C:\Test\barcode-qrcode-vbnet.png", KeepDynamic.BarcodeReader.Type.QRCode)
    2. Dim QRCode As String
    3. Dim Test As String = ""
    4. QRCode = String.Join(Test, barcodeValues)
    5. TextBox2.Text = QRCode


    Damit funktionert es bedingt.
    Ich erzeuge den QR-Code 456
    Dann klicke ich auf den Button laden, dann wird der QR-Code 456 richtig in der TextBox 2 angezeigt.
    Klicke ich erneut auf den Button laden, dann macht er aus dem QR-Code 456 in die TextBox 2 den QR-Code 156.

    Das Verstehe ich nicht.
    [/vbnet]

    Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „toeller“ ()

    Also gut, mach mal einen Haltepunkt bei Zeile #3 und schau dir im Einzelschritt an was in dem Array drinnen steht.
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
    Ok hab mir jetz die Trial geholt. Hab ma ne random nummer mit nem anderen Qr-Code Generator codiert (hier einen RIESEN Danke an @LukiLeu!)

    Also die Read-Funktion gibt ein String-Array zurück, kein Char-Array, wie ich dachte. Im normalfall sollte es reichen wenn du schreibtst

    VB.NET-Quellcode

    1. Textbox2.Text = barcodeValues(0)
    Bilder
    • ausgabe.jpg

      54,63 kB, 677×214, 142 mal angesehen
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell