We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

Empty cells in tab-delimited source file

matjashka
Advocate
Hello again,

I have a nested loop that takes data from columns in a tab-delimited file, before the mother loop jumps to the next row to repeat.
The nested loop is supposed to stop when it encounters an empty column.
	DO															!small loop - find matching LayoutNumber in columns 4 to n
		_readCell = input(_dataSource1, i, _iCol, _colnr)		!read row  starting with column _iCol in the database
		IF _readCell>0 AND _colnr = LayoutNumber THEN _foundMatch=1
		_iCol = _iCol+1
	WHILE _readCell>0

	IF _foundMatch=1 THEN _affected=1						!send info to array
It works great when the line (row) ends with a value. [edited for clarity]
The problem is that if an empty Tab occurs at the end of the line (i.e. file was edited as spreadsheet and saved from Excel) this completely breaks the script.
Per GS manual regarding INPUT():
The return value is the number of successfully read values, in case of end of file (-1).

Both the row and the column numbers have to be positive integers, otherwise you will get an error message.

If the row or column numbers are incorrect, the input will not be carried out. (n = 0)

If the row and the column can be identified, as many values shall be input from the given starting position as many parameters are given,
or if there are more parameters than values, the parameters without corresponding values will be set to zero.

In case of empty columns (i.e. if there is nothing between the separator characters) the parameters will be set to zero.
How should I interpret this information? I already have a condition that checks if the result of INPUT() is greater than zero, apparently that's not enough.
I tried to add a check if _colnr>0 (the returned value) is greater than zero, but that returns an "Uninitialized variable" error (all those have been declared earlier in the script that runs just fine in the above code)

Thank you!
Matt Krol [LinkedIn]
BHMS Architects and Planners, Chicago
AC 10 ... 26 USA
1 REPLY 1
matjashka
Advocate
OK it worked after forced change of the empty value into a string value:
	DO															!small loop - find matching LayoutNumber in columns 4 to n
		_readCell = input(_dataSource1, i, _iCol, _colnr)		!read row  starting with column _iCol in the database
		IF VARTYPE(_colnr)=1 THEN 
			_result = str(_colnr,1,0)
		ELSE
			_result = _colnr
		ENDIF
		IF _readCell>0 AND _result = LayoutNumber THEN _foundMatch=1
		_iCol = _iCol+1
	WHILE _readCell>0

	IF _foundMatch=1 THEN _affected=1						!send info to array
Matt Krol [LinkedIn]
BHMS Architects and Planners, Chicago
AC 10 ... 26 USA