C#->X# for dummies

This forum is meant for anything you would like to share with other visitors
User avatar
Chris
Posts: 4922
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

C#->X# for dummies

Post by Chris »

Hi Horst,

I searched for the library and found this, is this the one you are using? https://github.com/codebude/QRCoder

Indeed there's no "QrCode.SwissQrCode" class defined in it, that's why the compiler complains. But there's a nested class of class "QRCoder.PayloadGenerator" named "SwissQrCode", so in order to use it, you need the class name "PayloadGenerator.SwissQrCode", instead of just "SwissQrCode".

But even if I change the classnames in your code, I still get a couple different compiler errors, about wrong parameters used, so I suspect there's a mismatch between the sample and the library, the code is probably intended to be used with a different version of the library.

Where did you get the sample and library from?
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3757
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

C#->X# for dummies

Post by wriedmann »

Hi Horst,
please try your code with X#, and then the XIDE code completion will help you find the right names.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Horst
Posts: 337
Joined: Tue Oct 13, 2015 3:27 pm

C#->X# for dummies

Post by Horst »

Hi Chris, hi Wolfgang
ja its that libary.The libary is from Github and the sample from the homepage of the developer. i will look for a better sample.
i tried allready to translate it to X# but i am to stupid. :-) thats why i wanna make a working c# sample and then decomplie.
User avatar
wriedmann
Posts: 3757
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

C#->X# for dummies

Post by wriedmann »

Hi Horst,
where do you are encountering the problems to translate to X#?
I don't see any difficult part:

Code: Select all

using System;
using QRCoder;
function Start() as void 

System.Console.WriteLine("Hello XIDE from c#!")
//Anlegen der Kontaktdaten
local contactGeneral := SwissQrCode.Contact{ "John Doe", "3003", "Bern", "CH", "Parlamentsgebäude", "1"} as SwissQrCode.Contact 
//Anlegen der IBAN
local iban := SwissQrCode.Iban{ "CH2609000000857666015", PayloadGenerator.SwissQrCode.Iban.IbanType.Iban } as SwissQrCode.Iban
//Anlegen der Referenz
local reference := SwissQrCode.Reference{ SwissQrCode.Reference.ReferenceType.QRR, "990005000000000320071012303", SwissQrCode.Reference.ReferenceTextType.QrReference } as SwissQrCode.Reference
//Festlegen der Währung und Summe
local currency := SwissQrCode.Currency.CHF as SwissQrCode.Currency 
local amount = 100.25m as decimal

//Erstellung der Swiss QR Code Payload
local generator = SwissQrCode{ iban, currency, contactGeneral, reference, null, amount, null, null } as SwissQrCode
local payload := generator.ToString() as string 

//QR-Code Generator erzeugen
local qrGenerator := QRCodeGenerator{} as QRCodeGenerator
//Swiss QR Code payload in QR code format bringen
local qrCodeData := qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.M) as QRCodeData 
//Rohdaten-QR-Code erzeugen
local qrCode := QRCode{ qrCodeData } as QRCode
//Swiss-QR-Code-Bild aus Rohdaten erzeugen
local qrCodeImage := qrCode.GetGraphic(20, Color.Black, Color.White, (Bitmap)Bitmap.FromFile(Application.StartupPath + "CH-Kreuz_7mm.png"), 14, 1) as Bitmap 
When you don't understand the C# code, it may be better to not write C# code.
It is better to ask here how to translate it.

Wolfgang

P.S. probably the documentation was right sometimes in the past, but is not correct anymore because the developer has changed the code. ILSpy will help to discover that.
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 4922
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

C#->X# for dummies

Post by Chris »

Horst wrote:Hi Chris, hi Wolfgang
ja its that libary.The libary is from Github and the sample from the homepage of the developer. i will look for a better sample.
i tried allready to translate it to X# but i am to stupid. :-) thats why i wanna make a working c# sample and then decomplie.
You are not stupid, the problem is that the sample is not correct. Or it is meant to be used with a different version of the library. Can you please post a link to where you found the sample, so we can try it as well? And maybe also tell the developer to update the sample code, if it is indeed an old one that does not work anymore.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Horst
Posts: 337
Joined: Tue Oct 13, 2015 3:27 pm

