473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How skip to next line?

I am reading the text file and it works fine, until a start of string is not present. In that case it begins at start of text file and inserts all data to end point.

For example: ![TypeOfService] = getValue(strContent, 104, 105)

If there is no "104" in the file, it begins at beginning and copies all data to the end point of 105.

I hope I explained this clearly. I attempted on Line 41 but, I get a type mismatch.



Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. Public Function readFile(Optional strPath As String) As String
  4.     'Create a filesystemobject
  5.         Dim fso As Object
  6.  
  7.         Set fso = CreateObject("scripting.filesystemobject")
  8.  
  9.  
  10.     On Error GoTo Err_readFile
  11.  
  12.     'Open file for reading
  13.         strPath = "C:\Users\jeffrey.musgray\Desktop\TcossDocument.txt"
  14.         readFile = fso.OpenTextFile(strPath, 1).ReadAll
  15.  
  16.     'Cleanup
  17.         Set fso = Nothing
  18.  
  19. Exit Function
  20.  
  21. Err_readFile:
  22.      MsgBox "Error Description: " & Err.Description & vbCrLf & _
  23.             "LastDll Error: " & Err.LastDllError & vbCrLf & _
  24.             "Error Description: " & Err.Number & vbCrLf & _
  25.             "Location: readFile"
  26.  
  27.  
  28. Public Sub InputFile(Optional strContent As String)
  29.  
  30.      Dim rsDao As DAO.Recordset
  31.      Dim lngStart As Long
  32.  
  33.     On Error GoTo Err_InputFile
  34.  
  35.      Set rsDao = CurrentDb.OpenRecordset("SELECT * FROM TSR", dbOpenDynaset)
  36.  
  37.      rsDao.AddNew
  38.  
  39.      With rsDao
  40.         ![TsrNumber] = getValue(strContent, 101, 103)
  41.          If getValue(strContent, lngStart) Is Null Then NEXT
  42.         ![TypeOfAction] = getValue(strContent, 103, 104)
  43.         ![TypeOfService] = getValue(strContent, 104, 105)
  44.         ![NetworkRequirement] = getValue(strContent, 105, 1061)
  45.         ![OperationalSvcDate] = getValue(strContent, 1061, 1062)
  46.         ![RequestedSvcDate] = getValue(strContent, 1062, 107)
  47.         ![CCSDTrunkId] = getValue(strContent, 107, 108)
  48.         ![PurposeUseCode] = getValue(strContent, 108, 110)
  49.         ![TypeOperation] = getValue(strContent, 110, 111)
  50.         ![ModulationBandwidth] = getValue(strContent, 111, 112)
  51.         ![SVCAvailabilty] = getValue(strContent, 112, 115)
  52.         ![SignalingMode] = getValue(strContent, 115, 116)
  53.         ![CommSvcAuthorization] = getValue(strContent, 116, 117)
  54.         ![ProgDesignatorCode] = getValue(strContent, 117, 118)
  55.         ![OtimeExpeditingCharges] = getValue(strContent, 118, 119)
  56.         ![TransmissionMediaAV] = getValue(strContent, 119, 1201)
  57.         ![TerminalNodeLocation] = getValue(strContent, 1201, 1211)
  58.         ![StateCountryCode] = getValue(strContent, 1211, 1221)
  59.         ![AreaCode] = getValue(strContent, 1221, 1231)
  60.         ![FacilityCode] = getValue(strContent, 1231, 1241)
  61.         ![AddressSite] = getValue(strContent, 1241, 1251)
  62.         ![RoomNumber] = getValue(strContent, 1251, 1271)
  63.         ![TypeCryptoEquipment] = getValue(strContent, 1271, 1281)
  64.         ![Interface] = getValue(strContent, 1281, 1301)
  65.         ![UserTechnicalPOC] = getValue(strContent, 1301, 1311)
  66.         ![MailAddress] = getValue(strContent, 1311, 1401)
  67.         ![UnitIdentification] = getValue(strContent, 1401, 1202)
  68.         ![TerminalNodeLocation2] = getValue(strContent, 1202, 1212)
  69.         ![StateCountryCode2] = getValue(strContent, 1212, 1222)
  70.         ![AreaCode2] = getValue(strContent, 1222, 1232)
  71.         ![FacilityCode2] = getValue(strContent, 1232, 1242)
  72.         ![AddressSite2] = getValue(strContent, 1242, 1252)
  73.         ![RoomNumber2] = getValue(strContent, 1252, 1262)
  74.         ![TerminalEquipment2] = getValue(strContent, 1262, 1272)
  75.         ![TypeCryptoEquipment2] = getValue(strContent, 1272, 1282)
  76.         ![Interface2] = getValue(strContent, 1282, 1302)
  77.         ![UserTechnicalPoc2] = getValue(strContent, 1302, 1312)
  78.         ![MailAddress2] = getValue(strContent, 1312, 1402)
  79.         ![UnitIdentification2] = getValue(strContent, 1402, 401)
  80.         ![NarrativeInformation] = getValue(strContent, 401, 402)
  81.         ![TSRContact] = getValue(strContent, 402, 405)
  82.         ![EquipSVCAcqDit] = getValue(strContent, 405, 4071)
  83.         ![NationalSecSystem] = getValue(strContent, 4071, 409)
  84.         ![CmoAcceptService] = getValue(strContent, 409, 411)
  85.         ![SecurityRequirements] = getValue(strContent, 411, 413)
  86.         ![ShippingInformation] = getValue(strContent, 413, 4151)
  87.         ![DISAConNum] = getValue(strContent, 4151, 4152)
  88.         ![ExerciseProjectName] = getValue(strContent, 4152, 416)
  89.         ![CostThreshold] = getValue(strContent, 416, 417)
  90.         ![Remarks] = getValue(strContent, 417, 421)
  91.         ![USGateway] = getValue(strContent, 421, 430)
  92.         ![EstimatedSvcLife] = getValue(strContent, 430, 4371)
  93.         ![CPIWI] = getValue(strContent, 4371, 4372)
  94.         ![CPIWM] = getValue(strContent, 4372, 501)
  95.         ![JustifySVC] = getValue(strContent, 501, 510)
  96.         ![FundingTcoApproval] = getValue(strContent, 510, 514)
  97.         ![ReqActivityReqNumber] = getValue(strContent, 514)
  98.      End With
  99.      rsDao.Update
  100.      Set rsDao = Nothing
  101.  
  102.      Exit Sub
  103.  
  104. Err_InputFile:
  105.      MsgBox "Error Description: " & Err.Description & vbCrLf & _
  106.             "LastDll Error: " & Err.LastDllError & vbCrLf & _
  107.             "Error Description: " & Err.Number & vbCrLf & _
  108.             "Error Description: " & strContent & vbCrLf & _
  109.             "Location: InputFile"
  110.  
  111.  End Sub
  112.  
  113. Public Function getValue(strInput As String, lngStart As Long, Optional lngEnd As Long = 0) As String
  114.     'Get starting location
  115.     Dim lngPosStart As Long
  116.     Dim strStart As String
  117.     Dim lngPosEnd As Long
  118.  
  119. On Error GoTo Err_getValue
  120.  
  121.     strStart = vbCrLf & lngStart & "."
  122.     lngPosStart = InStr(1, strInput, strStart) + Len(strStart)
  123.  
  124.     If lngEnd <> 0 Then
  125.         lngPosEnd = InStr(1, strInput, vbCrLf & lngEnd & ".")
  126.     Else
  127.         lngPosEnd = Len(strInput)
  128.     End If
  129.     getValue = Mid(strInput, lngPosStart, lngPosEnd - lngPosStart)
  130.  
  131. Exit Function
  132.  
  133. Err_getValue:
  134.      MsgBox "Error Description: " & Err.Description & vbCrLf & _
  135.             "LastDll Error: " & Err.LastDllError & vbCrLf & _
  136.             "Error Description: " & Err.Number & vbCrLf & _
  137.             "Location: getValue"
  138.  
  139.  
  140.  
  141. End Function
  142.  
