cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper IV
Helper IV

separate the contents of a QR code and display it in labels

The QR code I have has 5 texts (Name, Department, position, Area, Email) I need to show separately in labels for example item1QR (Name) in label1 item2QR (Department) in label2 What code should I have on the labels?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Resident Rockstar
Resident Rockstar

Re: separate the contents of a QR code and display it in labels

@King 

Cool. So when a user scans that QR code, they'll get this back:

 

Eric Lott-email@test.comcargoTest/departmentTest

 

Where:

  • "Eric Lott" is  User().FullName
  • email@test.com is User().Email
  • cargoTest is Datos.cargo
  • departmentTest is Datos.departamento

Good stuff! Using Google APIs gives us a lot of flexibility.

 

Let's change your formula up a bit. Let's make your QR code content equal to this:

 

Substitute("https://chart.googleapis.com/chart?cht=qr&chs=450x450&chl="
& "Name:" & User().FullName & "Name:"
& "Email:" & User().Email & "Email:"
& "Cargo:" & Datos.cargo & "Cargo:"
& "Department:" & Datos.departamento & "Department:",
" ", "%20")

 

 

(we substitute %20 in case your strings have spaces)

Notice that the variable we will collect later are put between a beginning and ending tag equal to the name of the variable plus a colon. This is how we will extract them later.

This gives us this example response when the barcode is scanned from the BarcodeScanner1.Value property:

 

Name:Eric LottName:Email:test@email.comEmail:Cargo:cargoTestCargo:Department:department TestDepartment:

 

Let's SET() this as a variable for later use:

 

Set(CodeContents,BarcodeScanner1.Value)

 

Now we need to extract the data back from the QR code. To do that we'll use Match(). Match allows us to search the QR code value for patterns. Since we had the flexibility to add our own patterns with the tags, this will be very easy. In the below example, (.+) is a regex pattern that just looks for any amount of characters. So "Name:(.+)Name:" will look for our tags and everything between them.

Here's the example for getting the Name value:

 

Match(CodeContents,"Name:(.+)Name:",MatchOptions.Contains).FullMatch

 

This formula, if it were in a textbox, would display "Name:Eric LottName:". To get rid of the beginning and ending tags, we can use Substitute().

 

Substitute(Match(CodeContents,"Name:(.+)Name:",MatchOptions.Contains).FullMatch,"Name:","")

 

Now we can do this for the rest for the variables!

 

Substitute(Match(CodeContents,"Name:(.+)Name:",MatchOptions.Contains).FullMatch,"Name:","")
Substitute(Match(CodeContents,"Email:(.+)Email:",MatchOptions.Contains).FullMatch,"Email:","")
Substitute(Match(CodeContents,"Cargo:(.+)Cargo:",MatchOptions.Contains).FullMatch,"Cargo:","")
Substitute(Match(CodeContents,"Department:(.+)Department:",MatchOptions.Contains).FullMatch,"Department:","")

 

Notice we only have to change the references to which tag we want to look for and substitute.

 

An alternative formula that requires a little less maintenance is this, which doesn't require the Substitute() function. It's a little less intuitive, but it's basically returning the (.+) values, which automatically removes the tags. I went with the Substitute() formula in the above example because it's easier to follow along with, but feel free to swap to this:

First(Match(CodeContents,"Name:(.+)Name:",MatchOptions.Contains).SubMatches).Value

 

To experiment with regex, check this site out. https://regex101.com/

 

---
If this answered your question, please click "Accept Solution". If this helped, please Thumbs Up.

View solution in original post

6 REPLIES 6
Highlighted
Resident Rockstar
Resident Rockstar

Re: separate the contents of a QR code and display it in labels

Step 1) Get the QR code contents. Use a formula to store the contents of a QR code on the OnScan property of your barcode scanner.

 

Set(CodeContents,BarcodeScanner1.Value)

 

Step 2) Evaluate the QR code contents. For this step, it may be helpful for you to post a sample QR cod payload (the contents returned when a code is scanned. Here's a sample I will use:

 

BEGIN:VCARD VERSION:3.0 N:Lott;Eric EMAIL:test@email.com END:VCARD

 

Step 3) Split the QR code contents into variables. Hopefully the below example isn't too much info all at once. I first use the Match() function to match a pattern in the text with a regular expression (regex) pattern that correlates with what I'm trying to extract. The ExtractedName variable I'm setting is looking for the regex pattern "N:\w+;\w+" which means it's looking for the letter 'N' followed by a colon ':' followed by a word, a semicolon, and then another word. This matches the name pattern of our QR code content ("N:Lott;Eric"). I then extract the first name and last name from the ExtractedName variable by splitting the string at the semicolon and grabbing the first and last names. The same basic concept was done for the email.

 

