Results 1 to 22 of 22

Thread: [RESOLVED] log data to text file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    22

    Resolved [RESOLVED] log data to text file

    hi.. this is first time i'm joining a forum

    a need a help to log data to text. i'm doing temperature data logger.. so i need to keep on logging the temperature of 2 sensor to a text file.. can any one help me..

    thanx a lot

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: log data to text file

    Welcome to the forums.

    How is the sensor being read?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    22

    Re: log data to text file

    how sweet.. tq

    the sensor is controlled by my microcontroller. then it sends one byte of converted temperature to serial port which then i will display at a textbox. then another byte from second sensor is sent and display to second textbox. previously i make the two textbox as an array because i follow an example of MSFlexgrid.. sadly, i failed to open the file format.what about textfile? should it be in an array?

    to separate the two bytes.. i just use #254H and #253H in the assembly code.

    is my explanation clear? sorry coz i really bad at doing project

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: log data to text file

    So, you have the data in two textboxes, and you just want to write those two textboxes to a file? Is that it?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    22

    Re: log data to text file

    owh ya.. after it is displayed in text box.. i want it to be automatically saved to a textfile

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: log data to text file

    Then work this into your code
    Code:
    Open "c:\SenorReading.txt" For Append As #1
    Print #1, Text1.Text & " " & Text2.Text & vbCrLf
    Close #1
    If the numbers are coming in constantly, then you might want to do something like
    Code:
    Open "c:\SenorReading.txt" For Append As #1
    'your code to read the sensor goes here
    Print #1, Text1.Text & " " & Text2.Text & vbCrLf
    Close #1
    How you do it is up to you.
    Last edited by Hack; Apr 10th, 2010 at 12:07 PM.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    22

    Re: log data to text file

    tq vry much mr.hack

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: log data to text file

    So, is your issue resolved, or do you still have a question?

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    22

    Re: log data to text file

    really sorry mr.hack.. actly i'm so busy for my other 2 assignments this weken.. only now i'll come back to VB.. by the way.. may i now how to log the data with same space (meaning like coloumn) for 3 data : 2 for the read temperature and one for the time.

    tq very much for helping me

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    22

    Re: log data to text file

    ops sory... you have explain there rite.. ok2.. tq..

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    22

    Re: log data to text file

    errmm.. should i create the text file first?

    i got the run time error 75

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    22

    Re: log data to text file

    ok.. i setlle about the creating the file..

    actly i try to learn save the text box first.. i just create simple program for that so that i really understand how to save to text file.

    i just add one button for save.. my status now.. there is nothing in the text file that is saved when i clelck the save button. here is the code :

    Private Sub Command1_Click()

    Text1.Text = input1
    Text2.Text = input2

    Text3.Text = Time

    Open "C:\Program Files\Microsoft Visual Studio\VB98\SenorReading.text" For Append As #1
    Print #1, Text1.Text & " " & Text2.Text & " " & Text3.Text & vbCrLf
    Close #1


    End Sub

    Private Sub Form_Load()
    Dim input1 As Single
    Dim input2 As Single

    Text1.Text = input1
    Text2.Text = input2

    Text3.Text = Time


    End Sub

    Private Sub Text3_Change()
    Text3.Text = Now
    End Sub

    where should i adjust... sorry that my question is so easy.. i really new to coding

  13. #13
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: log data to text file

    If the path exists, you should see something in the file.

    Note: In command1_click you are setting Text3.Text=Time, that causes a Change event to occur. In your Text3_Change event, you are setting Text3.Text=Now. So Text3.Text will never contain just the time.

    Do you get any errors?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    22

    Re: log data to text file

    owh.. i didnt realise that. i have change it. but i didnot receive any error message.

    i save the text file in the VB98 folder. it is correct right? hhmm.. still nothing in that file.

  15. #15
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: log data to text file

    Quote Originally Posted by anizz View Post
    ... i save the text file in the VB98 folder. it is correct right? hhmm.. still nothing in that file.
    Where you save your file is up to you. Permissions on newer Operating Systems may prevent saving in locations other than typical My Document folders, but that is another topic and you should read this FAQ topic.

    I find it hard to believe that the file has nothing in it, unless you are getting errors. The content of your 3 textboxes + a carriage return should be in that file. If those textboxes are empty/blank, then you should still have a file with just carriage returns.

    Ensure you are looking at the same file you are saving to. If you have any statements like On Error Resume Next, rem those out or remove them for now because they are hiding errors that should be brought to your attention. Are you accessing the file anywhere else in your program & if so, where/how?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    22

    Re: log data to text file

    owh.. this is weird..

    i do not have any other code because i just test to save the textbox to text file first. if this succeed. then only i will use it in the temperature main program.

    i'm using Vista.. i quite not understand what should from FAQ topic.

    i have try to change the location to desktop and my document.. but still nothing.

    hhmmm.. i always get these weird2 problem.. huhu

  17. #17
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: log data to text file

    Maybe the file you are looking at isn't the one you wrote. Vista virtualization may be in play?

    Some other notes: add this line to the very top of your form: Option Explicit
    In command1_click you have these statements:
    Text1.Text = input1
    Text2.Text = input2

    Input1 and Input2 are nothing, they aren't declared. VB will declare them as Variants by default if no DIM statement is used. Input1/2 are declared in form_load, but they apply to that routine only.

    The links I provided above are more FAQ topics you should read. You may want to spend some time in the VB FAQ section and browse other topics related to your program. In my signature below is a link to the main FAQ page.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    22

    Re: log data to text file

    i have some little progress now.. but not fully correct yet.

    when i deleted the input1 and input2 line from original code.. suddenly i have printed something in the text file. it appears like this

    " 4/12/2010 10:53:05 PM
    "
    " 4/12/2010 10:53:15 PM
    "

    however.. when i enter other value to the text box.. the contain of that file still unchanged.. i stick to that line..

    i tried to modified some of the code.. but still cannot change the first reading as above.. do you have any idea.. i will try too

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    22

    Re: log data to text file

    this is my current code

    Private Sub Command1_Click()


    Text1.Text = input1
    Text2.Text = input2
    Text3.Text = Now

    Open "C:\Users\Anis\Documents\SenorReading.text" For Append As #1
    Write #1, Text1.Text & " " & Text2.Text & " " & Text3.Text & vbCrLf
    Close #1



    End Sub

    Private Sub Form_Load()
    Dim input1 As Single
    Dim input2 As Single







    End Sub

    Private Sub Text3_Change()
    Text3.Text = Now
    End Sub

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    22

    Re: log data to text file

    oh.. no no.. i have the file.. i forgot to delete from my desktop.. so the file is actually at my document.. so the only problem is the value of text 1 and 2 are missing

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    22

    Re: log data to text file

    YES!!!! i have resolved it... tq2!!!! tq so muchhhhh!!

  22. #22
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: log data to text file

    They are missing because input1 & input2 are not declared; therefore, they are default variants with a value of Empty. Read both links I gave you in post #17.

    Edited: See you resolved it; glad to hear it. Be sure to mark this thread as resolved: dropdown "Thread Tools" menu near top of your first post above.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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