02-28-2014 01:08 PM
I get an Error sgCmd = Replace(sgCmd,"#1",oChannel.GetReference(eRefTypeIndexName)) in this line "Invalid Character
Error in <TxtToNum.VBS> (Line: 208, Column: 61):
Invalid character
02-28-2014 03:52 PM
Hey Jcheese,
Where is this data coming from? What file format is it being loaded from? It's possible we can push the formatting you want into the DataPlugin being used, so all you have to do is drag the data file from the NAVIGATOR into the Data Portal and get the numeric channels you want automatically.
Care to send over a sample data set?
Brad Turpin
DIAdem Product Support Engineer
National Instruments
brad.turpin@ni.com
02-28-2014 08:03 PM
03-01-2014 02:53 AM
I double checked the code again, using the example data you posted. Its working. The only issue I could think of is that somehow a non-printable character was included by copying the code to and from the discussion forum. The code is definitely working. Here it is again:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Text to Numeric Channel ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' if programrevision > 1129 then Dim Channel,State,Dict3,t,TXT1 IF Data.Root.ChannelGroups(1).Channels.Count > 0 THEN FOR Each Channel In Data.Root.ChannelGroups(1).Channels IF Trim(UCase(Channel.Properties("DisplayType").Value)) = "TEXT" THEN Call ConvertTxtToNum(Channel) Call ValChn(Channel) END IF NEXT ' Channel END IF ' Any Channels at all END IF ' Program Version Function ConvertTxtToNum(Channel) Call Channel.ChannelGroup.Activate for t = 1 to Channel.Size IF Dict3.Exists(ChT(t,Channel.Name)) THEN ' Compares value in channel to value in dictionary ChT(t,Channel.Name) = Dict3.Item(ChT(t,Channel.Name)) ' changes the Key to the Item in the dictionary Else ChT(t,Channel.Name) = "0" end if 'dict3 next End Function ' ConvertTxtToNum() Function ValChn(oChannel) Dim sgCmd Dim ChnNumber : ChnNumber = oChannel.Properties("number").Value sgCmd = "ch(""#1"") = Val(ch(""#1""))" sgCmd = Replace(sgCmd,"#1",oChannel.GetReference(eRefTypeIndexName)) Calculate(sgCmd) End Function
03-05-2014 07:57 AM
Thanks, works fine. Must have copied a character somewhere.