02-25-2008 09:46 AM
02-25-2008 01:42 PM - edited 02-25-2008 01:44 PM
Dim a,b,c,d,f,grpindex,Frs,Channels,TempArray,grpname,exRange
TempArray = .Range(NamesRange).Value
for d = 1 to Channels
ChanNames(d-1) = TempArray(1,d)
Next 'd
Matthias Alleweldt Project Engineer / Projektingenieur | Twigeater? |
02-25-2008 02:05 PM
02-25-2008 02:26 PM
Matthias Alleweldt Project Engineer / Projektingenieur | Twigeater? |
02-26-2008 08:02 AM
You are correct about there being problems when Excel is already open when using the Diadem functions. I will have to work that out as I move forward in the program. Right now I am just trying to see if I can get Diadem to do what I need.
If you looked at the attached spreadsheet you may pick up on the problem I just figured out this morning. The channel names I am using come from another program that is further upstream and they cannot be changed due to other legacy software we have in place. The problem lies with the channel names using "illegal" characters that Diadem will automatically substitute a replacement (such as / replaced with \). This caused me great headaches until I finally realized what was happening. I then switched from using the names taken from the spreadsheet to using the channel index for referencing the destination for the incoming data.
One of many lessons I will certainly learn doing this program.
Thanks for the help.
Wayne
02-26-2008 06:14 PM
Hi Wayne,
I also checked out your code and made some changes. I agree with Twigeater that you should stick with all OLE commands and abandon the Excel Import Wizard functions entirely. I also recommend you use the ArrayToChannels() command to transfer the VBS data array to channels in the DIAdem Data Portal. It looks to me like your script left out the named data range, so I added in a dummy name (I couldn't guess the name you used) and requested the data values as a 2D array, just like you did for the names. You'll need to tweek the "DataRange" text to match what's in the Excel file, and you'll need to uncomment those two lines-- the commented code runs on my computer and imports the correct number of channels into each group.
Ask as you have further questions,
Brad Turpin
DIAdem Product Support Engineer
National Instruments
'-------------------------------------------------------------------------------
'-- VBS script file
'-- Created on 02/23/2008 19:56:07
'-- Author: Wayne Yount
'-- Comment: Trial to import excel based results
'-------------------------------------------------------------------------------
Option Explicit 'Forces the explicit declaration of all the variables in a script.
Call DataDelAll 'clear all previous data
Dim FilePath
FilePath = AutoActPath & "fw586 results.xls"
call LoadChannels(FilePath)
sub LoadChannels(FilePath)
Dim i, z, iMax, ErrNum, Excel, Sheet, WorkBook, SheetName
Dim TempArray, NamesRange, ChanNames, DataRange
WorkBook = NameSplit(FilePath, "N") & ".XLS"
On Error Resume Next
Set Excel = CreateObject("Excel.Application") ' Start Excel via OLE
ErrNum = Err.Number
On Error Goto 0
IF ErrNum <> 0 THEN MsgBox ErrNum : Exit Sub
Excel.Visible = FALSE ' Don't hide Excel during debug so you can close it manually
'Excel.ScreenUpdating = FALSE ' Disable screen refresh
call Excel.Workbooks.Open(FilePath) ' Open Excel File
for Each Sheet In Excel.Workbooks(WorkBook).Sheets
SheetName = Trim(Sheet.Name)
z = InStr(SheetName, "Sheet")
If Len(SheetName) = 6 and z = 0 then
Call GroupCreate(SheetName)
Call GroupDefaultSet(GroupCount)
NamesRange = SheetName & "!BodyRelativeChannelNames"
TempArray = Sheet.Range(NamesRange).Value
iMax = UBound(TempArray, 2)
ReDim ChanNames(iMax-1)
for i = 1 TO iMax
ChanNames(i-1) = "/" & TempArray(1, i)
next
' DataRange = SheetName & "!BodyRelativeChannelValues"
' TempArray = Sheet.Range(DataRange).Value
Call ArrayToChannels(TempArray, ChanNames, true, true)
end if
next ' Sheet
Excel.Workbooks(WorkBook).Close
Set Sheet = Nothing ' Release the object variable memory
Set Excel = Nothing ' Release the object variable memory
end sub
02-27-2008 09:51 AM