07-30-2002, 12:30 PM
I'm having a bit of bother with the few lines of VBscript below - I usually do ASP in Jscript and I'm not sure what's up with it?
This is in a chunk of code that loops through a recordset: the 'rs.Fields("database_field").value' bit definitely supplies a string that looks (for eg.) like "employees+first_name".
I get an error on the 'dbColumn=splitDBF(1)' line, saying:
Subscript out of range: '[number: 1]'
What am I doing wrong?
07-30-2002, 01:43 PM
Try doing a
Before each split to see how many elements are being put into the array.
It looks like on dbTable you are splitting by " ", then on dbColumn you are again splitting using " ". Do you want to split by the same delimiter twice?
07-31-2002, 10:20 AM
Pardon? Thanks for your help, I think I may have got myself a little lost somewhere.
I've got a string that looks like "tableName+columnName" coming out of a database recordset.
All I want to do is split it on the "+".
So I've set the variable "splitDBF" to be an Array - which is returned from running the Split() function on that recordset value, and which holds what I assume are only 2 elements:
dbTable="tableName" [the first element in the zero-based array "splitDBF"]
dbColumn="columnName" [the second element in the array]
Is that not what the bit of code I posted does? Am I splitting something twice?
07-31-2002, 10:34 AM
there may be some fields which doesnt have + sign. try to verify by running this code:
field = Cstr(rs.Fields("database_field").value)
response.write "Field: " & field & "<br>"
response.write "Ubound: " & ubound(splitDBF) & "<br>"
for i = 0 to ubound(splitDBF)
response.write i & ": " & splitDBF(i) & "<br>"
07-31-2002, 11:28 AM
Hmmm - this gets weirder.
There are indeed some records that don't contain the "+" sign. I THOUGHT I was catching that, but it turns out I'm not - and that's probably why it falls over when it gets to one.
So - this InStr() function. Does it actually work? If it doesn't find a match, it returns "0", right? Could anyone explain why the following:
Do While Not rs.EOF
Response.Write mydbString & " - "
Response.Write InStr("employees", mydbString)
results in my browser displaying:
employees+name_first - 0
employees+name_last - 0
addresses+email - 0
-- - 0
07-31-2002, 11:30 AM
I've just realised.
*Runs and hides sheepishly under his desk before swapping the argumments round for InStr()*