|
-
Oct 11th, 2000, 09:32 PM
#1
Thread Starter
Junior Member
Hello,I am sure this is easy but I am very new to vb and need your help.
I have a project where I have to read text files and convert it to a different format.
Let's say there are 7 fields, each field always has the same position so if ssn number assigned 13 spaces and uses 9 the rest have to be left justified and filled with spaces .The same for the names.There is another issue I have to use a default address but again it ie assigned 25 spaces but fills only 10. etc...
I read the files and convert it using With statement.
Please help.
Thank you
-
Oct 11th, 2000, 09:49 PM
#2
-
Oct 11th, 2000, 09:50 PM
#3
Hyperactive Member
use mid and lset
If I understand your probably, this will help. Lookup the mid function and use it for parsing out the input string. Lookup the lset function and use it to construct and write back a string.
-
Oct 11th, 2000, 10:00 PM
#4
Hyperactive Member
You are in a classrom aren't you?
I ask this because I can see that your tutor is wanting you do to something like the sample below.
You will want to use and leant the Type keyword in which you may create your own Type of variable. Another name you might see around is UDT (User Defined Type).
This simple example should see you pointed in the right direction. All the padding (thats what it's called when you want text fields to contain trailling spaces up to a preset limit) and truncating is handled for you automatically by the UDT.
Code:
' this is on a form with a Command Button
Option Explicit
' declare your UDT
Private Type MyType
SSN As String * 13
Address As String * 25
End Type
Private Sub Command1_Click()
'declare a variable
Dim myThing As MyType
' use the with keyword for ease of reading and speed
With myThing
' set one "field" of the UDT
.Address = "this is only part of it"
' set another field
.SSN = "1234"
End With
' print the content of the fields plus the length of them
Debug.Print myThing.Address, Len(myThing.Address)
Debug.Print myThing.SSN, Len(myThing.SSN)
End Sub
-
Oct 11th, 2000, 10:16 PM
#5
Thread Starter
Junior Member
I think you are on the right track paul,but I dont have a user interface in the project.
I declared everything in global module for the fields that I have and the ones I have to convert to.
lets say that the file that I am reading
is claimantSSN AND the one I have to convert to is ssn
with "Whatever"
claimantSSN=whatever.ssn
claimantName=whatever.Name
end with
I have to make sure that when the new file is created and goes to a different folder the length would be correct.
Like I said before they all start from the same position
Thank you so much for your response
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|