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
237 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
  • 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

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

932 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

12 Experts available now in Live!

Get 1:1 Help Now