Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Top/Bottom Justification

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Example:

Input Data:
Line 1 Mr. John Q. Sample
Line 2
Line 3 1234 Any Street
Line 4 Anytown, US 99999

Desired Top Justified Output Data:
Line 1 Mr. John Q. Sample
Line 2 1234 Any Street
Line 3 Anytown, US 99999
Line 4

Desired Bottom Justified Output Data:
Line 1
Line 2 Mr. John Q. Sample
Line 3 1234 Any Street
Line 4 Anytown, US 99999

Code:

if Line4 = "" then
PrintLine Line4
PrintLine Line1
PrintLine Line2
PrintLine Line3
else
PrintLine Line1
PrintLine Line2
PrintLine Line3
PrintLine Line4
endif

How do I rewrite PrintLine as a function that outputs a string to a file or have it output a blank line if the input string is empty.
 
Use this to replace a blank string with a Carrige return (new line)
If Len(myString)=0 Then myString = vbCrLf
 
I am already doing that but it runs slow. I want to create an array to do this but I am not very familiar with arrays.

The other problem with the logic above is that there can be all different kinds of variations with the address block.
Line 2 and 4 could be missing or all but 1 line could be missing. Also, I do not want blank lines in my output file.
 
Don't know what you want to do but here is info on arrays

dim StrArray() as string 'array of strings
dim temp as string
dim Fp as integer
dim Index as long

fp=freefile()
open "YourFileName" fp for input
Index=0
do until(EOF)
lineinput #fp,temp
if temp <>&quot;&quot; then
redim StrArray(Index+1)
StrArray(Index)=Temp
Index=Index+1
endif
Loop
close(Fp)

Now StrArray will have data with empty strings removed.

BIG QUESTION:How do you know which data is a name, address, or a zipcode if the data can appear on any line and none to all fields can be missing?

I don't know how you can get more speed. If you have a lot of data that isn't well formatted, then your program has to process the information(which takes time). In this case, every line read from file has to be checked to see if its empty or not AND if its a name,address, or zipcode.

If a rational person made the data file, then there must be more organization than what you wrote.

 
I have a fixed fielded line sequencial file that I am reading in. The data that is being inputed is address information. I want to feed this information into an array and pull it out and append a tag name to the beginning and a vbcrlf at the end of each entry.

I have stored each one of these positions in a variable by creating a user defined type. My question is how do you store the information in an array and pull it back out to be able to top or bottom justify the data into an output file? I am not familiar with arrays and any help would be appreciated.

Example 1 (Bottom Justification):

Input:
Pos - 001 Len - 50 Data - *******AUTO**3-DIGIT 120
Pos - 051 Len - 50 Data - Mr. John Q. Sample
Pos - 101 Len - 50 Data - President
Pos - 151 Len - 50 Data - Any Company
Pos - 201 Len - 50 Data - Apt. 101
Pos - 251 Len - 50 Data - One Way West
Pos - 301 Len - 50 Data - 1234 Any Street
Pos - 351 Len - 50 Data - Anytown, US 12345

Desired Output:
<maddr1>*******AUTO**3-DIGIT 120
<maddr2>Mr. John Q. Sample
<maddr3>President
<maddr4>Any Company
<maddr5>Apt. 101
<maddr6>One Way West
<maddr7>1234 Any Street
<maddr8>Anytown, US 12345

Example 2 (Top Justification):

Input:
Pos - 001 Len - 50 Data - *******AUTO**3-DIGIT 120
Pos - 051 Len - 50 Data - Mr. John Q. Sample
Pos - 101 Len - 50 Data -
Pos - 151 Len - 50 Data -
Pos - 201 Len - 50 Data -
Pos - 251 Len - 50 Data -
Pos - 301 Len - 50 Data - 1234 Any Street
Pos - 351 Len - 50 Data - Anytown, US 12345

Desired Output:
<maddr1>
<maddr2>
<maddr3>
<maddr4>
<maddr5>*******AUTO**3-DIGIT 120
<maddr6>Mr. John Q. Sample
<maddr7>1234 Any Street
<maddr8>Anytown, US 12345

Example 1 (Top Justification):

Input:
Pos - 001 Len - 50 Data - *******AUTO**3-DIGIT 120
Pos - 051 Len - 50 Data - Mr. John Q. Sample
Pos - 101 Len - 50 Data - President
Pos - 151 Len - 50 Data - Any Company
Pos - 201 Len - 50 Data - Apt. 101
Pos - 251 Len - 50 Data - One Way West
Pos - 301 Len - 50 Data - 1234 Any Street
Pos - 351 Len - 50 Data - Anytown, US 12345

Desired Output:
<maddr1>*******AUTO**3-DIGIT 120
<maddr2>Mr. John Q. Sample
<maddr3>President
<maddr4>Any Company
<maddr5>Apt. 101
<maddr6>One Way West
<maddr7>1234 Any Street
<maddr8>Anytown, US 12345

Example 2 (Top Justification):

Input:
Pos - 001 Len - 50 Data - *******AUTO**3-DIGIT 120
Pos - 051 Len - 50 Data - Mr. John Q. Sample
Pos - 101 Len - 50 Data -
Pos - 151 Len - 50 Data -
Pos - 201 Len - 50 Data -
Pos - 251 Len - 50 Data -
Pos - 301 Len - 50 Data - 1234 Any Street
Pos - 351 Len - 50 Data - Anytown, US 12345

Desired Output:
<maddr1>*******AUTO**3-DIGIT 120
<maddr2>Mr. John Q. Sample
<maddr3>1234 Any Street
<maddr4>Anytown, US 12345
<maddr5>
<maddr6>
<maddr7>
<maddr8>
 
I think your better of using strings or userdefined data type but if you want an array....

dim A() as byte 'this declares an array of bytes
dim fp as integer
fp=freefile()
Open &quot;YOURINPUTFILE&quot; for input as fp
redim A(SIZEYOUWANT) ' this alocates ram memory for array

for i=1 to SIZEYOUWANT 'start loading file into array
A(i)=input(1,fp)
next i
close(fp)

'now the whole file is in an array

You can start manipulating the array. Here are some methods:
1)search an array for a value
for i= 0 to MaxValue
if A(i)= 15 then
'do stuff
endif
next i
2) to jump to a section of an array(in your case 50 byte increments)
A( Num*50+i)
here, Num is index for field and i is index for each character.
In your example 1, A(2*50+3)='t',A(3*50+6)='P'

Looking at your code, I would make an array of user defined data and open the input file for random access:

Type Pinfo
S(8) as string*50 'an array of 8 fixed length strings
End Type
fp=freefile()
Dim PAdrs(NumberNeeded+1) as Pinfo
Open &quot;MYDATA&quot; for random as fp len=sizeB(PAdrs(1))
for i=1 to NumberRecords
Get fp,i,Padrs(i)
next i

To do your justifing stuff:
Sub TopJust(ByRef Dat as Pinfo)
dim NumEmpty as integer
NumEmpty=0
for i=1 to 8
if Trim(Dat.s(i))<>&quot;&quot; then
'print to file
else
numempty=numempty+1
endif
next i
'Here print empty lines for numempty
end sub

Sub BotJust (ByRef Dat as Pinfo)
dim NumEmpty as integer
NumEmpty=0
for i=1 to 8
if trim(Dat.s(i))=&quot;&quot; then
numempty=numempty+1
endif
next i
'Here print empty lines for numempty

for i=1 to 8
if Trim(Dat.s(i))<>&quot;&quot; then
'write to file contents ot Dat.s(i)
endif
next i
end sub

to call function use a statement like
topjust PAdrs(5) or topjust PAdrs(i)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top