• We should now be fully online following an overnight outage. Apologies for any inconvenience, we do not expect there to be any further issues.

vb6 reading specific field

confused123

Junior Member
Sep 17, 2007
4
0
0
Hi, I'm trying to make a viewer to read some data off a text file. The data looks like this:
10011009082007WEST xxxxxxxxx xxxxxxxxxxxxx
10020100702007EAST xxxxxxxxx xxxxxxxxxxxxx
So there is no delimiters here. I have to compare these data to a "specification sheet" which tells me what the first 6 digit mean and then extract the data from specific field of that line. So far I tried reading this line by line in vb6 but then I donno how to make it read the first 6 digits and then compare it to the specification sheet(its on paper) and extract data from the specified fields. Can anyone tell me an efficent way to do this in vb6? I'm an vb noob >_<


Edit* btw I want to output this to another text file TY
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Read the line in

Analyze the control info.

Branch to the appropriate handler based on the analysis, passing in either the complete line or the rest of the line that needs to be processed.
 

confused123

Junior Member
Sep 17, 2007
4
0
0
thx, I "think" I understand what your saying but can you give me like step by step instruction? sorry for being such a noob
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
I have no real experience with VB.

However, from a S/W Enginereing stand point....


Read in the file record

Extract the first 6 characters from the data record read in.

Determine which functional area that those 6 characters are related to on the spec sheets.

Have a control function that processes the data record. This function should be directly related to the spec sheet.

Pass the data record to the control function.

The control function should verify that the 6 control characters are proper for the function and then hand off the data record to other functions to tear it apart and do what ever with data.


You should have a control function for each type defined on the spec sheet.

Also, please fix your profile to be more accurate - presently it follows the pattern of spammers (which are not appreciated here).
 

Daishiki

Golden Member
Nov 9, 2001
1,943
36
91
Here's how to pull out the first 6 characters:

firstSix = Left(aString, 6)


firstSix will contain the first 6 characters, starting from the left, of aString.
 

confused123

Junior Member
Sep 17, 2007
4
0
0
I was able to read the first 6 characters. Then I made individual procedures for extracting fields. However I encountered yet another problem, I can't get it to read fields that are 50+ in the line. I used str1 = mid(strline,113,6). I can use this to read the first 15 or so chars fine but after that it just shows up blank in the output file. I'm assuming the mid is not made for something too deep into the line. Anyone know what i need to use? thx
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Again not knowing VB but based on Daishiki example;
Create two strings from your base string each time.

First string would be the Left (astring,6)
Second string would be the the Mid(astring,6)

I would thing that by not having the size, the Mid to go to the end.

Repeat the same logic above as needed. Extracting what you need to work with and storing the left overs in a new string for later use.

I would think the Mid should work, read up on the usage specs for that function.
 

Daishiki

Golden Member
Nov 9, 2001
1,943
36
91
Originally posted by: Common Courtesy
Again not knowing VB but based on Daishiki example;
Create two strings from your base string each time.

First string would be the Left (astring,6)
Second string would be the the Mid(astring,6)

I would thing that by not having the size, the Mid to go to the end.

Repeat the same logic above as needed. Extracting what you need to work with and storing the left overs in a new string for later use.

I would think the Mid should work, read up on the usage specs for that function.

Common Courtesy: Yup, using Mid(String, Long) will return everything until the end.

confused123: With "mid(strline,113,6)", it will return 6 characters, starting from the 113th. If strline has less characters than that, then that may the reason why you're seeing blanks.

Here's the example from MSDN on Mid:

Dim MyString, FirstWord, LastWord, MidWords
MyString = "Mid Function Demo" ' Create text string.
FirstWord = Mid(MyString, 1, 3) ' Returns "Mid".
LastWord = Mid(MyString, 14, 4) ' Returns "Demo".
MidWords = Mid(MyString, 5) ' Returns "Function Demo".


 

confused123

Junior Member
Sep 17, 2007
4
0
0
yeah, it does. The problem was the variable i used. It wasn't a global variable, so I had to use line input again when i called the procedure. Thanks for everything guys
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
You are welcome.

Thanks for fixing your profile.