Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

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

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
JohnDoeSr
Asked:
JohnDoeSr
  • 2
1 Solution
 
jkaiosCommented:
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
 
jkaiosCommented:
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
 
JohnDoeSrAuthor Commented:
Works like a charm.

Thanks!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now