Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2001-08-05
11
Medium Priority
?
393 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 400 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

721 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