08-23-2010 12:56 PM
All,
I am building a program to gather data from a force gauge via RS232. One of the requirements of the program is to have the user tell the program what sample they are on in case their samples are not in order. I also need to check my Excel sheet if that sample has already been tested. Some of my code in a module looks like this:
Function HasSampleBeenTested(dblSample As Double, strSG As String) As Boolean
' Finds out if the sample being tested has already been tested.
HasSampleBeenTested = False
Range("B14").Select
'First, find the Sample Group Number
Do Until ActiveCell.Value = ""
If ActiveCell.Value = strSG Then
ActiveCell.Offset(0, -1).Select
Exit Do
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
' Next, find the actual sample
Do Until ActiveCell.Value = ""
If ActiveCell.Value = strSample And ActiveCell.Offset(0, 1).Value = strSG Then
HasSampleBeenTested = True
Exit Do
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
End Function
I also have a diagram wired to this exact instance of Excel, but I'm not sure how to wire my type (boolean) and get the data out as a boolean via the Variant to Data VI.
Solved! Go to Solution.
08-23-2010 01:10 PM
If the datatype of the variant is a Boolean then all you need to do is to wire a Boolean constant (its value is irrelevant) to the Variant to Data to convert the variant to a Boolean.
Note: Are "Sample #" and "Previous Sample" supposed to be integer values? If so, you should make the datatype I32 instead of DBL. If the value is truly floating point, then you should NOT be using an equal function to compare floats. Please search on this topic (comparing floats).
Also, any particular reason why you're using a local variable for "Raw Data Report" instead of a wire?
08-23-2010 01:14 PM
Yes, Sample Number and Previous Sample are supposed to be integer values.
Eariler on in my sequence, I create the file from a templete. I thought it would be easier doing a local variable. Is there a more acceptable solution?
08-23-2010 01:17 PM - edited 08-23-2010 01:19 PM
BadAzzS10 wrote:Eariler on in my sequence, I create the file from a templete. I thought it would be easier doing a local variable. Is there a more acceptable solution?
Yes. A wire. Local variables can "easily" create race conditions, so they're not as "easier" as most new LabVIEW programmers think. They have their uses, but for the most part they just lead to problems. See, for example, this thread of horror:
http://forums.ni.com/t5/BreakPoint/Why-some-people-say-Local-Variables-are-bad/td-p/711239
08-23-2010 01:21 PM
Yikes...and I have them all over the place!
08-23-2010 01:52 PM
08-23-2010 02:00 PM
One more thing, I'm getting lost on the Insert Into Array. I think it needs it to satisify the Excel Run Macro VI (that would be my Sample and the Sample Group that I send to the Excel module), but I'm getting a unwired or bad termal at that point.
08-23-2010 02:08 PM
There is no reason to actually have an Insert Into Array. The Build Array already gives you an array. The Excel Run Macro actually wants an array of variants, not an array of strings. The red coercion dot indicates that your array of strings is being converted to an array of variants. I'm not sure if the macro will actually received the Sample # correctly since you're converting it to a string. The safe bet would be to convert each value to a variant (using the To Variant function) and build an array from that to feed to the Excel Run Macro:
08-23-2010 02:13 PM
That appears to have worked. Thank you for your time! I've learned quite a bit.