|
-
Apr 9th, 2010, 10:35 AM
#1
Thread Starter
Junior Member
-
Apr 9th, 2010, 10:43 AM
#2
Re: log data to text file
Welcome to the forums. 
How is the sensor being read?
-
Apr 9th, 2010, 10:50 AM
#3
Thread Starter
Junior Member
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
-
Apr 9th, 2010, 10:54 AM
#4
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?
-
Apr 9th, 2010, 10:54 AM
#5
Thread Starter
Junior Member
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
-
Apr 9th, 2010, 12:20 PM
#6
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.
-
Apr 9th, 2010, 08:46 PM
#7
Thread Starter
Junior Member
Re: log data to text file
tq vry much mr.hack
-
Apr 10th, 2010, 12:08 PM
#8
Re: log data to text file
So, is your issue resolved, or do you still have a question?
-
Apr 11th, 2010, 08:29 PM
#9
Thread Starter
Junior Member
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
-
Apr 11th, 2010, 08:30 PM
#10
Thread Starter
Junior Member
Re: log data to text file
ops sory... you have explain there rite.. ok2.. tq..
-
Apr 11th, 2010, 08:59 PM
#11
Thread Starter
Junior Member
Re: log data to text file
errmm.. should i create the text file first?
i got the run time error 75
-
Apr 11th, 2010, 09:17 PM
#12
Thread Starter
Junior Member
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
-
Apr 12th, 2010, 09:18 AM
#13
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?
-
Apr 12th, 2010, 09:23 AM
#14
Thread Starter
Junior Member
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.
-
Apr 12th, 2010, 09:32 AM
#15
Re: log data to text file
 Originally Posted by anizz
... 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?
-
Apr 12th, 2010, 09:59 AM
#16
Thread Starter
Junior Member
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
-
Apr 12th, 2010, 10:08 AM
#17
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.
-
Apr 12th, 2010, 10:19 AM
#18
Thread Starter
Junior Member
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
-
Apr 12th, 2010, 10:20 AM
#19
Thread Starter
Junior Member
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
-
Apr 12th, 2010, 10:21 AM
#20
Thread Starter
Junior Member
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
-
Apr 12th, 2010, 10:25 AM
#21
Thread Starter
Junior Member
Re: log data to text file
YES!!!! i have resolved it... tq2!!!! tq so muchhhhh!!
-
Apr 12th, 2010, 10:26 AM
#22
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|