C#->X# for dummies

Post by Horst »

Hi Chris
i found the same sample on github

https://github.com/codebude/QRCoder/wik ... -iso-20022

Are you sure its not a compiler setting thing ??
User avatar
Chris
Posts: 4922
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

C#->X# for dummies

Post by Chris »

I don't think so, I tried it in VS and I get the same errors and problems. I think it's just an old sample, or the library is too new :)

You can go a step further by replacing all occurences of "SwissQrCode." with "QRCoder.PayloadGenerator.SwissQrCode.", but then you will see you will still get errors and warnings about using depreciated parts of the library.

I think it's best to ask the developer if he has an updated sample. But don't tell him you are using XIDE, better tell him you only use VS :). I need to go right now, but later I can also give it a try to adjust the sample as needed.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Horst
Posts: 337
Joined: Tue Oct 13, 2015 3:27 pm

C#->X# for dummies

Post by Horst »

Hi Chris
With your and Wolfgangs help i am close . Just 3 errors and 3 warnings left
:-)
Ah a question for what is the m ? ->100.25m

FUNCTION TestQRCode ()
LOCAL contactGeneral AS PayloadGenerator.SwissQrCode.Contact
LOCAL iban AS PayloadGenerator.SwissQrCode.Iban
LOCAL reference AS PayloadGenerator.SwissQrCode.Reference
LOCAL currency AS PayloadGenerator.SwissQrCode.Currency
LOCAL generator AS PayloadGenerator.SwissQrCode
LOCAL qrGenerator AS QRCodeGenerator
LOCAL qrCodeData AS QRCodeData
LOCAL qrCode AS QRCode
LOCAL qrCodeImage AS Bitmap
LOCAL payload AS STRING
LOCAL amount AS decimal

//Anlegen der Kontaktdaten
contactGeneral := PayloadGenerator.SwissQrCode.Contact{"John Doe", "3003", "Bern", "CH", "Parlamentsgebäude", "1"}
//Anlegen der IBAN
iban := PayloadGenerator.SwissQrCode.Iban {"CH2609000000857666015", PayloadGenerator.SwissQrCode.Iban.IbanType.Iban}
//Anlegen der Referenz
reference := PayloadGenerator.SwissQrCode.Reference{PayloadGenerator.SwissQrCode.Reference.ReferenceType.QRR, "990005000000000320071012303", PayloadGenerator.SwissQrCode.Reference.ReferenceTextType.QrReference}
//Festlegen der Währung und Summe
currency := PayloadGenerator.SwissQrCode.Currency.CHF
// decimal amount = 100.25m
amount := 100.25m

//Erstellung der Swiss QR Code Payload
generator := PayloadGenerator.SwissQrCode {iban, currency, contactGeneral, reference, NULL, amount, NULL, NULL}
payload := generator:ToString()

//QR-Code Generator erzeugen
qrGenerator := QRCodeGenerator {}
//Swiss QR Code payload in QR code format bringen
qrCodeData := qrGenerator:CreateQrCode(payload, QRCodeGenerator.ECCLevel.M)
//Rohdaten-QR-Code erzeugen
qrCode := QRCode {qrCodeData}
//Swiss-QR-Code-Bild aus Rohdaten erzeugen
//qrCodeImage := qrCode:GetGraphic(20, Color.Black, Color.White, (Bitmap)Bitmap.FromFile(WorkDir() + "CH-Kreuz_7mm.png"), 14, 1)

RETURN NIL
User avatar
wriedmann
Posts: 3757
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

C#->X# for dummies

Post by wriedmann »

Hi Horst,
"m" is a postfix for numeric literals - it defines the value is a decimal datatype.
Please see https://docs.xsharp.it/doku.php?id=literals
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Horst
Posts: 337
Joined: Tue Oct 13, 2015 3:27 pm

C#->X# for dummies

Post by Horst »

Hi Wolfgang

So when i make:
local Amount as decimal
i dont need this m at the end ?

Gruss
Horst
Post Reply