473,785 Members | 2,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Start of file problem.

8 New Member
Hi,

I wonder if somebody could help me. My VB knowledge is limited and I need some help with a VB script an ex member of staff has written.

The script looks at a text file and pulls the infomation into Excel. As far as I can tell the scripts looks for === as the beginning point and then pulls the folling information until it gets to the end of line.

Example:-

=== 22601331 NC MANORD 1624.0 812.00 748.29 0.00 0.00 0.00 0.00 1560.29 0.00 060130 22601622 NC MANORD 1150.0 575.00 530.25 0.00 0.00 0.00 0.00 1105.25 0.00 060116

However, the format of the text file has changed and instead of the info being on 1 line it's now on several lines

Example:-

===
22601331 NC MANORD 1624.0 812.00 748.29 0.00 0.00 0.00 0.00 1560.29 0.00 060130
22601622 NC MANORD 1150.0 575.00 530.25 0.00 0.00 0.00 0.00 1105.25 0.00 060116

So the script is falling over as it isn't finding anything after the start point. I need a way of change the scripts from looknig for 1 continues line to looking for several lines.

The code that is currently being used is:-
Expand|Select|Wrap|Line Numbers
  1.  Dim Airline, AWBNum As String 
  2. Dim ProcDone, Cont, UseEst
  3. Dim Charges(100)
  4. Dim Descs(100), ChgDesc(100) As String
  5. Dim Estimates(100), Actuals(100)
  6. Dim I, J As Integer
  7. crow = 2
  8. chgcode = Sheets("Charges").Range("A" & crow)
  9. While chgcode <> ""
  10. Descs(chgcode) = Sheets("Charges").Range("B" & crow)
  11. crow = crow + 1
  12. chgcode = Sheets("Charges").Range("A" & crow)
  13. Wend
  14. numdesc = 0
  15. For I = 1 To 99
  16. desc = Descs(I)
  17. If desc <> "" Then
  18. found = False
  19. For J = 1 To numdesc
  20. If desc = ChgDesc(J) Then found = True: J = 99
  21. Next J
  22. If Not found Then
  23. numdesc = numdesc + 1
  24. ChgDesc(numdesc) = desc
  25. End If
  26. End If
  27. Next I
  28. ChgDesc(numdesc + 1) = "Other"
  29. ProcDone = False
  30. infile = Range("E7")
  31. UseEst = Range("AA1")
  32. On Error GoTo NoInFile
  33. Open infile For Input As #1
  34. On Error GoTo 0
  35. Workbooks.Add
  36. bookname = ActiveWorkbook.Name
  37. While Not EOF(1)
  38. fstart = 0
  39. While fstart = 0 And Not EOF(1)
  40. Line Input #1, inrec
  41. Cont = False
  42. recno = recno + 1
  43. fstart = InStr(inrec, "IATA CARGO ACCOUNTS SETTLEMENT SYSTEM")
  44. If fstart = 0 Then
  45. stpos = InStr(inrec, "=== ")
  46. If stpos <> 0 Then
  47. Cont = True
  48. fstart = 1
  49. Else
  50. If Left(inrec, 7) = "CARRIED" Then
  51. While Not EOF(1) And Left(inrec, 7) <> "BROUGHT"
  52. Line Input #1, inrec
  53. recno = recno + 1
  54. Wend
  55. If Not EOF(1) Then
  56. Line Input #1, inrec
  57. recno = recno + 1
  58. Cont = True
  59. stpos = -3
  60. fstart = 1
  61. End If
  62. End If
  63. End If
  64.  
Sorry for the stupidly long post but if anybody could shed any light on this I would be more then grateful.

Thanks in advance.
May 10 '06 #1
2 2132
Banfa
9,065 Recognized Expert Moderator Expert
Your question is unanswerable because you have not posted complete code and the part you have missed is the part that contains the problem you are asking about. This becaomes obvious when I reformat some of the posted code (the end) so that it is properly indented.

The code stpos = InStr(inrec, "=== ") tests for your start condition, the string probably wants to change from "=== " to "===" as you have no garunttee of a space after the = signs. If this is true it sets the variable cont to True. The code that this variable is used by has to be after the end of the code you have posted.


Expand|Select|Wrap|Line Numbers
  1. While Not EOF(1)
  2.   fstart = 0
  3.   While fstart = 0 And Not EOF(1)
  4.     Line Input #1, inrec
  5.     Cont = False
  6.     recno = recno + 1
  7.     fstart = InStr(inrec, "IATA CARGO ACCOUNTS SETTLEMENT SYSTEM")
  8.     If fstart = 0 Then
  9.       stpos = InStr(inrec, "=== ")
  10.       If stpos <> 0 Then
  11.         Cont = True
  12.         fstart = 1
  13.       Else
  14.         If Left(inrec, 7) = "CARRIED" Then
  15.         While Not EOF(1) And Left(inrec, 7) <> "BROUGHT"
  16.           Line Input #1, inrec
  17.           recno = recno + 1
  18.         Wend
  19.         If Not EOF(1) Then
  20.           Line Input #1, inrec
  21.           recno = recno + 1
  22.           Cont = True
  23.           stpos = -3
  24.           fstart = 1
  25.         End If
  26.       End If
  27.     End If
  28.  
