Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textStream read and write 1

Status
Not open for further replies.

tonymontana69

Programmer
Feb 2, 2006
4
GB
Does anyone have code for a working textstream read and write, I would like to read a text file (unix report *.txt compliant)and parse with mid(mid$), and write a parsed output to another file(*.txt).
 
I'm a newbie in VBA. I have a simple VBA code that I used to get status/utilization of certain ckts on a particular GSM network element...hosted on a unix server. It is still in its raw state. At least it may give you an idea or something...
hope this helps.


Option Explicit
Dim Reflection2 As Reflection2.Application
Dim appExcel As Excel.Application
Dim row As Integer
Dim bscnum As Integer
Dim btsnum As Integer

Public Sub Main()

Set appExcel = CreateObject("Excel.application")
Workbooks("excelfile").Activate

Set Reflection2 = CreateObject("Reflection2.Application")
With Reflection2
'.Visible = True
If .Connected = False Then
.ConnectionType = "TELNET"
.ConnectionSettings = "Host 10.126.254.170" 'GSM
.Connect
End If
.ProcessDataComm = False
.WaitForString "login:"
.Transmit ("myname") & vbCr
.WaitForString "Password:"
.Transmit ("mypaswd") & vbCr
.WaitForString "myname%"
row = 3
Do Until Sheets("Sheet1").Cells(row, 3).Value = ""
btsnum = Sheets("Sheet1").Cells(row, 3).Value
bscnum = Sheets("Sheet1").Cells(row, 2).Value
.Transmit "bsc command -n bsc" & bscnum & vbCr
.WaitForString "< "
ZEELBTS
row = row + 1
Loop
.Transmit vbCr
.Transmit "exit" & vbCr
.Disconnect
.ProcessDataComm = True
.Quit
End With
MsgBox "Done"
End
End Sub

Private Sub ZEELBTS()
Dim lineread As String
Dim AlarmTime As String
Dim bfr As String
Dim bhr As String
Dim ifr As String
Dim ihr As String
Dim bsd As String
Dim isd As String
Dim brts As String
Dim gprsts As String

With Reflection2
.ProcessDataComm = False
.Transmit "ZEEL::BTS=" & btsnum & ";" & vbCr
Do While Not InStr(1, lineread, "<EE_>")
lineread = .ReadLine
Sheets("Sheet1").Cells(1, 1).Value = lineread
If Trim(lineread <> "") And InStr(1, lineread, "BSC4i_198") Then
AlarmTime = Mid(lineread, 37, 20)
ElseIf InStr(1, lineread, "BUSY FULL RATE") Then
bfr = Mid(lineread, 37, 3)
ElseIf InStr(1, lineread, "BUSY HALF RATE") Then
bhr = Mid(lineread, 37, 3)
ElseIf InStr(1, lineread, "IDLE FULL RATE") Then
ifr = Mid(lineread, 37, 3)
ElseIf InStr(1, lineread, "IDLE HALF RATE") Then
ihr = Mid(lineread, 37, 3)
ElseIf InStr(1, lineread, "BUSY SDCCH") Then
bsd = Mid(lineread, 37, 3)
ElseIf InStr(1, lineread, "IDLE SDCCH") Then
isd = Mid(lineread, 37, 3)
ElseIf InStr(1, lineread, "BLOCKED RADIO TIME SLOTS") Then
brts = Mid(lineread, 37, 3)
ElseIf InStr(1, lineread, "GPRS TIME SLOTS") Then
gprsts = Mid(lineread, 37, 3)
ElseIf InStr(1, lineread, "COMMAND EXECUTED") Then
Sheets("Sheet1").Cells(row, 1).Value = "'" & AlarmTime
Sheets("Sheet1").Cells(row, 5).Value = bfr
Sheets("Sheet1").Cells(row, 6).Value = bhr
Sheets("Sheet1").Cells(row, 7).Value = ifr
Sheets("Sheet1").Cells(row, 8).Value = ihr
Sheets("Sheet1").Cells(row, 10).Value = bsd
Sheets("Sheet1").Cells(row, 11).Value = isd
Sheets("Sheet1").Cells(row, 13).Value = brts
Sheets("Sheet1").Cells(row, 14).Value = gprsts
ElseIf InStr(1, lineread, "<EE_>") Then
Exit Do
End If
DoEvents
Loop
.Transmit "ZZZ;" & vbCr
.WaitForString "continue"
.Transmit " " & vbCr
.ProcessDataComm = True
End With
End Sub

 
I'm sure there are lots of stuff floating around this site on the topic. Here's a quickie, just typed, not tested ...

[tt]dim fs as object ' scripting.filesystemobject
dim txtin as object ' scripting.textstream
dim txtout as object ' scripting.textstream
dim strline as string

set fs = createobject("scripting.filesystemobject")
set txtin = fs.opentextfile("c:\test.txt", 1) ' 1 ForReading
set txtout = fs.createtextfile("c:\test2.txt", true)
do while not txtin.atendofstream
strline = txtin.readline
' manipulate the strline thingie
txtout.writeline strline
loop
txtin.close
txtout.close
set txtin = nothing
set txtout = nothing
set fs = nothing[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top