Home > Domino Tips > Developer > Agent > Importing data from files
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

AGENT

Importing data from files


Amy Weston
01.31.2006
Rating: -2.50- (out of 5)


Lotus Notes and Domino tips, tutorials and how-to articles
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


VIEW MEMBER FEEDACK TO THIS TIP

When processing files from other sources, sometimes you have fixed length files and sometimes you have delimited files. The routines SetVariableValueByLen and SetVariableValue are two generic subroutines that facilitate the process nicely and unclutters your code.

 
Code: Sub SetVariableValueByLen
( variablename As String, searchstring 
As String, strlen As Integer)
 
 variablename = Left(searchstring, strlen)
 searchstring = Right(searchstring, 
Len(searchstring) - strlen)
 
End Sub

Sub SetVariableValue( variablename As 
String, searchstring As String, searchchar As String)
 
 i = 0
 charat = 0
 For i = 1 To Len(searchstring)
  bchar = Mid(searchstring, i, 1)
  If bchar = searchchar Then
   charat = i
   'set i to the len of search so it 
will quit looping unnecessarily
   i = Len(searchstring)
  End If
 Next
 
 If ( charat = 0 ) Then
  'no searchchar found
  variablename =  Fulltrim(searchstring)
 Else
  If ( charact = 1) Then
   variablename = ""
   searchstring = Right(searchstring, 
Len(searchstring) - charat)
  Else   
   variablename = Left(searchstring, charat -1)
   searchstring = Right(searchstring, 
Len(searchstring) - charat)
  End If
 End If
End Sub


SAMPLE CALLING ROUTINE
fname = ws.OpenFileDialog(False, 
"Select file to be imported",, pathname) 
If Not(Isempty(fname)) Then
   Set stream = session.CreateStream
   pathname = Cstr(fname(0)) 
   If Not stream.Open(pathname, "ASCII") Then
      Messagebox pathname,, "Open failed"
      Exit Sub
   End If
   If stream.Bytes = 0 Then
      Messagebox pathname,, "File has no content"
      Exit Sub
   End If
  
   cnt = 0
   Do
      cnt = cnt + 1
      buffer$ = stream.ReadText
(STMREAD_LINE, EOL_CRLF)
      REM Discard lines with only LF + CR
      While buffer$ = Chr(13) & Chr(10) _
      And (Not stream.IsEOS)
         buffer$ = stream.ReadText(STMREAD_LINE)
 Wend
REM Process each line
   datavalue = buffer$
Call SetVariableValueByLen( checkstatus, 
datavalue, 1) Call SetVariableValueByLen
( bankdiv, datavalue, 
3) Call SetVariableValueByLen( account, 
datavalue, 10) Call SetVariableValueByLen
( checknum, datavalue, 
10) Call SetVariableValueByLen( yy, datavalue, 
2) Call SetVariableValueByLen( mm, datavalue, 
2) Call SetVariableValueByLen( dd, datavalue, 
2) Call SetVariableValueByLen( amountstr, datavalue, 
10) amount = Ccur( amountstr) \ 100 
Call SetVariableValueByLen( temp, datavalue, 
1) Call SetVariableValueByLen( unitcode, datavalue, 
3) Call SetVariableValueByLen( vendorid, datavalue, 
16) Call CreateCheckDoc() Loop 
Until stream.IsEOS Call stream.Close

MEMBER FEEDBACK TO THIS TIP

for delimited files I prefer something like this. I feel it's lot more readable:

Dim RecordEntry As Variant 
Line Input #Fh%, EntireLine 
                
'Explode the values from that 
record to return individual field values 
RecordEntry = 
Evaluate (|@Explode("| & EntireLine & |" ; ";")|) 

Call doc.ReplaceItemValue("Field1", RecordEntry(0)) 
Call doc.ReplaceItemValue("Field2", RecordEntry(1)) 
Call doc.ReplaceItemValue("Field3", RecordEntry(2)) 
...

—Thilo H.

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip library by member Amy Weston. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
Agent
Run or restart Notes/Domino agents via text messages
Approve Lotus Notes documents using a BlackBerry mobile device
LotusScript agent indexes Lotus Notes/Domino databases
Open documents in Lotus Notes from the Web without a UNID
Fix and update Lotus Notes documents with limited access
Verify scheduled agent status with Domino Extensible Language (DXL)
How to export data from a Lotus Notes database to a CSV file
Enable or disable scheduled agents without opening the Lotus Notes database design
Creating custom views in Lotus Notes databases
Editing fields in a Lotus Notes view with Ajax

Lotus Notes Domino Agents
How the Agent Profiler tool improves Notes/Domino performance
Run or restart Notes/Domino agents via text messages
Calculating results for a column in a Lotus Notes view
Approve Lotus Notes documents using a BlackBerry mobile device
LotusScript agent indexes Lotus Notes/Domino databases
Top 10 Lotus Notes/Domino coding and development tips of 2008
Open documents in Lotus Notes from the Web without a UNID
Fix and update Lotus Notes documents with limited access
Verify scheduled agent status with Domino Extensible Language (DXL)
Top 10 Lotus Notes Domino programming and development tips of 2007

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts