Solved

Write #filenum% when you don't know how many fields...

Posted on 2001-08-05
11
382 Views
Last Modified: 2013-12-18
I'm trying to write a function to export data to a text file. Simple enough hey?

Well, I want to keep it generic because it will be used to export many different documents with a different number of fields (based on a 'profile' document where the fields are specified.) The problem is that I can't pass a variant to the "Write filenum#, var()"

Is there any way to export to a file using LScript when you don't know the number of fields?

I thought of exploding the variant using an evaluate command but that wont work as the "Write" will surround the entire exploded string within quotes.

Basically I want to:
   Write filenum#, var(0), var(1), var(..n)
   where 'n' is not known at compile time.

Thanks.
Carl
0
Comment
Question by:Carl_Joseph
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 13

Expert Comment

by:CRAK
Comment Utility
Have you tried lbound(var) and ubound(var) to cycle through all elements in a for-next loop?
0
 
LVL 3

Expert Comment

by:Gunsen
Comment Utility
If varX Is Nothing Then
  ' NUL value, write blank?
  Write #filenum,
Else
  If IsArray( varX ) Then
    For i=Lbound(varX) To Ubound(varX)
      Write #filenum, varx(i)
    Next
  Else
    Write #filenum, varx
  End If
End If
0
 

Author Comment

by:Carl_Joseph
Comment Utility
That's not exactly what I'm after sorry. I need to be able to write out ONE LINE containing all the indexes of the variant. What you suggested will write:
_______
1, value1
2, value2
3, value3
_______

Where'as I want:
________
1, value1, value2, value3
2, ...
________

I need to construct:
   Write #filenum, var(0), var(1), var(..n)
  on the one line.

Is it even possible?

0
 
LVL 3

Expert Comment

by:Gunsen
Comment Utility
' Build up the string using temporary string variable
s = varX(Lbound(varX))
For i=Lbound(varX)+1 To Ubound(varX)
  s = s & ", " & varx(i)
Next
Write #filenum, s

0
 
LVL 13

Accepted Solution

by:
CRAK earned 100 total points
Comment Utility
Ithe array contains only one item, the code above results in an error. Try this one:

s = ''
For i=Lbound(varX) To Ubound(varX)
 s = s & varX(i)
 if i < Ubound(varX) then s = s & ", "
Next
Write #filenum, s



0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 3

Expert Comment

by:Gunsen
Comment Utility
No it dosn't.  It will simply skip then FOR LOOP....
0
 
LVL 13

Expert Comment

by:CRAK
Comment Utility
Lotus script does indeed skip it!
I have worked with several other BASIC-dialects in the past; some of them try to be smart and automatically start couting down, resulting in an error at VarX(1). I have grown a standard set of work-arounds; this was one of them....
My apologies!  ;-)
0
 
LVL 3

Expert Comment

by:Gunsen
Comment Utility
I know, for earlier versions of basic (until vb4 version i think), this was a no-no, dirty coding, and only a side-effect depending on the vb-runtime or (semi)compiler.
0
 

Author Comment

by:Carl_Joseph
Comment Utility
Well...figured it out...

'field_data' is an array containing the values to export for each record.
'field_string' is a string holding the concatenated values

    '// Write Values
    Forall vals In field_data
      If field_string = "" Then
         field_string = vals
      Else
          field_string = field_string + {", "} + vals    
      End If
    End Forall
         
    Write #fileNum, field_string
         
Similar to all of the above, but not quite. You need to include the quotes around each string value. Otherwise I would've used the Print #fileNum statement.
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
Carl_Joseph,
No comment has been added lately (935 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to CRAK http:#6355498
Please leave any comments here within 4 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

Zvonko
EE Cleanup Volunteer
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Domino not switching to TLS 1.0 4 757
Lotus Domino server 11 55
Domino Lotus Notes Client 4 66
attaching a file lotus notes 4 98
This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now