|
-
Apr 4th, 2007, 04:52 AM
#1
Thread Starter
Fanatic Member
Comparing strings in an array to excel cells
I am writing a dts package to import excel, the first stage is to compare the header row of the spreadsheet against array, to make sure the format is correct. I have the active x vbscript.
Code:
Function Main()
Dim excelapp, wkb, oSheet
Dim qArray(21),fileLink,x
qArray(0) = "#"
qArray(1) = "date"
qArray(2) = "time"
qArray(3) = "1*programme name"
qArray(4) = "2*customer experience programme name"
qArray(5) = "3*vendor name"
qArray(6) = "4*programme director name"
qArray(7) = "4*name of survey responder"
qArray(8) = "4*contract ref"
qArray(9) = "4*project title"
qArray(10) = "5 work type"
qArray(11) = "6 cost"
qArray(12) = "7 timescales"
qArray(13) = "8 quality"
qArray(14) = "9 flexibility"
qArray(15) = "10 changes"
qArray(16) = "11*responsiveness"
qArray(17) = "12*professionalism"
qArray(18) = "13 communication"
qArray(19) = "14 comparison"
qArray(20) = "15 rationale"
qArray(21) = "16 improvements"
Set excelapp = CreateObject("Excel.Application")
excelapp.visible = false
excelapp.displayalerts = false
excelapp.EnableEvents = false
Set wkb = excelapp.Workbooks.Open("/vendor/VDC101_M_Template.xls")
Set oSheet = wkb.Worksheets("Data")
for x = 0 to 21
if cstr(ucase(qArray(x))) <> ucase(left(cstr(oSheet.Cells(1, x + 1)),len(qArray(x)))) then
msgbox("Error with [" + lcase(qArray(x)) + "][" + lcase(mid(oSheet.Cells(1, x + 1).value,1,len(qArray(x)))) +"]")
end if
next
wkb.close
Set oSheet = nothing
Set wkb = nothing
excelapp.quit
set excelapp = nothing
Main = DTSTaskExecResult_Success
End Function
I trim the text in the cell in excel to the length of the strign in the array and then compare, showing a message box with the two strings if they dont match. It works up until comparing the 5th string then fails all until 10, 11, and 12 which work then fails again.
The msgbox that shows the failure however shows two identical strings.
I cannot see any difference by looking but there is obviously something in excel i cant spot. If I retype the whole cell in excel with the same text then it wil work, but as this is controlled by user I cannot do this all the time
Last edited by davebat; Apr 4th, 2007 at 04:57 AM.
-
Apr 4th, 2007, 04:55 AM
#2
Thread Starter
Fanatic Member
Re: Comparing strings in an array to excel cells
funnily enough when i posted into the code window below * appears in the spacing between the numbers in the array on the ones that are successful. Does anyone know what this character is as i didn't type that into my array
-
Apr 4th, 2007, 05:37 AM
#3
Thread Starter
Fanatic Member
Re: Comparing strings in an array to excel cells
I realised that excel wasnt using a space next to the number, but instead a masculine odrinal indicator.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|