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:- - Dim Airline, AWBNum As String
-
Dim ProcDone, Cont, UseEst
-
Dim Charges(100)
-
Dim Descs(100), ChgDesc(100) As String
-
Dim Estimates(100), Actuals(100)
-
Dim I, J As Integer
-
crow = 2
-
chgcode = Sheets("Charges").Range("A" & crow)
-
While chgcode <> ""
-
Descs(chgcode) = Sheets("Charges").Range("B" & crow)
-
crow = crow + 1
-
chgcode = Sheets("Charges").Range("A" & crow)
-
Wend
-
numdesc = 0
-
For I = 1 To 99
-
desc = Descs(I)
-
If desc <> "" Then
-
found = False
-
For J = 1 To numdesc
-
If desc = ChgDesc(J) Then found = True: J = 99
-
Next J
-
If Not found Then
-
numdesc = numdesc + 1
-
ChgDesc(numdesc) = desc
-
End If
-
End If
-
Next I
-
ChgDesc(numdesc + 1) = "Other"
-
ProcDone = False
-
infile = Range("E7")
-
UseEst = Range("AA1")
-
On Error GoTo NoInFile
-
Open infile For Input As #1
-
On Error GoTo 0
-
Workbooks.Add
-
bookname = ActiveWorkbook.Name
-
While Not EOF(1)
-
fstart = 0
-
While fstart = 0 And Not EOF(1)
-
Line Input #1, inrec
-
Cont = False
-
recno = recno + 1
-
fstart = InStr(inrec, "IATA CARGO ACCOUNTS SETTLEMENT SYSTEM")
-
If fstart = 0 Then
-
stpos = InStr(inrec, "=== ")
-
If stpos <> 0 Then
-
Cont = True
-
fstart = 1
-
Else
-
If Left(inrec, 7) = "CARRIED" Then
-
While Not EOF(1) And Left(inrec, 7) <> "BROUGHT"
-
Line Input #1, inrec
-
recno = recno + 1
-
Wend
-
If Not EOF(1) Then
-
Line Input #1, inrec
-
recno = recno + 1
-
Cont = True
-
stpos = -3
-
fstart = 1
-
End If
-
End If
-
End If
-
Sorry for the stupidly long post but if anybody could shed any light on this I would be more then grateful.
Thanks in advance.
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. -
While Not EOF(1)
-
fstart = 0
-
While fstart = 0 And Not EOF(1)
-
Line Input #1, inrec
-
Cont = False
-
recno = recno + 1
-
fstart = InStr(inrec, "IATA CARGO ACCOUNTS SETTLEMENT SYSTEM")
-
If fstart = 0 Then
-
stpos = InStr(inrec, "=== ")
-
If stpos <> 0 Then
-
Cont = True
-
fstart = 1
-
Else
-
If Left(inrec, 7) = "CARRIED" Then
-
While Not EOF(1) And Left(inrec, 7) <> "BROUGHT"
-
Line Input #1, inrec
-
recno = recno + 1
-
Wend
-
If Not EOF(1) Then
-
Line Input #1, inrec
-
recno = recno + 1
-
Cont = True
-
stpos = -3
-
fstart = 1
-
End If
-
End If
-
End If
-
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. -
Dim F, FS As Object
-
Dim strContents, arrContents() As String
-
Const ForReading = 1, ForWriting = 2, ForAppending = 8
-
-
Sub getString()
-
-
Set FS = CreateObject("Scripting.FileSystemObject")
-
Set F = FS.opentextfile("C:\Rodney\Test.txt", ForReading) 'Change the path to your .txt file
-
-
Do Until InStr(1, strContents, "===") = 1
-
strContents = F.readline
-
Loop
-
ReDim arrContents(0)
-
-
Do While Not F.atendofstream
-
ReDim Preserve arrContents(UBound(arrContents) + 1)
-
strContents = F.readline
-
arrContents(UBound(arrContents)) = strContents
-
Loop
-
-
Range("A1").Select
-
For i = 1 To UBound(arrContents)
-
ActiveCell = arrContents(i)
-
ActiveCell.Offset(1, 0).Select
-
Next
-
End Sub
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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...
|
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.
|
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.
|
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?.
| |
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
|
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...
|
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
|
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...
|
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
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |