By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,695 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,695 IT Pros & Developers. It's quick & easy.

multiple functions?

P: n/a
I have some code I am working on. One function reads a file using fso, then
I have multiple functions using the string read from the file. Each
function splits the lines up and will return one value.

Is there a better way? Is handling this many array which are basically the
same going to cause some server distress?
Thanks
Mike


Code:

Function ReadFile(strFileName)
Dim objFSO, ts, s
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ts = objFSO.OpenTextFile(strFileName, 1)
s = ts.Readall
ts.Close
Set objFSO = Nothing
ReadFile = s
End Function

Function GetBarCode(strBarcodeLine)
Dim Arline1, Arline2, ArCell1, strBarcode
Arline1 = Split(strBarcodeLine, vbCrLf)
Arline2 = Split(Arline1(0), ",")
ArCell1 = Split(Arline2(0), "=")
strBarcode = Trim(ArCell1(1))
GetBarCode = strBarcode
End Function

Function GetPlateFormat(strPlateFormatLine)
Dim Arline1, Arline2, ArCell1, strPlateFormat
Arline1 = Split(strPlateFormatLine, vbCrLf)
Arline2 = Split(Arline1(1), ",")
ArCell1 = Split(Arline2(0), "=")
strPlateFormat = Trim(ArCell1(1))
GetPlateFormat = strPlateFormat
End Function
Function GetPlateDate(strPlateDateLine)
Dim Arline1, Arline2, ArCell1, datPlateDate
Arline1 = Split(strPlateDateLine, vbCrLf)
Arline2 = Split(Arline1(3), ",")
ArCell1 = Split(Arline2(0), "=")
datPlateDate = Trim(ArCell1(1))
GetPlateDate = datPlateDate
End Function

Function GetReceivingLab(strReceivingLabLine)
Dim Arline1, Arline2, ArCell1, strReceivingLab
Arline1 = Split(strReceivingLabLine, vbCrLf)
Arline2 = Split(Arline1(5), ",")
ArCell1 = Split(Arline2(0), "=")
strReceivingLab = Trim(ArCell1(1))
GetReceivingLab = strReceivingLab
End Function


Dim strFileRead

strFileRead = ReadFile(strImportFiles)
Jul 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Mike" <Mi**@nospam.com> wrote in message
news:Oh**************@TK2MSFTNGP10.phx.gbl...
I have some code I am working on. One function reads a file using fso, then I have multiple functions using the string read from the file. Each
function splits the lines up and will return one value.

Is there a better way? Is handling this many array which are basically the same going to cause some server distress?


Are these operations all performed all at once, or one at a time? Better to
read the file each time if they happen one at a time. However, if you are
calling these all at once, read the file once, and pass it around as
function arguments.
Jul 19 '05 #2

P: n/a
If you can do the split once, it'll make the process more efficient. I do
similar stuff in my own code - if there's going to be an instance where I'm
opening - closing - opening - closing...I try very very hard to open and
close only once. The same goes for any process where I could potentially
duplicate the same action/set of actions several times.

- Wm

"Mike" <Mi**@nospam.com> wrote in message
news:Oh**************@TK2MSFTNGP10.phx.gbl...
I have some code I am working on. One function reads a file using fso, then I have multiple functions using the string read from the file. Each
function splits the lines up and will return one value.

Is there a better way? Is handling this many array which are basically the same going to cause some server distress?
Thanks
Mike


Code:

Function ReadFile(strFileName)
Dim objFSO, ts, s
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ts = objFSO.OpenTextFile(strFileName, 1)
s = ts.Readall
ts.Close
Set objFSO = Nothing
ReadFile = s
End Function

Function GetBarCode(strBarcodeLine)
Dim Arline1, Arline2, ArCell1, strBarcode
Arline1 = Split(strBarcodeLine, vbCrLf)
Arline2 = Split(Arline1(0), ",")
ArCell1 = Split(Arline2(0), "=")
strBarcode = Trim(ArCell1(1))
GetBarCode = strBarcode
End Function

Function GetPlateFormat(strPlateFormatLine)
Dim Arline1, Arline2, ArCell1, strPlateFormat
Arline1 = Split(strPlateFormatLine, vbCrLf)
Arline2 = Split(Arline1(1), ",")
ArCell1 = Split(Arline2(0), "=")
strPlateFormat = Trim(ArCell1(1))
GetPlateFormat = strPlateFormat
End Function
Function GetPlateDate(strPlateDateLine)
Dim Arline1, Arline2, ArCell1, datPlateDate
Arline1 = Split(strPlateDateLine, vbCrLf)
Arline2 = Split(Arline1(3), ",")
ArCell1 = Split(Arline2(0), "=")
datPlateDate = Trim(ArCell1(1))
GetPlateDate = datPlateDate
End Function

Function GetReceivingLab(strReceivingLabLine)
Dim Arline1, Arline2, ArCell1, strReceivingLab
Arline1 = Split(strReceivingLabLine, vbCrLf)
Arline2 = Split(Arline1(5), ",")
ArCell1 = Split(Arline2(0), "=")
strReceivingLab = Trim(ArCell1(1))
GetReceivingLab = strReceivingLab
End Function


Dim strFileRead

strFileRead = ReadFile(strImportFiles)

Jul 19 '05 #3

