Solved

Would like to Print 2nd dimension of array on the 50th position of its line in .txt file

Posted on 2006-11-27
3
241 Views
Last Modified: 2010-05-03
I'm saving off both parts of a 2 dimensional array onto a text file like so:

Open FileNameSave$ For Append As #2
For tt% = LastSave& To i%
    Print #2, EmailnPw$(tt%, 1) & ";" & EmailnPw$(tt%, 2)     - Email being (1,1) and PW being (1,2)
Next
Close #2

Each Email PW will be placed on its own line in the text file
I'd like to have the PWs line up in a nice column. The email will easily do this since it's placed on the first position of its line. I could easily add a TAB between email & pw but that will not guarantee me that the PW will be placed in the same position of the line since email lengths can vary.

What I'd like to do is something like place the PW on the something like the 50th position of its line, regardless of the length of the email address. Not 50 spaces AFTER the email has ended but 50th position from the start of the line. This way, if the length of an email address is 10 characters or 40, the pw will always be in the 50th position. The main objective here is to have a nice column of both email addresses and passwords like so:

john@frank.com                     pass1
sing@songsforboe.com           pass2
joe@joe.com                         pass3
0
Comment
Question by:JohnDoeSr
[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
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
jkaios earned 250 total points
ID: 18024293
Open FileNameSave$ For Append As #2
For tt% = LastSave& To i%
    Print #2, PadR(EmailnPw$(tt%, 1), 48) & ";" & EmailnPw$(tt%, 2)
Next
Close #2

'============================================================================
Public Function PadR(ByVal sExpr As String, ByVal iLength As Integer, Optional ByVal sPadChar As String = " ") As String
 
 ' Returns a string with padded chars on the Right side.
 PadR = Left$(sExpr & (String$(iLength, sPadChar)), iLength)

End Function
'============================================================================
0
 
LVL 12

Expert Comment

by:jkaios
ID: 18024325
If you plan to remove the semi-colon (";") as the separator between the email address and the password, then
simply increase the length of the string from 48 to 49 as follows:

========================================
   Print #2, PadR(EmailnPw$(tt%, 1), 49) & EmailnPw$(tt%, 2)
========================================

This will print the email address (padded with spaces up to the 49th column/position).  Therefore, the next printed text, which is the password, will ALWAYS be on the 50th column or position within the text file.

Cheers!
0
 

Author Comment

by:JohnDoeSr
ID: 18024957
Works like a charm.

Thanks!
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

729 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