Topic
If-Condition with empty variable
Page d'accueil ' Communauté ' FPScript ' Condition If avec variable vide
- Ce sujet contient 3 réponses, 2 participants et a été mis à jour pour la dernière fois par Stefan S., le il y a 4 années et 5 mois.
-
AuteurMessages
-
11.12.2020 à 11:53 #33658Leon DParticipant
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.
Thanks in advance!
11.12.2020 à 12:24 #33659Stefan S.Maître des clésIf 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
11.12.2020 à 14:13 #33660Leon DParticipantIt 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?
11.12.2020 à 15:26 #33661Stefan S.Maître des clésThis 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.
-
AuteurMessages
- Vous devez être connecté pour répondre à ce sujet.