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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month7 days, 3 hours left to enroll

623 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