Solved

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

Posted on 2001-08-05
11
383 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

  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…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

895 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

15 Experts available now in Live!

Get 1:1 Help Now