# Forum FlexPro – Discuss your topic!

## If-Condition with empty variable

Home > Community > FPScript > If-Condition with empty variable

Ansicht von 4 Beiträgen – 1 bis 4 (von insgesamt 4)
• Autor
Beiträge
• #28527
Leon D
Teilnehmer

Hey,

I do have measurements with an Measurment number, but some Measurement number do not exist.

For context, I have the following code. In general it works fine.

``````Dim SourceData = [IC_I_U_RMS, IHV_Sys_ave, MeasNr, Record]
Dim maxIHV, maxIC
Dim Idx, _Event, _Event2, maxMeasNr, Idx2
Dim Maxima, Idexes, baum
Dim startIdx, endIdx
maxMeasNr = Maximum(MeasNr.Y)

For i = 1 To maxMeasNr Do

_Event = ValuesInInterval(MeasNr, i, i, EVENT_INDEX)
_Event2 = ValuesInInterval(Record, 1, 1, EVENT_INDEX)
Idx = IndexAnd(_Event, _Event2)

If Idx = ???  Then
maxIHV :="NaN"
maxIC :="NaN"
Else
startIdx = Minimum(Idx)
endIdx = Maximum(Idx)
maxIHV := Maximum(IHV_Sys_ave[startIdx, endIdx], )
maxIC := Maximum(IC_I_U_RMS[startIdx, endIdx], )
End

Maxima = {maxIHV, maxIC}

End``````

My Problem is, that if “IndexAnd()” has no common indexes, it outputs an empty variable. This happens when the MeasNr doesn`t exist. If the MeasNr doesn`t exist the code is supposed to write down “NaN”. So if the variable Idx is empty the code should write “NaN” and if it isn`t empty it should write an value.

What i can`t figure out is how to write the “if var Idx equals empty then…” = If Idx = ?EMPTY? Then…

How can i solve this? I can`t put down: False, “”, 0 etc.

#28528
Stefan S.
Moderator

If the ValuesInterval doesn’t find an event, it returns a data series with zero values. So you can test this with the following code:

``If NumberOfRows(Idx) == 0 then``

FYI

With the following code you can test if a variable is empty:

``If variable == EMPTY then``

#28529
Leon D
Teilnehmer

It works great thanks a lot!

Just now i noticed that you can`t write a string into a Dataset, is that correct or am i missing something?

#28530
Stefan S.
Moderator

This is correct. You cannot use FPScript to change another object (e.g. dataset). Use the result of a new FPScript formula instead of the dataset and work with this (e.g. in a diagram). If you really want to change the original object, you have to use VBA script.

Ansicht von 4 Beiträgen – 1 bis 4 (von insgesamt 4)
• Du musst angemeldet sein, um auf dieses Thema antworten zu können.