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..:o
thanx a lot:)
Printable View
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..:o
thanx a lot:)
Welcome to the forums. :wave:
How is the sensor being read?
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 :(
So, you have the data in two textboxes, and you just want to write those two textboxes to a file? Is that it?
owh ya.. after it is displayed in text box.. i want it to be automatically saved to a textfile
Then work this into your codeIf the numbers are coming in constantly, then you might want to do something likeCode:Open "c:\SenorReading.txt" For Append As #1
Print #1, Text1.Text & " " & Text2.Text & vbCrLf
Close #1
How you do it is up to you.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
tq vry much mr.hack:)
So, is your issue resolved, or do you still have a question?
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
ops sory... you have explain there rite.. ok2.. tq..
errmm.. should i create the text file first?
i got the run time error 75
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
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?
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.
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?
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 :(
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.
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 :)
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
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
YES!!!! i have resolved it... tq2!!!! tq so muchhhhh!!
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.