Sara_j_11
asked on
vb - read input from text file
I use vb 6.0 to run a sql to which I pass parameters like statrt date and end date from
vb to sql.. and then print results to a file.
Private Function Build_Query(sFileName As String, customer As String, sFolderLoc As String)
Dim sInput As String
Dim sOutput As String
Open sFileName For Input As #1
Line Input #1, sInput ' Get a line of input from the file(sFileName) and store it in the sInput
' string
sOutput = sInput
Do While Not EOF(1)
Line Input #1, sInput
sOutput = sOutput & Chr(10) & sInput
Loop
sOutput = Replace(sOutput, "&BEGDATE", "'" & strBegDate & "'")
sOutput = Replace(sOutput, "&ENDDATE", "'" & strEndDate & "'")
sOutput = Replace(sOutput, "&customer_LIST", svcbr)
Close #1
Build_Query = sOutput
Open sFolderLoc & "\List_" & Format(strEndDate, "mmm") & "_" & Format(runDate, "mm""-""dd""-""yyyy") & ".txt" For Append As #5
Print #5, "This Report was run was for " & customer
Close #5
End Function
and then I make a call to the function build_query like this:
customer = "(1,7)"
sSQL = Build_Query(SQL_Home & "\sqlFileName.sql", customer, sFolderLoc)
If you notice I am hard coding the cutomer list like this:customer = "(1,7)"
Instead , I want to create a text file(using notepad) and store the customer values there in a folder and then use
that in my code,, so that every time the user changes the customer list, I dont have to change my code, instead i can just
change the text file contents.
How do I do this? Please add changes to my code to be specific.
vb to sql.. and then print results to a file.
Private Function Build_Query(sFileName As String, customer As String, sFolderLoc As String)
Dim sInput As String
Dim sOutput As String
Open sFileName For Input As #1
Line Input #1, sInput ' Get a line of input from the file(sFileName) and store it in the sInput
' string
sOutput = sInput
Do While Not EOF(1)
Line Input #1, sInput
sOutput = sOutput & Chr(10) & sInput
Loop
sOutput = Replace(sOutput, "&BEGDATE", "'" & strBegDate & "'")
sOutput = Replace(sOutput, "&ENDDATE", "'" & strEndDate & "'")
sOutput = Replace(sOutput, "&customer_LIST", svcbr)
Close #1
Build_Query = sOutput
Open sFolderLoc & "\List_" & Format(strEndDate, "mmm") & "_" & Format(runDate, "mm""-""dd""-""yyyy") & ".txt" For Append As #5
Print #5, "This Report was run was for " & customer
Close #5
End Function
and then I make a call to the function build_query like this:
customer = "(1,7)"
sSQL = Build_Query(SQL_Home & "\sqlFileName.sql", customer, sFolderLoc)
If you notice I am hard coding the cutomer list like this:customer = "(1,7)"
Instead , I want to create a text file(using notepad) and store the customer values there in a folder and then use
that in my code,, so that every time the user changes the customer list, I dont have to change my code, instead i can just
change the text file contents.
How do I do this? Please add changes to my code to be specific.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@DanRollins
Award me the points since I answered the question.
Sara_j_11 introduced an unrelated second question on 5/19.
=======================
@Sara_j_11
This is the first time I'm seeing this due to PC problems I'm having. Is this second problem still a problem for you or have you resolved it?
Award me the points since I answered the question.
Sara_j_11 introduced an unrelated second question on 5/19.
=======================
@Sara_j_11
This is the first time I'm seeing this due to PC problems I'm having. Is this second problem still a problem for you or have you resolved it?
ASKER
when I get to this line of code such as :
If rstRecordSet.RecordCount > 0 in the foll. module , I get the error - operation not allowed when object is closed.
what is that error and how do i correct it?
Private Sub WriteOutReport1(ByVal sFileName As String)
'remove_file (sFileName)
If rstRecordSet.RecordCount > 0 Then 'put data into file which will be read
Open sFileName For Output As #1
Write #1, rstRecordSet.Fields(0).Nam
rstRecordSet.Fields(2).Nam
rstRecordSet.Fields(4).Nam
rstRecordSet.Fields(6).Nam
rstRecordSet.Fields(8).Nam
Do While Not rstRecordSet.EOF
Write #1, rstRecordSet.Fields(0), rstRecordSet.Fields(1), _
rstRecordSet.Fields(2), rstRecordSet.Fields(3), _
rstRecordSet.Fields(4), rstRecordSet.Fields(5), _
rstRecordSet.Fields(6), rstRecordSet.Fields(7), _
rstRecordSet.Fields(8), rstRecordSet.Fields(9)
rstRecordSet.MoveNext
Loop
Close #1
'rstRecordSet.Close
End If
End Sub