May 11 '06 #2
Rodney Roe
61 New Member
I don't know if you want to rewrite your program but this would work and it's a little cleaner and easier to read.

Expand|Select|Wrap|Line Numbers
  1. Dim F, FS As Object
  2. Dim strContents, arrContents() As String
  3. Const ForReading = 1, ForWriting = 2, ForAppending = 8
  4.  
  5. Sub getString()
  6.  
  7. Set FS = CreateObject("Scripting.FileSystemObject")
  8. Set F = FS.opentextfile("C:\Rodney\Test.txt", ForReading) 'Change the path to your .txt file
  9.  
  10. Do Until InStr(1, strContents, "===") = 1
  11.     strContents = F.readline
  12. Loop
  13. ReDim arrContents(0)
  14.  
  15. Do While Not F.atendofstream
  16.     ReDim Preserve arrContents(UBound(arrContents) + 1)
  17.     strContents = F.readline
  18.     arrContents(UBound(arrContents)) = strContents
  19. Loop
  20.  
  21. Range("A1").Select
  22. For i = 1 To UBound(arrContents)
  23.     ActiveCell = arrContents(i)
  24.     ActiveCell.Offset(1, 0).Select
  25. Next
  26. End Sub
  27.  
Nov 18 '10 #3

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

Similar topics

16
12929
by: Kerry Neilson | last post by:
For the past couple of months, Idle won't start when I invoke it. I am at a complete loss for why this is. When this happens, they python command line still starts, and python works fine otherwise. Most interesting to me is that a reboot won't fix the problem. But if I just try it again sometime later it will work. Anyone have any ideas? I'm running python 2.3 on windows 2000 professional.
0
2095
by: Jeff Reed | last post by:
I am experiencing the the problem outlined the below. Unfortunately, I am using WinXP and I not sure if I can apply the solution due to lack of security control Any feed back would be apreciated http://support.microsoft.com/default.aspx?scid=kb;EN-US;31795 FIX: "Failed to Start Monitoring Directory Changes" Error Message When You Browse to an ASP.NET Pag View products that this article applies to This article was previously...
7
13407
by: Mark | last post by:
Hello, I have researched and tried every thing I have found on the web, in groups and MS KB articles. Here is what I have. I have a Windows 2000 Domain Controller all service packs and every thing else from windows update. ..NET 1.0 and 1.1 installed on the server. Actually .NET was installed before the server was made a DC.
9
3215
by: Tim D | last post by:
Hi, I originally posted this as a reply to a rather old thread in dotnet.framework.general and didn't get any response. I thought it might be more relevant here; anyone got any ideas? My questions are below... "David Good" wrote: > We have a network running both Win2k and Win2k3 webservers and our web sites > reside on a UNC network share that happens to be a Network Appliance NAS.
18
1808
by: Juan Gil | last post by:
I have a problem with this. I installed it in my computer to modify it, but when I try to save the configuration file(xml file) the server returned an error that say that I dont have permissions to write in the server. How i can write file in the server?.
16
3154
by: Fernando Arámburu | last post by:
Hi , it´s me again. I will take another way because yesterday I make a question and, probably I didn´t make myself clear so you didn´t understand my question. I want to know if there is any way to register a method to the Application Start event. I know there is one way, in Global.asax writing code in Application_Start
3
11757
by: Dean Slindee | last post by:
The code below is being used to launch WinWord.exe from a VB.NET program. Word launches, but displays this error message: "Word has experienced an error trying to open the file. Try these suggestions. 1) Check the file permissions for the document or drive. 2) Make sure there is sufficient free memory and disk space. 3) Open the file with the Text Recovery converter." The document that I want to display is on my PC and was created by...
0
2248
by: Sergistm | last post by:
Hello World, :D I have a problem that it is making me crazy, I hope you can help me. I'm trying to execute a .exe file with the Procces.Start, and there is no problem when the file is on my computer, the problem comes when the file is in a network drive. The most amazing thing is that in one computer I can execute my .Net program without problems independently if the file is
10
1978
by: Doug Robertson | last post by:
First off, I'm a hardware/OS guy. I just write code on the side and I'm completely self taught - so bear in mind my total lack of expertise. I have a program originally written in VB2003 using the dotnet 1.1 framework. The program makes extensive use of Win32 API calls to help manage and track remote access sessions with out clients. I've left it running for days at a time on my system with no problems. It has always been stable. I...
7
20440
by: =?Utf-8?B?ams=?= | last post by:
I am using System.Diagnostics.Process class to open a word document by call ing Process.Start("test.doc"). I am using C# as programming language. On some of the computers on running this code i get "Access is Denied" Win32Exception. What do i do to not generate this exception ? Any help highly appreciated, Thanks, Jay
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.