cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
langsem
Post Patron
Post Patron

Check if string its empty

Hello I have a barcode scanner that scans a qr code. Then it extracts some values. 

I then have a label that holds the value. I want to make a function that says "If the field its empty assign variable1 if the fields its not empty do First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value)

How can i perform this ? I tried with If(IsBlank(Label2.Text);"variable1";First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value)

 

But it gives error

2 ACCEPTED SOLUTIONS

Accepted Solutions
v-xiaochen-msft
Community Support
Community Support

Hi @langsem ,

 

Thank you for your information.

 

I assume:

  1. After splitting, the FORSIKRING column has a value. The value does not contain spaces.
  2. After splitting, the FORSIKRING column has no displayable value, the value is composed of spaces.

 

You could try the following code:

If(" " in First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value),"variable 1",First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value))

 

Best Regards,

Wearsky

View solution in original post

v-xiaochen-msft
Community Support
Community Support

Hi @langsem ,

 

You could try this code:

If(IsBlank(Trim(First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value))),"variable 1",First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value))

// Trim function can delete all spaces in a text string, except for a single space between words.

 

Best Regards,

Wearsky

View solution in original post

12 REPLIES 12

@langsem 


@langsem wrote:

 I want to make a function that says "If the field its empty assign variable1 if the fields its not empty do First(Match(BarcodeScanner1.Value;"FORSIKRING:



To do this you must already have the variable set OnVisible or somewhere at the beginning first

 

OnVisible Screen1

 

Set(_Variable01;"")

 

 

Where are you using the longer formula (on which property, and on what kind of thing is it on)?

 

For the longer formula, you can try something like this

 

If(IsBlank(Label2.Text);Set(_Variable01;"somethingGoesHere");false)

 

For the part that says false above, you would try your longer sub formula here

 

First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value)

 

but before you try that longer one - if the longer one gives an error, put something easier there so you can test it. If false also gives an error, try an empty string, or some other mock value that matches the context of where you are using this whole formula.

 

Check if something like the above helps.

 

 

Hm dident get a error, but also it dident work. Its still just shows blank

v-xiaochen-msft
Community Support
Community Support

Hi @langsem ,

 

Could you tell me:

  1. When BarcodeScanner1.Value is empty, do you want the value of label2 to be a string text variable 1?
  2. When BarcodeScanner1.Value is not empty, do you want the value of label2 to be First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value)?

 

I assume:

  1. When BarcodeScanner1.Value is empty, you want the value of label2 to be a string text variable 1.
  2. When BarcodeScanner1.Value is not empty, you want the value of label2 to be First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value).

 

I've made a test for your reference:

1\ Set label2s Text property to:

If(IsBlank(BarcodeScanner1.Value),"variable 1", First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value))

 

Best Regards,

Wearsky

almost. The BarcodeScanner1.Value contains alot of text so the code 

First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value).

 Splits that value and place it into labels. 

So I need to check if Label2 contains text after the barcode scan has been made. If the code above dont have a value i want to fill the Label2 with some text. I cant check if the Barcodescanner1.value has a value because it will always have some form of value, have to check after it splits the value of the Barcodescanner1.value 

v-xiaochen-msft
Community Support
Community Support

Hi @langsem ,

 

According to your description, I modified the formula.

You could try the following code:

If(IsBlank(First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value)),"variable 1",First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value))

 

Firstly, split BarcodeScanner1.Value .

Secondly, determine whether the required part is empty.

If it is empty, label2 displays "variable 1".

If it is not empty, label2 displays the value of the required part.

 

Best Regards,

Wearsky 

I think we are close, is it possible to check if it contains whitespace? Because i am still getting a blank field, so I assume the value its whitespace or something ? 

v-xiaochen-msft
Community Support
Community Support

Hi @langsem ,

 

According to your description, I think the formula executes First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value).

 

Could you tell me:

What is the value of BarcodeScanner1.Value?

And What is the value returned by First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value) ?

 

Best Regards,

Wearsky

the barcodescanner value its 
a dynamic value 

but in general it is 
SO:00005554
REG:EB23335
FORSIKRING:TRYG
JOBB:4
LAGERSTED:80

So the code  First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value) splits the total value and retrieves TRYG, BUT sometimes the fields its blank. So in a case that i have now its returning just whitespaces

v-xiaochen-msft
Community Support
Community Support

Hi @langsem ,

 

Thank you for your information.

 

I assume:

  1. After splitting, the FORSIKRING column has a value. The value does not contain spaces.
  2. After splitting, the FORSIKRING column has no displayable value, the value is composed of spaces.

 

You could try the following code:

If(" " in First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value),"variable 1",First(Match(BarcodeScanner1.Value;"FORSIKRING:(.+)";Contains).SubMatches).Value))

 

Best Regards,

Wearsky

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (2,688)