• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

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
    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.
  • 2
1 Solution
    Dim strCustData As String
    Open "C:\Folder\Config.txt" For Input As #1
    Input #1, strCustData
    Close #1
Sara_j_11Author Commented:
Thanks expert , i used a text file
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).Name, rstRecordSet.Fields(1).Name, _
                        rstRecordSet.Fields(2).Name, rstRecordSet.Fields(3).Name, _
                        rstRecordSet.Fields(4).Name, rstRecordSet.Fields(5).Name, _
                        rstRecordSet.Fields(6).Name, rstRecordSet.Fields(7).Name, _
                        rstRecordSet.Fields(8).Name, rstRecordSet.Fields(9).Name

        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)


        Close #1

    End If
End Sub
Award me the points since I answered the question.

Sara_j_11 introduced an unrelated second question on 5/19.  


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?

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now