Solved

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

Posted on 2001-08-05
11
387 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
ID: 6354938
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
ID: 6354984
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
ID: 6354993
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 3

Expert Comment

by:Gunsen
ID: 6355014
' 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
ID: 6355498
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
 
LVL 3

Expert Comment

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

Expert Comment

by:CRAK
ID: 6355553
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
ID: 6355778
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
ID: 6357973
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
ID: 10476354
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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