Mar 10 '11 #1
1 4697
NeoPa
32,556 Expert Mod 16PB
Jeffrey, That type of file parsing is specifically for use only with data files that do conform to the format expected. It doesn't handle (as far as I can see at least) anomalous data at all well.

Have you considered processing the file another way? Importing the data into an Access table first for instance?
Mar 11 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: les_ander | last post by:
Hi, suppose I am reading lines from a file or stdin. I want to just "peek" in to the next line, and if it starts with a special character I want to break out of a for loop, other wise I want to...
3
by: rasdj | last post by:
I have a lot of SQL to convert to postgres from oracle. I have most of the problems worked out except for this last bit. Many of my tables need the last comma replaced with a close parenthesis -...
1
by: Rocketman | last post by:
I am trying to find out when i reach the next line when multiline is switched on and i DON'T PRESS ENTER TO GO TO THE NEXT LINE(lines method is there for that purpose). Is there any other method i...
2
by: matthewtec | last post by:
I realize this is a very basic question, but I cannot figure out what to do in VB. if I have a TextBox called txtBoxOne, and I execute the line: txtBoxOne.Text = "First Line of text" I don't...
6
by: Jacob Rael | last post by:
Hello, I have a simple script to parse a text file (a visual basic program) and convert key parts to tcl. Since I am only working on specific sections and I need it quick, I decided not to...
22
by: ashkaan57 | last post by:
Hi, I am trying to put text on left and right side of the page and used: <div> <span>blah blah</span> <span style="float:right">blah blah</span> </div> The 2nd text does go to the right but the...
1
by: majorecono | last post by:
Im new to java and not too familiar with how to put the following text on 2 lines instead of one..... i know in C++ it was end. but how do you do it here? JOptionPane.showMessageDialog(null,...
4
by: Vernon Wenberg III | last post by:
I'm not really sure how readline() works. Is there a way to iterate through a file with multiple lines and then putting each line in a variable in a loop?
2
by: poolboi | last post by:
hi guys, i got the info say CLASS 1234 NAME DAN if i use the code below:
2
by: deenar | last post by:
Hi I'm having problems with Java in reading the next line in a text file to execute to find a solution. My program is read the data from the text file and excute it and provide the answer on the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.