Set(ExtractedName,Match(CodeContents,"N:\w+;\w+",MatchOptions.Contains).FullMatch);
Set(ExtractedFirstName,Last(Split(Right(ExtractedName,Len(ExtractedName)-2),";").Result).Result);
Set(ExtractedLastName,First(Split(Right(ExtractedName,Len(ExtractedName)-2),";").Result).Result);
Set(ExtractedEmail,Match(CodeContents,"\w+@\w+.\w+",MatchOptions.Contains).FullMatch);

 

From there, you have everything in variable that can be placed in labels or text boxes.

AGAIN, please don't let that intimidate you. I can help with anything that doesn't make sense. If you can, please share a sample QR code and we can go from there.

---
If this answered your question, please click "Accept Solution". If this helped, please Thumbs Up.

Highlighted
Helper IV
Helper IV

Re: separate the contents of a QR code and display it in labels

Hi @EricLott  

 

Thanks for answering I will show you the content of my code                                                                                                                  I understand what you tell me when saving the content in the variable and that you will search for each of these elements and keep them in a variable where I am confused about how it is that you are looking for the elements

 

Untitled.png

Highlighted
Resident Rockstar
Resident Rockstar

Re: separate the contents of a QR code and display it in labels

@King 

Cool. So when a user scans that QR code, they'll get this back:

 

Eric Lott-email@test.comcargoTest/departmentTest

 

Where:

  • "Eric Lott" is  User().FullName
  • email@test.com is User().Email
  • cargoTest is Datos.cargo
  • departmentTest is Datos.departamento

Good stuff! Using Google APIs gives us a lot of flexibility.

 

Let's change your formula up a bit. Let's make your QR code content equal to this:

 

Substitute("https://chart.googleapis.com/chart?cht=qr&chs=450x450&chl="
& "Name:" & User().FullName & "Name:"
& "Email:" & User().Email & "Email:"
& "Cargo:" & Datos.cargo & "Cargo:"
& "Department:" & Datos.departamento & "Department:",
" ", "%20")

 

 

(we substitute %20 in case your strings have spaces)

Notice that the variable we will collect later are put between a beginning and ending tag equal to the name of the variable plus a colon. This is how we will extract them later.

This gives us this example response when the barcode is scanned from the BarcodeScanner1.Value property:

 

Name:Eric LottName:Email:test@email.comEmail:Cargo:cargoTestCargo:Department:department TestDepartment:

 

Let's SET() this as a variable for later use:

 

Set(CodeContents,BarcodeScanner1.Value)

 

Now we need to extract the data back from the QR code. To do that we'll use Match(). Match allows us to search the QR code value for patterns. Since we had the flexibility to add our own patterns with the tags, this will be very easy. In the below example, (.+) is a regex pattern that just looks for any amount of characters. So "Name:(.+)Name:" will look for our tags and everything between them.

Here's the example for getting the Name value:

 

Match(CodeContents,"Name:(.+)Name:",MatchOptions.Contains).FullMatch

 

This formula, if it were in a textbox, would display "Name:Eric LottName:". To get rid of the beginning and ending tags, we can use Substitute().

 

Substitute(Match(CodeContents,"Name:(.+)Name:",MatchOptions.Contains).FullMatch,"Name:","")

 

Now we can do this for the rest for the variables!

 

Substitute(Match(CodeContents,"Name:(.+)Name:",MatchOptions.Contains).FullMatch,"Name:","")
Substitute(Match(CodeContents,"Email:(.+)Email:",MatchOptions.Contains).FullMatch,"Email:","")
Substitute(Match(CodeContents,"Cargo:(.+)Cargo:",MatchOptions.Contains).FullMatch,"Cargo:","")
Substitute(Match(CodeContents,"Department:(.+)Department:",MatchOptions.Contains).FullMatch,"Department:","")

 

Notice we only have to change the references to which tag we want to look for and substitute.

 

An alternative formula that requires a little less maintenance is this, which doesn't require the Substitute() function. It's a little less intuitive, but it's basically returning the (.+) values, which automatically removes the tags. I went with the Substitute() formula in the above example because it's easier to follow along with, but feel free to swap to this:

First(Match(CodeContents,"Name:(.+)Name:",MatchOptions.Contains).SubMatches).Value

 

To experiment with regex, check this site out. https://regex101.com/

 

---
If this answered your question, please click "Accept Solution". If this helped, please Thumbs Up.

View solution in original post

Highlighted
Helper IV
Helper IV

Re: separate the contents of a QR code and display it in labels

Hi @EricLott 

thank you very much I learned how to use "Match" to find and "Substitute" to change a letter or character this has worked 100% I thank you

Highlighted
Resident Rockstar
Resident Rockstar

Re: separate the contents of a QR code and display it in labels

Good deal! I didn't know about the Google APIs URL to build out a QR code. That's good to know.

Highlighted
New Member

Re: separate the contents of a QR code and display it in labels

Worked! Excellent example

Helpful resources

Announcements
Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (6,051)