From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

TextFileReadLn returns NoValue and not Null

Solved!
Go to solution

Hi,

 

I'm writing this to report an issue rather than look for a solution.

 

The help files state that TextFileReadLn will return Null when it reaches the end of the file. However, that doesn't seem to be the case, at least not with my installation of DIAdem 2022, as it returns NoValue instead.

 

A minor change to my code got it working.

 

Regards.

0 Kudos
Message 1 of 4
(843 Views)

Hi Simon_Aldworth,

 

Thank you for your information.

DIAdem uses NaN for NoValues and indicates that the variable contains no valid data.

VBS uses Null for the same behavior. In both cases you check for NoValues or for Null with the VBS function IsNull. In the end both NoValue and Null have the same meaning.

The following script (which describes your case) works fine.

dim iHdl, sFullFileName, text

sFullFileName = "MyFullFileName.txt"
iHdl = TextFileOpen(sFullFileName, eTextFileAttributeRead)
if iHdl <> 0 then
  do
    text = TextFileReadln(iHdl)
    if not isNull(text) then 
      msgbox text
    else
      TextFileClose(iHdl)
    end if
  loop until isNull(text)
end if

 

Greetings

Walter

0 Kudos
Message 2 of 4
(801 Views)

Hi Walter,

 

I'm afraid this doesn't work for me. My code is:

  T1 = TextFileReadLn(FileNum)
  If Not IsNull(T1) Then
    Call DataFileLoad(DataReadPath & T1)
    Etc, etc....
  End If

 

This fails because it enters the If...Then code and tries to load a file called "NOVALUE". 

 

However, the following is fine:

  T1 = TextFileReadLn(FileNum)
  If T1 <> "NOVALUE" Then
    Call DataFileLoad(DataReadPath & T1)
    Etc, etc...
  End If

 

Regards.

0 Kudos
Message 3 of 4
(768 Views)
Solution
Accepted by topic author Simon_Aldworth

Hi Simon_Aldworth,

 

Yes, the reason is T1. T1 is a DIAdem variable with the specific datatype String. A string can only contain text data and has no “marker” for NaN or Null. Therefor we implemented in case of assigning NaN (or Null) to DIAdem string variables the text “NoValue”.

In my example I used a VBS variable which is always a variant and can have different sub datatypes and works fine with NaN or Null.

 

Greetings

Walter

0 Kudos
Message 4 of 4
(764 Views)