[Newbie Question] Loop Problem
I am developing a GUI for a device called LabJack to get streaming data of UV light intensity.
Code:
For i = 0 To numScansToDisplay - 1
For j = 1 To numChannel
testdata = Format(adblData(j - 1 + (numChannel * i)), "#.####") + ","
data = data + testdata
Next j
data = CStr(TimeValue(Now)) + data + vbCrLf
Next i
RichTextBox1.Text = RichTextBox1.Text + data
This is the result i get
4:31:41 PM4:31:41 PM4:31:41 PM4:31:41 PM-.0005,4.9894,-.3128,-.3178,
-.0005,4.9843,-.3758,-.3909,
-.0005,4.9843,-.411,-.4211,
-.0005,4.9843,-.401,-.4236,
4:31:42 PM4:31:42 PM4:31:42 PM4:31:42 PM.002,4.9843,-.3959,-.4262,
-.0005,4.9818,-.4236,-.4362,
-.0005,4.9818,-.3959,-.4262,
.002,4.9793,-.4236,-.4312,
But if i change the code to
Code:
data = data + CStr(TimeValue(Now)) + vbCrLf
The results are
-.0005,4.9894,-.3128,-.3178,4:31:41 PM
-.0005,4.9843,-.3758,-.3909,4:31:41 PM
-.0005,4.9843,-.411,-.4211,4:31:41 PM
-.0005,4.9843,-.401,-.4236,4:31:41 PM
In fact, what i am trying to get is:
4:31:41 PM,.002,4.9843,-.3959,-.4262,
4:31:41 PM,-.0005,4.9818,-.4236,-.4362,
4:31:41 PM,-.0005,4.9818,-.3959,-.4262,
4:31:41 PM,.002,4.9793,-.4236,-.4312,
I have tried numeours codes but i have no idea how to do it :(
Thanks for help
Re: [Newbie Question] Loop Problem
With strings: Use & to combine them, not +
If using math on strings, ensure you convert the string to appropriate variable type first, i.e., CDbl(theString), CLng(theString), etc. Failing to do this could result in type mismatch errors and/or potentially incorrect calculations.
Re: [Newbie Question] Loop Problem
Try:
data = CStr(TimeValue(Now)) & "," & data & "," & vbCrLf
Re: [Newbie Question] Loop Problem
Quote:
Originally Posted by
some1uk03
Try:
data = CStr(TimeValue(Now)) & "," & data & "," & vbCrLf
But that isn't the only line that is using + to concatenate strings. OP should review post #2 also.
Re: [Newbie Question] Loop Problem
Thanks LaVolpe and Some1uk30.
I have tried your suggestions, but it doesn't work also. :(
Re: [Newbie Question] Loop Problem
Since I cannot test your code, Try this and tell me what are the two exact messages that you are getting?
Code:
For i = 0 To numScansToDisplay - 1
For j = 1 To numChannel
testdata = Format(adblData(j - 1 + (numChannel * i)), "#.####") + ","
Data = Data & testdata
Next j
MsgBox "1~~> " & Data '<~~ 1st Message
Data = CStr(TimeValue(Now)) & Data & vbCrLf
MsgBox "2~~> " & Data '<~~ 2nd Message
Exit Sub '<~~ For testing purpose only
Next i
Re: [Newbie Question] Loop Problem
Quote:
Originally Posted by
syahzuan
Thanks LaVolpe and Some1uk30.
I have tried your suggestions, but it doesn't work also. :(
Maybe you should show us your modified code and also tell us how you declared Data & testData.