Results 1 to 10 of 10

Thread: vb consult sequential file by date

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2015
    Posts
    23

    vb consult sequential file by date

    hello i am octor
    I have a problem when consulted by date sequential file, I read the whole file, simply read by date.
    Save data does well


    Code:
    This form is to store data does well
    
    Dim date As String
    Dim name As String
    Dim lastname As String
    Dim product As String
    Dim quantity As Integer
    Dim price As Integer
    Dim overall As Integer
    Dim archive As String
    
    Private Sub Command1_Click()
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""
    Text5.Text = ""
    Text6.Text = ""
    Text2.SetFocus
    End Sub
    
    Private Sub Command2_Click()
    Dim i As Integer
    date = Text1.Text
    name = Text2.Text
    lastname = Text3.Text
    product = Text4.Text
    quantity = Text5.Text
    price = Text6.Text
    overall = Val(Text5.Text) * Val(Text6.Text)
    Text7.Text = Val(Text5.Text) * Val(Text6.Text)
    archive = App.Path & "\stock.txt"
    Open archive For Append As #1
    Write #1, fecha, name, lastname, product, quantity, price, overall
    For i = 0 To List1.ListCount - 1
    
            Print #1, List1.List(i)
            Next i
    Close #1
    
    End Sub
    
    
    
    This form is to consultation
    
    Dim fe As String
    Dim nom As String
    Dim apel As String
    Dim prod As String
    Dim cant As Integer
    Dim prec As Integer
    Dim tot As Integer
    Dim archivo As String
    Private Sub Command1_Click()
    Unload Me
    Form1.Show
    End Sub
    Private Sub Command2_Click()
    Text1.Text = ""
    List1.Clear
    Text1.SetFocus
    End Sub
    
    
    Private Sub Command3_Click()
    List1.Clear
    List2.Clear
    Dim k As Integer
    If Text1.Text = "" Then Exit Sub
    fe = Format(Text1.Text, Date)
    Text1.Text = fe
    Text2.Text = nom
    Text3.Text = apel
    Text4.Text = prod
    Text5.Text = cant
    Text6.Text = prec
    Text7.Text = tot
    archive = App.Path & "\stock.txt"
    Open archive For Input As #1
    If fe = Date Then
    While Not EOF(1)
    Input #1, fe, nom, apel, prod, cant, prec, tot
    List1.AddItem fe & "        " & nom & "       " & apel & "      " & prod & "       " & cant & "      " & prec & "        " & tot
    
    Wend
    End If
    Close #1
    
    End Sub

    thanks you

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,285

    Re: vb consult sequential file by date

    I really can't tell what your question is here.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2015
    Posts
    23

    Re: vb consult sequential file by date

    hello i am octor
    the question is who reads the entire file there several times and want to read only one time a day

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2015
    Posts
    23

    Re: vb consult sequential file by date

    hello i am octor
    There are several dates and
    * I want that reads just a date of one day

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,285

    Re: vb consult sequential file by date

    Sorry but you have not provided enough info.
    We have no idea what this file looks like or what "I want that reads just a date of one day " may mean.

    In order to get good help you must first start by giving a clear and detailed description of what problem you are facing. In this case that would need to include some sample of what the file looks like in addition to more detail on your question.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Mar 2015
    Posts
    23

    Re: vb consult sequential file by date

    hello i am octor
    the stock.txt file is:
    "03/14/2015", "e", "e", "e", 2,8,16
    "03/14/2015", "d", "d", "d", 2,8,16
    "03/14/2015", "c", "c", "c", 2,8,16
    "03/15/2015", "a", "a", "a", 2,8,16
    "03/15/2015", "b", "b", "b", 12,4,48

    for example if I say that out "03/14/2015" you exit

    "03/14/2015", "e", "e", "e", 2,8,16
    "03/14/2015", "d", "d", "d", 2,8,16
    "03/14/2015", "c", "c", "c", 2,8,16

  7. #7
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,285

    Re: vb consult sequential file by date

    Well that loop at the bottom could have an If statement added to it so that it only adds the items to the list box that matches your date
    Code:
    While Not EOF(1)
    Input #1, fe, nom, apel, prod, cant, prec, tot
      If Fe=MyDate Then
        List1.AddItem fe & "        " & nom & "       " & apel & "      " & prod & "       " & cant & "      " & prec & "        " & tot
      End IF
    Wend
    Assuming of course that is what you want to do, Hard to be sure when your posts only contain one or two sentences.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Mar 2015
    Posts
    23

    Re: vb consult sequential file by date

    hi i am octor
    I put a date and does not come out any results
    not know which is the error

  9. #9
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,895

    Re: vb consult sequential file by date

    In the Input statement the variable "fe" holds the date of current line.
    If you want to add only lines with a specific date then you should compare the date in "fe" with the desired date.

    Like DataMiser already showed you
    Code:
    While Not EOF(1)
    Input #1, fe, nom, apel, prod, cant, prec, tot
      Debug.Print fe, MyDate
      If Fe=MyDate Then
        List1.AddItem fe & "        " & nom & "       " & apel & "      " & prod & "       " & cant & "      " & prec & "        " & tot
      End IF
    Wend

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Mar 2015
    Posts
    23

    Re: vb consult sequential file by date

    hola soy octor
    solucionado


    Code:
    This form is to consultation
    
    Dim fe As String
    Dim nom As String
    Dim apel As String
    Dim prod As String
    Dim cant As Integer
    Dim prec As Integer
    Dim tot As Integer
    Dim archivo As String
    Private Sub Command1_Click()
    Unload Me
    Form1.Show
    End Sub
    Private Sub Command2_Click()
    Text1.Text = ""
    List1.Clear
    Text1.SetFocus
    End Sub
    
    
    Private Sub Command3_Click()
    List1.Clear
    List2.Clear
    Dim k As Integer
    If Text1.Text = "" Then Exit Sub
    fe = CDate(Text1.Text)
    Text1.Text = fe
    Text2.Text = nom
    Text3.Text = apel
    Text4.Text = prod
    Text5.Text = cant
    Text6.Text = prec
    Text7.Text = tot
    archive = App.Path & "\stock.txt"
    Open archive For Input As #1
    While Not EOF(1)
    Input #1, fe, nom, apel, prod, cant, prec, tot
    If fe = Text1.Text Then
    List1.AddItem fe & "        " & nom & "       " & apel & "      " & prod & "       " & cant & "      " & prec & "        " & tot
    End If
    Wend
    
    End Sub

    thank you very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width