ถามเรื่อง Subscript out of range: 'ubound' Error เช็คเคสที่ข้อมูลใน DB เป็น 0
Code (ASP)
<!--#include file="./include/connectdb.asp"-->
<!--#include file="./js/function_all.js"-->
<%
'############################
'###### CONNECT DATABASE ########
'############################
'****Get Drawing Type *****
Set ObjRSDrawType = Server.CreateObject("ADODB.Recordset")
DSql = "select * from MASTER_TYPE"
ObjRSDrawType.Open DSql, ObjConn, 3, 1
'****Get Design 's Mgr. for approve drawing type *****
Set ObjRSMgrDesign = Server.CreateObject("ADODB.Recordset")
DSql = "select * from MASTER_USER"
ObjRSMgrDesign.Open DSql, ObjConn, 3, 1
' ***** Declaration Variable for Array *****
Dim dList_drawreq()
Dim dList_drawno()
Dim dList_drawname()
Dim dList_drawrevision()
Dim dList_drawvencode()
Dim dList_drawvenname()
Dim dList_drawbuyer()
Dim dList_drawtype()
Dim dList_drawregister()
'#########################
Set objAdoDisList = Server.CreateObject("ADODB.Recordset")
dSql = ""
dSql = dSql & " SELECT DISTINCT * FROM DISTRIBUTION d "
dSql = dSql & " LEFT OUTER JOIN MASTER_TYPE t "
dSql = dSql & " ON d.Type_ID = t.Type_ID "
dSql = dSql & " LEFT OUTER JOIN MWEB_VD_MSTR v "
dSql = dSql & " ON d.vendor_code = v.vd_addr "
dSql = dSql & " Where Distribution_Flag = '1' "
dSql = dSql & " order by Request_ID DESC "
objAdoDisList.Open dSql, ObjConn, 3, 1
response.write("SQL" & dSql) & "<br/>"
lCnt = 0
do while objAdoDisList.eof = false
redim Preserve dList_drawreq(lCnt)
redim Preserve dList_drawtype(lCnt)
redim Preserve dList_drawno(lCnt)
redim Preserve dList_drawname(lCnt)
redim Preserve dList_drawrev(lCnt)
redim Preserve dList_drawvencode(lCnt)
redim Preserve dList_drawvenname(lCnt)
redim Preserve dList_drawapp(lCnt)
redim Preserve dList_drawbuyer(lCnt)
dList_drawreq(lCnt) = objAdoDisList("Request_ID")
dList_drawtype(lCnt) = objAdoDisList("Type_ID")
dList_drawno(lCnt) = objAdoDisList("Draw_No")
dList_drawname(lCnt) = objAdoDisList("Draw_Name")
dList_drawrev(lCnt) = objAdoDisList("Draw_Revision")
dList_drawvencode(lCnt) = objAdoDisList("Vendor_Code")
dList_drawvenname(lCnt) = objAdoDisList("Vendor_Name")
dList_drawapp(lCnt) = objAdoDisList("Draw_App")
dList_drawbuyer(lCnt) = objAdoDisList("Buyer_Name")
lCnt = lCnt +1
objAdoDisList.MoveNext
loop
'##############END CONNECT ##################
%>
<html>
<head>
<title>Menu</title>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620" />
<link rel="stylesheet" href="css/drawing.css" type="text/css">
</head>
<body>
<FORM NAME="form_input" ACTION="inputdrawing.asp" METHOD="POST">
<input type="text" name="SSdrawno" value="<%=request.form("draw_no")%>" >
<table width="95%" height="60" border="0" align=center>
<tr>
<td align="center" ><font size=5 color="#003366"><strong>INPUT DRAWING DATA</strong></font></td>
</tr>
</table>
<table align=center border="1" width="95%" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="100%" class="ht" >
<tr>
<input name="draw_RequestID" type='text' maxlength='5' value="<%=request.form("draw_RequestID")%>">
<td width="13%" >Drawing No. : <font color="#FF0000">*</font></td>
<td width="22%">
<input name="draw_no" type="text" maxlength="15" value="<%=request.form("draw_no")%>" onclick ="Check_drawno()">
<input name="draw_search" type='submit' maxlength='5' value="..." target="_blank"
onclick="WinOpenSel(925,642,'yes',draw_no.value,'search_drawing.asp')"></td>
<td width="13%">Drawing Name : <font color="#FF0000">*</font></td>
<td width="25%"><input type="text" maxlength="50" name="draw_name" size="30" align="left" value="<%=request.form("draw_name")%>"></td>
<td width="10%">Revision : <font color="#FF0000">*</font></td>
<td width="4%"><input type="text" name="draw_revision" maxlength="3" size="5" value="<%=request.form("draw_revision")%>"></td>
<td width="20%"><div align="center"><input name="button1" type="button" style="width:100px;" onClick="buttonClick_Input(1)" value="Input/Update"></div></td>
</tr>
<tr class="ht">
<td>Vendor Code : </td>
<td><input name="draw_vencode" type="text" maxlength="15" size="30" value="<%=request.form("draw_vencode")%>"></td>
<td>Vendor Name : </td>
<td><input type="text" maxlength="50" name="draw_venname" size="30" value="<%=request.form("draw_venname")%>"></td>
<td>Buyer Code :</td>
<td><input type="text" name="draw_buyer" maxlength="3" size="5" value="<%=request.form("draw_buyer")%>"></td>
<td><div align="center"><input name="button2" type="button" style="width:100px;" onClick="buttonClick_Input(2)" value="Delete"></div></td>
</tr>
<tr class="ht">
<td>Drawing Type :</td>
<td><select name="draw_type" style="width:145">
<option value="">-- SELECT--</option>
<%
If ObjRSDrawType.eof <> True Then
While Not ObjRSDrawType.EOF
response.write ("<option value='" & ObjRSDrawType("Type_ID") & "'")
if draw_type = ObjRSDrawType("Type_name") then
response.write (" selected")
end if
response.write (">" & ObjRSDrawType("Type_name") & "</option>")
ObjRSDrawType.MoveNext
Wend
End If
ObjRSDrawType.Close
Set ObjRSDrawType = Nothing
%>
</select>
</td>
<td>Manager Approve : </td>
<td><select name="draw_app" style="width:200">
<!-- <option value="">-- SELECT--</option> -->
<%
' If ObjRSMgrDesign.eof > "1" Then
' response.write ("<option value=''>-- SELECT--</option>")
' Else
If ObjRSMgrDesign.eof <> True Then
While Not ObjRSMgrDesign.EOF
response.write ("<option value='" & ObjRSMgrDesign("User_ID") & "'")
if draw_app = ObjRSMgrDesign("Name") then
response.write (" selected")
end if
response.write (">" & ObjRSMgrDesign("Name") & " " & ObjRSMgrDesign("Surname") & " </option>")
ObjRSMgrDesign.MoveNext
Wend
End If
ObjRSMgrDesign.Close
Set ObjRSMgrDesign = Nothing
' End if
%>
</select>
</td>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<table align=center border="1" width="95%" cellpadding="0" cellspacing="0" >
<tr >
<td>
<table width="100%" border="1" align="center" cellspacing="0" bordercolor="#FFFFFF" >
<tr height="25" class="condition">
<th width="1%"><div align="center"></div></th>
<th width="10%"><div align="center">Req No.</div></th>
<th width="10%"><div align="center">Type</div></th>
<th width="14%"><div align="center">Draw_No.</div></th>
<th width="12%"><div align="center">Draw_Name</div></th>
<th width="5%"><div align="center">Rev.</div></th>
<th width="5%"><div align="center">Ven_Code</div></th>
<th width="23%"><div align="center">Ven_Name</div></th>
<th width="10%"><div align="center">Mgr. App.</div></th>
<th width="10%"><div align="center">Buyer</div></th>
</tr>
<%
'if isArray(myArray) then
'If objAdoDisList.eof <> True Then
' objAdoDisList.movefirst
If ubound(dList_drawno) > 0 then ' orginal criteria is ">0" change to <> "" (updated : 20/01/2012)
' For lCnt = 0 to ubound(dList_drawno)
For lCnt = 0 to ubound(dList_drawno) %>
%>
<tr class="ht">
<td><input type="button" value=" " OnClick="buttonClick_pass(<% = lCnt %>)"></td>
<td align="left"><input type="hidden" Value="<% =dList_drawreq(lCnt)%>" name="List_drawreq"><%=dList_drawreq(lCnt)%> </td>
<td align="left"><input type="hidden" Value="<%=dList_drawtype(lCnt)%>" name="List_drawtype"><%=dList_drawtype(lCnt)%> </td>
<td align="left"><input type="hidden" Value="<%=dList_drawno(lCnt)%>" name="List_drawno"><%=dList_drawno(lCnt)%> </td>
<td align="center"><input type="hidden" Value="<%=dList_drawname(lCnt)%>" name="List_drawname"> <%=dList_drawname(lCnt)%> </td>
<td align="center"><input type="hidden" Value="<%=dList_drawrev(lCnt)%>" name="List_drawrev"> <%=dList_drawrev(lCnt)%> </td>
<td align="left"><input type="hidden" Value="<%=dList_drawvencode(lCnt)%>" name="List_drawvencode"> <%=dList_drawvencode(lCnt)%>
<td align="left"><input type="hidden" Value="<%=dList_drawvenname(lCnt)%>" name="List_drawvenname"> <%=dList_drawvenname(lCnt)%>
<td align="left"><input type="hidden" Value="<%=dList_drawapp(lCnt)%>" name="List_drawapp"> <%=dList_drawapp(lCnt)%>
<td align="left"><input type="hidden" Value="<%=dList_drawbuyer(lCnt)%>" name="List_drawbuyer"> <%=dList_drawbuyer(lCnt)%>
</tr>
<% Next
' Else
' response.write "WELCOME NEW SYSTEM"
End If
'End if
objAdoDisList.close
Set objAdoDisList = nothing
%>
</table>
</td>
</tr>
</table>
<!-- ####Send Hidden form to file "Updateinputdrawing.asp #### -->
<input type="hidden" name="Send_drawno" Value="" >
<input type="hidden" name="Send_drawname" Value="" >
<input type="hidden" name="Send_drawrevision" Value="" >
<input type="hidden" name="Send_drawvencode" Value="" >
<input type="hidden" name="Send_drawvenname" Value="" >
<input type="hidden" name="Send_drawbuyer" Value="" >
<input type="hidden" name="Send_drawtype" Value="" >
<input type="hidden" name="Send_drawapp" Value="" >
<input type="hidden" name="Send_Data_Flag" Value="" >
<input type="hidden" name="Send_DrawrequestID" Value="" >
</form>
</body>
</html>
<script language='JavaScript' >
//**********************************//
//* [Pass]Button click *//
//* List >>> Input Form *//
//**********************************//
function buttonClick_pass(Idx) {
frm = document.forms[0];
if (frm.List_drawreq.length){
//array
frm.draw_RequestID.value = frm.List_drawreq[Idx].value;
frm.draw_no.value = frm.List_drawno[Idx].value;
frm.draw_name.value = frm.List_drawname[Idx].value;
frm.draw_revision.value = frm.List_drawrev[Idx].value;
frm.draw_vencode.value = frm.List_drawvencode[Idx].value;
frm.draw_venname.value = frm.List_drawvenname[Idx].value;
frm.draw_buyer.value = frm.List_drawbuyer[Idx].value;
frm.draw_type.value = frm.List_drawtype[Idx].value;
frm.draw_app.value = frm.List_drawapp[Idx].value;
} else {
//not array
frm.draw_RequestID.value = frm.List_drawreq.value;
frm.draw_no.value = frm.List_drawno.value;
frm.draw_name.value = frm.List_drawname.value;
frm.draw_revision.value = frm.List_drawrev.value;
frm.draw_vencode.value = frm.List_drawvencode.value;
frm.draw_venname.value = frm.List_drawvenname.value;
frm.draw_buyer.value = frm.List_drawbuyer.value;
frm.draw_type.value = frm.List_drawtype.value;
frm.draw_app.value = frm.List_drawapp.value;
}
}
//***************************************//
function Check_drawno() {
frm = document.forms[0];
if(frm.draw_no.value != "") {
window.alert("Search detail before!!");
frm.draw_no.focus();
return;
}
}
//***************************************//
//* [Input/Update],[Delete]Button click *//
//* Idx = 1:[Input/Update] *//
//* Idx = 2:[Delete] *//
//***************************************//
function buttonClick_Input(Idx) {
frm = document.forms[0];
flag = "false";
msg = ""
// alert("flag"+flag);
if(frm.draw_no.value == "") {
window.alert("Please input [Drawing No.]");
frm.draw_no.focus();
return;
}
if(frm.draw_name.value == "") {
window.alert("Please input [Drawing Name]");
frm.draw_name.focus();
return;
}
if(frm.draw_revision.value == "") {
window.alert("Please input [Drawing Revision]");
frm.draw_revision.focus();
return;
}
if(frm.draw_vencode.value == "") {
window.alert("Please input [Vendor Code]");
frm.draw_vencode.focus();
return;
}
if(frm.draw_venname.value == "") {
window.alert("Please input [Vendor Name]");
frm.draw_venname.focus();
return;
}
if(frm.draw_buyer.value.length == "") {
window.alert("Please input [Buyer Code]");
frm.draw_buyer.focus();
return;
}
if(frm.draw_type.value.length == "") {
window.alert("Please input [Drawing Type]");
frm.draw_type.focus();
return;
}
if(frm.draw_app.value.length == "") {
window.alert("Please Select [Manager 's name for approve].");
frm.draw_app.focus();
return;
}
// ***** [Request_ID] Repetition Check *****
if (frm.List_drawreq.length){
for (cnt = 0 ; cnt <= frm.List_drawreq.length - 1 ; cnt++ ) {
if (frm.draw_RequestID.value == frm.List_drawreq[cnt].value) {
flag = "true";
}
}
} else {
if (frm.draw_RequestID.value == frm.List_drawreq.value) {
flag = "true";
}
}
//***** Output Message *****
if (Idx == 1) { //+++++++++ Insert & Update +++++++++
if (flag == "false") {
msg = "This data input.";
frm.Send_Data_Flag.value = "Input";
} else {
msg = "This data update.";
frm.Send_Data_Flag.value = "Update";
// alert("This data is nothing.");
}
// alert("flag"+flag);
} else { //+++++++++ Delete +++++++++
if (flag == "false") {
alert("This data is nothing.");
return;
} else {
msg = "This data delete.";
frm.Send_Data_Flag.value = "Delete";
}
}
retflag = confirm(msg);
if (retflag != true){
return;
}
//***** Send Value setting for input DATA*****
frm.Send_DrawrequestID.value = frm.draw_RequestID.value;
frm.Send_drawno.value = frm.draw_no.value;
frm.Send_drawname.value = frm.draw_name.value;
frm.Send_drawrevision.value = frm.draw_revision.value;
frm.Send_drawvencode.value = frm.draw_vencode.value;
frm.Send_drawvenname.value = frm.draw_venname.value;
frm.Send_drawbuyer.value = frm.draw_buyer.value;
frm.Send_drawtype.value = frm.draw_type.value;
frm.Send_drawapp.value = frm.draw_app.value;
//***** Link Setting *****
frm.action = "./Updatedrawing.asp";
frm.method = "POST";
frm.target = "_self";
//***** Link *****
window.frm.submit();
}
//-->
///////////////////////////////// Open Windows //////////////////////////////////
var win = null;
function WinOpenSel(w,h,scroll,draw_no,fileName){
formName = document.forms[0].name
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(fileName+"?draw_no="+draw_no+"&formName_s="+formName,"FG",settings);
}
//-->
</script>
มันมีปัญหาในส่วนของการใช้ Ubound น่ะค่ะ มีวิธีเช็คยังไงได้บ้างคะที่จะใช้กับเคสที่เราล้างข้อมูลใน DB ออกหมด
เพื่อจะเริ่มใหม่ ไม่ให้ระบบ Error มาว่า Subscript out of range: 'ubound' แต่ถ้ามีข้อมูลใน DB อยู่ ก็ใช้งานได้ปกติ
แต่มันไม่ตอบโจทย์ในกรณีที่ขึ้นระบบใช้งานใหม่ค่ะTag : ASP, Ms SQL Server 2005, HTML/CSS, JavaScript, VBScript
Date :
2012-02-07 09:03:31
By :
ลักษณ์
View :
4046
Reply :
4
เอาเฉพาะส่วนที่เป็น ubound แล้วมัน Error มาดูหน่อยครับ ที่ให้มา code เยอะดูไม่เข้าใจ
Date :
2012-02-07 19:08:51
By :
Thep
Code (ASP)
If ubound(dList_drawno) > 0 then ' orginal criteria is ">0" change to <> "" (updated : 20/01/2012)
For lCnt = 0 to ubound(dList_drawno) %>
<tr class="ht">
<td><input type="button" value=" " OnClick="buttonClick_pass(<% = lCnt %>)"></td>
<td align="center"><input type="hidden" Value="<% =dList_drawreq(lCnt)%>" name="List_drawreq"><%=dList_drawreq(lCnt)%> </td>
<td align="center"><input type="hidden" Value="<%=dList_drawtype(lCnt)%>" name="List_drawtype"><%=sel_TypeDraw(dList_drawtype(lCnt))%> </td>
<td align="left"><input type="hidden" Value="<%=dList_drawno(lCnt)%>" name="List_drawno"><%=dList_drawno(lCnt)%> </td>
<td align="center"><input type="hidden" Value="<%=dList_drawname(lCnt)%>" name="List_drawname"> <%=dList_drawname(lCnt)%> </td>
<td align="center"><input type="hidden" Value="<%=dList_drawrev(lCnt)%>" name="List_drawrev"> <%=dList_drawrev(lCnt)%> </td>
<td align="center"><input type="hidden" Value="<%=dList_drawvencode(lCnt)%>" name="List_drawvencode"> <%=dList_drawvencode(lCnt)%>
<td align="left"><input type="hidden" Value="<%=dList_drawvenname(lCnt)%>" name="List_drawvenname"> <%=dList_drawvenname(lCnt)%>
<td align="center"><input type="hidden" Value="<%=dList_drawapp(lCnt)%>" name="List_drawapp"> <%=dList_drawapp(lCnt)%>
<td align="center"><input type="hidden" Value="<%=dList_drawbuyer(lCnt)%>" name="List_drawbuyer"> <%=dList_drawbuyer(lCnt)%>
</tr>
<% Next
End If
ตามโค้ดด้านบนคือบล๊อก Error ของ Ubound ได้แล้วค่ะ แต่คราวนี้โค้ดนี้มันต้องส่งค่าบางตัวเป็น Jscript เพื่อเช็คอัพเดทข้อมูล
// ***** [Request_ID] Repetition Check *****
if (frm.List_drawreq.length){
for (cnt = 0 ; cnt <= frm.List_drawreq.length - 1 ; cnt++ ) {
if (frm.draw_RequestID.value == frm.List_drawreq[cnt].value) {
flag = "true";
}
}
} else {
if (frm.draw_RequestID.value == frm.List_drawreq.value) {
flag = "true";
}
}
//***** Output Message *****
if (Idx == 1) { //+++++++++ Insert & Update +++++++++
if (flag == "false") {
msg = "This data input.";
frm.Send_Data_Flag.value = "Input";
} else {
msg = "This data update.";
frm.Send_Data_Flag.value = "Update";
}
} else { //+++++++++ Delete +++++++++
if (flag == "false") {
alert("This data is nothing.");
return;
} else {
msg = "This data delete.";
frm.Send_Data_Flag.value = "Delete";
}
}
retflag = confirm(msg);
if (retflag != true){
return;
}
ซึ่งมันก็จะ Error เรื่อง Null เหมือนเดิมค่ะ ตอนนี้กำลังหาวิธีเช็คให้ Jscript ตัวนี้ไม่ให้มัน Error อยู่ค่ะ
Date :
2012-02-16 10:35:48
By :
Newjam001
Load balance : Server 02