Solved

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

Posted on 2001-08-05
11
391 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

630 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