DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Coverting Text Channel to Numberic using Dict.Add function

Solved!
Go to solution

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

0 Kudos
Message 11 of 15
(2,833 Views)

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

0 Kudos
Message 12 of 15
(2,826 Views)
Brad,
Thanks for looking into this. I have added a uri, data set and test script to the thread in the last comment .zip file. Again as always I appreciate any help or advice you have for me.
J
0 Kudos
Message 13 of 15
(2,819 Views)

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

 

 

0 Kudos
Message 14 of 15
(2,813 Views)

Thanks, works fine.  Must have copied a character somewhere.

0 Kudos
Message 15 of 15
(2,789 Views)