P: n/a
I am reading the file only once and setting it to a variable. That variable
is then split multiple times.

Thanks
Mike
"Richard K Bethell" <so*****@spammingisevil.bad> wrote in message
news:uH**************@TK2MSFTNGP12.phx.gbl...
"Mike" <Mi**@nospam.com> wrote in message
news:Oh**************@TK2MSFTNGP10.phx.gbl...
I have some code I am working on. One function reads a file using fso, then
I have multiple functions using the string read from the file. Each
function splits the lines up and will return one value.

Is there a better way? Is handling this many array which are basically

the
same going to cause some server distress?


Are these operations all performed all at once, or one at a time? Better

to read the file each time if they happen one at a time. However, if you are
calling these all at once, read the file once, and pass it around as
function arguments.

Jul 19 '05 #4

P: n/a
I'll try the split once.

Thanks for the reply

Mike

"William Morris" <se***************@hotmail.com> wrote in message
news:bo*************@ID-205671.news.uni-berlin.de...
If you can do the split once, it'll make the process more efficient. I do
similar stuff in my own code - if there's going to be an instance where I'm opening - closing - opening - closing...I try very very hard to open and
close only once. The same goes for any process where I could potentially
duplicate the same action/set of actions several times.

- Wm

"Mike" <Mi**@nospam.com> wrote in message
news:Oh**************@TK2MSFTNGP10.phx.gbl...
I have some code I am working on. One function reads a file using fso,

then
I have multiple functions using the string read from the file. Each
function splits the lines up and will return one value.

Is there a better way? Is handling this many array which are basically

the
same going to cause some server distress?
Thanks
Mike


Code:

Function ReadFile(strFileName)
Dim objFSO, ts, s
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ts = objFSO.OpenTextFile(strFileName, 1)
s = ts.Readall
ts.Close
Set objFSO = Nothing
ReadFile = s
End Function

Function GetBarCode(strBarcodeLine)
Dim Arline1, Arline2, ArCell1, strBarcode
Arline1 = Split(strBarcodeLine, vbCrLf)
Arline2 = Split(Arline1(0), ",")
ArCell1 = Split(Arline2(0), "=")
strBarcode = Trim(ArCell1(1))
GetBarCode = strBarcode
End Function

Function GetPlateFormat(strPlateFormatLine)
Dim Arline1, Arline2, ArCell1, strPlateFormat
Arline1 = Split(strPlateFormatLine, vbCrLf)
Arline2 = Split(Arline1(1), ",")
ArCell1 = Split(Arline2(0), "=")
strPlateFormat = Trim(ArCell1(1))
GetPlateFormat = strPlateFormat
End Function
Function GetPlateDate(strPlateDateLine)
Dim Arline1, Arline2, ArCell1, datPlateDate
Arline1 = Split(strPlateDateLine, vbCrLf)
Arline2 = Split(Arline1(3), ",")
ArCell1 = Split(Arline2(0), "=")
datPlateDate = Trim(ArCell1(1))
GetPlateDate = datPlateDate
End Function

Function GetReceivingLab(strReceivingLabLine)
Dim Arline1, Arline2, ArCell1, strReceivingLab
Arline1 = Split(strReceivingLabLine, vbCrLf)
Arline2 = Split(Arline1(5), ",")
ArCell1 = Split(Arline2(0), "=")
strReceivingLab = Trim(ArCell1(1))
GetReceivingLab = strReceivingLab
End Function


Dim strFileRead

strFileRead = ReadFile(strImportFiles)


Jul 19 '05 #5

P: n/a
strFilePath = 'Set file path here.
Set I = New Info
I.ParseFile(strFilePath)
strBarcode = I.BarCode
strPlateFormat = I.PlateFormat
strPlateDate = I.PlateDate
strReceivingLab = I.ReceivingLab
Set I = Nothing
Class Info
Private maryLines
Private mdblLines
Private mstrBarCode
Private mstrPlateFormat
Private mstrPlateDate
Private mstrReceivingLab

Private Sub Class_Initialize()
mdblLines = 0
mstrBarCode = ""
mstrPlateFormat = ""
mstrPlateDate = ""
mstrReceivingLab = ""
End Sub

Private Sub Class_Terminate()

End Sub

Public Property Get BarCode()
BarCode = mstrBarCode
End Property

Public Property Get PlateFormat()
PlateFormat = mstrPlateFormat
End Property

Public Property Get PlateDate()
PlateDate = mstrPlateDate
End Property

Public Property Get ReceivingLab()
ReceivingLab = mstrReceivingLab
End Property

Public Sub ParseFile(strPath)
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile(strPath, 1)
strData = File.ReadAll
File.Close
Set File = Nothing
Set FSO = Nothing
If Len(strData) > 0 Then
maryLines = Split(strData,vbCrLf)
mdblLines = UBound(maryLines) + 1
mstrBarCode = ParseLine(0)
mstrPlateFormat = ParseLine(1)
mstrPlateDate = ParseLine(3)
mstrReceivingLab = ParseLine(5)
End If
End Sub

Private Function ParseLine(intLine)
If CDbl(mdblLines) > CDbl(intLine) Then
arData1 = Split(maryLines(intLine),",")
arData2 = Split(arData1(0),"=")
ParseLine = Trim(arData2(1))
End If
End Function
End Class

-dlbjr

Discerning resolutions for the alms
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.