Solved

VB:Error While running application (The Object variable or with  Block Varaible not set)

Posted on 2004-04-28
5
476 Views
Last Modified: 2008-02-01
Can you please help me resolve this issue.
I have online form, which inserts data to SQL server databse through ASP, VB, VB to SQL Server.
When I want to insert 2 rrecords, it is inserting only 1st record in the database.
The ASP page code below
'--------------------------------
<%@ Language=VBScript %>
<!--#include file="resources\incConstants.asp"-->
<%

'Function / Sub Variables
Dim objCon            'Used for database connection
Dim sTempStr      'Temporary variable to hold the date values
Dim sTmpStr            'Temporary variable to hold the date values
Dim iTempVal      'Temporary variable to hold the date values
Dim iTmpVal            'Temporary variable to hold the date values

'Page Variables
Dim sForm(2)      'Variable to hold the form values
Dim sData(9,1)      'Variable to hold the Meter data values
Dim sErrMsg            'Variable to hold the error messages
Dim sQuery            'Variable to hold the query value
Dim iLp                  'Variable for looping the Meter Info
Dim iLoop            'Variable for looping the Meter Info
Dim bIsMeter      'Variable to check the flag for MeterInfo
Dim sRegions      'Variable to get the region info
Dim rsRegions      'Variable to loop the regions
Dim sEmployeeID                  'Variable used to hold the employeeId of the Employee
Dim sMeterDate                  'Variable used to hold the MeterDate for the Meter
Dim sRegion                        'Variable used to hold the region for the Meter
Dim sMeterSerialNo            'Variable used to hold the Meter SerialNo for the Meter
Dim nAutoID                        'Variable used to hold the AutoID
Dim sStatus                        'Variable used to hold the status IN/OUT for the Meter
Dim sReg(1)                        'Variable to hold the region value

'****************************************************
' Create/Format Input Dictionary to PageController  *
'****************************************************
Set oInputDict = Server.CreateObject("Scripting.Dictionary")
Set oInputDict = InitializeInput(cgFORMAT_AS_DICTIONARY, cgFORMAT_AS_DICTIONARY)
       
'**********************************************************      
' Create/Format Output Dictionary from PageController     *
'**********************************************************
Set oOutPutDict = Server.CreateObject("Scripting.Dictionary")
 
'Load IN/OUT Deafult
For iLp = 0 to 9
      sData(iLp,1) = "OUT"
Next

sReg(0) = "Bellwood"
sReg(1) = "Glen Ellyn"


'Get Passed Back Form Data After INSERT
If CBool(Request.QueryString("pass")) = True then
      sForm(0) = Request.QueryString("empid")
      sForm(1) = Request.QueryString("date")
      sForm(2) = Request.QueryString("reg")
End If

'Form Has Been Submitted
If Request.Form("Action") = "Add" then
      sErrMsg = ""

            'Collect Up The General Info
            For iLp = 0 to 2
                  sForm(iLp) = Trim(Request.Form("f_"&iLp))
            Next

            'Collect Up The Meter Info
            For iLp = 0 to 9
                  For iLoop = 0 to 1
                        sData(iLp,iLoop) = Trim(Request.Form("m_"&iLoop&"_"&iLp))
                  Next
            Next

      'Validation of form with proper values
      If sErrMsg = "" then
            'validation for Employee ID
            If (sForm(0) = "") or (sForm(0) = "99999") or not (IsNumeric(sForm(0)))or (Len(sForm(0)) <> 5) then
                        If sForm(0) = "" then
                              sErrMsg = "Error: Employee ID - Required field."
                        Elseif sForm(0) = "99999" or not IsNumeric(sForm(0))or (Len(sForm(0)) <> 5) then
                        sErrMsg = "Error: Employee ID - Invalid Value."
                        End If
                  Else
            
                        'validation for Date
                        If sForm(1) = "" then
                              sErrMsg = "Error: Date - Required Field."
                        Else
                              sForm(1) = PadDate(sForm(1))
                              If ValidateDate(sForm(1),sErrMsg) = True then
                                    sForm(1) = sErrMsg
                                    sErrMsg = ""
            
                                    'validation for Region
                                    If sForm(2) = "" then
                                          sErrMsg = "Error: Region - Required Field."
                                    Else
                                    sForm(2) = SetCap(sForm(2))

                                    'validation for Meter Info
                                    bIsMeter = False
                                    'If meter details yes, check for valid Meter info
                                    For iLp = 0 to 9
                                         If sData(iLp,0) <> "" then
                                              If Left(sData(iLp,0),1) = "7" then
                                                   sErrMsg = "Error: Meter No (" & sData(iLp,0) & ") - Can't Start With 7."
                                              Else
                                                   If Len(sData(iLp,0)) <> 7 then
                                                        sErrMsg = "Error: Meter No (" & sData(iLp,0) & ") - Wrong Length."
                                                   Else
                                                        bIsMeter = True
                                                   End If
                                              End If
                                                                       
                                              If sErrMsg <> "" then
                                                   iLp = 9
                                              End If
                                         End If
                                    Next

                                          'Checking for Meter Details
                                          If sErrMsg = "" then
                                          'All Ok - INSERT Details into DB
                                                If bIsMeter = False then
                                                      sErrMsg = "Error: Meter No Details - Required."
                                                Else
                                                      If sErrMsg = "" then
                                                            For iLp = 0 to 9
                                                                  If sData(iLp,0) <> "" then
                                                                        sEmployeeID = SQL(sForm(0))
                                                                        sMeterDate = sForm(1)
                                                                        sRegion = SQL(sForm(2))
                                                                        sMeterSerialNo = SQL(sData(iLp,0))
                                                                        sStatus = sData(iLp,1)
                                                                        'Add the values to input dictionary
                                                                        oInputDict.Add "sEmployeeID", sEmployeeID
                                                                        oInputDict.Add "sMeterDate", sMeterDate
                                                                        oInputDict.Add "sRegion", sRegion
                                                                        oInputDict.Add "sMeterSerialNo", sMeterSerialNo
                                                                        oInputDict.Add "sStatus", sStatus
                                                                        '**********************************************************
                                                                        'Call the Page controller.
                                                                        '**********************************************************
                                                                        Set oPC = Server.CreateObject ("CmpMTCTRL.CMTCTRL")
                                                                        lPCResponseCode = oPC.ProcessPage(oInputDict, oOutputDict, sRedirectURL)
                                                                  End If
                                                            Next
                                                            Response.Redirect "MeterTracking.asp?pass=True&empid=" & sForm(0) & "&date=" & sForm(1) & "&reg=" & sForm(2)
                                                      End If
                                                End If
                                          End If
                                    End If
                              End If
                        End If
            End If
      End If
End If

CloseDB
%>
<html>
      <head>
            <title>Meter Information</title>
      </head>
<body>
      <table width="500" cellspacing="1" cellpadding="0" border="0" bgcolor="#000000" align=center>
            <form name="Reading" method="post" action="MeterTracking.asp">
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td height="30"><b>M E T E R&nbsp;&nbsp;&nbsp;I N F O R M A T I O N</b></td>
                                    </tr>
                              </table>
                  <td>
                  </tr>
                  <%If sErrMsg <> "" then%>
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td height="30"><font color="#FF0000"><%=sErrMsg%></font>
                                          </td>
                                    </tr>
                              </table>
                        </td>
                  </tr>
                  <%End If%>
                  <%If CBool(Request.QueryString("pass")) = True then%>
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td height="30">Notice: Info Successfully inserted into DB.
                                          </td>
                                    </tr>
                              </table>
                        </td>
                  </tr>
                  <%End If%>
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td colspan="2" height="30"><b>General Details:</b></td>
                                    </tr>
                                    <tr>
                                          <td width="100" height="25">*Employee ID:
                                          </td>
                                          <td width="400">
                                                <input type="text" name="f_0" size="5" maxlength="5" value="<%=sForm(0)%>">
                                          </td>
                                    </tr>
                                    <tr>
                                          <td height="25">*Date:
                                          </td>
                                          <td>
                                                <input type="text" name="f_1" size="10" maxlength="10" value="<%=sForm(1)%>">(Ex-01/01/2004)
                                          </td>
                                    </tr>
                                    <tr>
                                          <td height="25">*Region:
                                          </td>
                                          <td>
                                                <select name="f_2">
                                                      <%If sForm(2) = "" then%>
                                                            <option value="">Please select</option>
                                                      <%End If
                                                      For iLp = 0 to UBound(sReg)
                                                            If sForm(2) = sReg(iLp) then%>
                                                                  <option value="<%=sReg(iLp)%>" selected><%=sReg(iLp)%></option>
                                                            <%Else%>
                                                                  <option value="<%=sReg(iLp)%>"><%=sReg(iLp)%></option>
                                                            <%End If
                                                    Next%>
                                                </select>
                                          </td>
                                    </tr>
                              </table>
                        </td>
                  </tr>
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td colspan="4" height="30"><b>Meter Numbers:</b>
                                          </td>
                                    </tr>
                                    <%For iLp = 0 to 9%>
                                    <tr>
                                          <td width="100" height="25">Meter No:
                                          </td>
                                          <td width="125">
                                                <input type="text" name="m_0_<%=iLp%>" size="6" maxlength="7" value="<%=sData(iLp,0)%>"">(7 Digits)
                                          </td>
                                          <td width="50">Status:
                                          </td>
                                          <td width="225">
                                                <input type="radio" name="m_1_<%=iLp%>" value="OUT" <%If sData(iLp,1) = "OUT" then%>checked<%End If%>>&nbsp;OUT&nbsp;&nbsp;
                                                <input type="radio" name="m_1_<%=iLp%>" value="IN" <%If sData(iLp,1) = "IN" then%>checked<%End If%>>&nbsp;IN
                                          </td>
                                    </tr>
                                    <%Next%>
                              </table>
                        </td>
                  </tr>
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td height="30" align="center">
                                                <input type="hidden" name="Action" value="Add">
                                                <input type="submit" name="Button" value="Submit">
                                                <input id=reset name=reset type=reset value=Reset></TD>
                                          </td>
                                    </tr>
                              </table>
                        </td>
                  </tr>
            </form>
      </table>
</body>
</html>
<%
'Function for Date value
Function PadDate(Value)
If Len(Value) = 0 then
      PadDate = Value
Else
      If IsDate(Value) then
            sTmpStr = ""
            sTempStr = ""
            iTempVal = 0
            For iLp = 1 to Len(Value)
                  If IsNumeric(Mid(Value,iLp,1)) then
                        sTempStr = sTempStr & Mid(Value,iLp,1)
                  Else
                  If Len(sTempStr) > 2 then
                        PadDate = Value
                  Else
                        sTempStr = Left("00",2-Len(sTempStr)) & sTempStr & "/"
                        sTmpStr = sTmpStr & sTempStr
                        sTempStr = ""
                  End If
                  End If
            Next
                  If Len(sTempStr) > 4 then
                        PadDate = Value
                  Else
                        PadDate = sTmpStr & Left("2000",4-Len(sTempStr)) & sTempStr
                  End If
      Else
            PadDate = Value
      End If
End If
End Function

'Function for validating Date value entered by user
Function ValidateDate(Value, sErrMsg)
If Len(Value) <> 10 then
      ValidateDate = False
      sErrMsg = "Error: Date - Invalid."
Else
      If IsNumeric(Mid(Value,1,2)) and IsNumeric(Mid(Value,4,2)) and IsNumeric(Mid(Value,7,4)) then
            Value = Mid(Value,1,2) & "/" & Mid(Value,4,2) & "/" & Mid(Value,7,4)
            If IsDate(Value) then
                  ValidateDate = True
                  sErrMsg = Value
            Else
                  ValidateDate = False
                  sErrMsg = "Error: Date - Invalid."
            End If
      Else
            ValidateDate = False
            sErrMsg = "Error: Date - Invalid."
      End If
End If
End Function

'Function to replace quotes
Function SQL(Value)
SQL = Replace(Value,"'","''")
End Function

'Function used for capitilizing the values
Function SetCap(Value)
If Value <> "" Then
      sTempStr = ""
      sTempStr = sTempStr & UCase(Mid(Value, 1, 1))
      For iTempval = 2 To Len(Value)
            If Mid(Value, iTempval-1, 1) = " " Then
                  sTempStr = sTempStr & UCase(Mid(Value, iTempval, 1))
            Else
            sTempStr = sTempStr + Mid(Value, iTempval, 1)
            End If
      Next
      SetCap = sTempStr
End If
End Function

%>

And I have VB page COde
'------------------------------------------------------------------
Private Function ExecutePage(oInputDict As Scripting.Dictionary, oOutputDict As Scripting.Dictionary, sRedirectURL As String) As Long
Const cMETHOD_NAME As String = "ExecutePage"
   
' Start custom implementation code for declarations
    Dim sEmployeeID As String       'Variable used to hold the employeeId of the Employee
    Dim sMeterDate As String        'Variable used to hold the MeterDate for the Meter
    Dim sRegion As String    'Variable used to hold the region for the Meter
    Dim sMeterSerialNo As String    'Variable used to hold the Meter SerialNo for the Meter
    Dim nAutoID As Integer        'Variable used to hold the AutoID
    Dim sStatus As String   'Variable used to hold the status IN/OUT for the Meter
    Dim avRegions          'Array of regions to get records from database
    Dim objGetRegionsBO As CmpServerInterfaceMT.IMT    'Create objGetRegionsBO instance
    Dim objInsertMTBO As CmpServerInterfaceMT.IMT  'Create objInsertMTBO instance
   
   
    'Instantiate the CMTBO object
    Set objInsertMTBO = CreateObject("CmpMTBO.CMTBO")
    'Set objGetRegionsBO = CreateObject("CmpMTBO.CMTBO")
' End custom implementation code for declarations

' Start custom code
    'Add avRegions to Output Dictionary
    'oOutputDict.Add "avRegions", objGetRegionsBO.GetRegions()
 
    ' Add values to the Input Dictionary

    'If the data entered by the user is valid then get the values from the input dictionary
   
        ' Add values to the input dictionary
        sEmployeeID = Trim(CStr(oInputDict.Item("sEmployeeID")))
        sMeterDate = Trim(CStr(oInputDict.Item("sMeterDate")))
        sRegion = Trim(CStr(oInputDict.Item("sRegion")))
        'nAssocID = oInputDict.Item("nAssocID")
        sMeterSerialNo = oInputDict.Item("sMeterSerialNo")
        sStatus = oInputDict.Item("sStatus")
 
        'call the function to add the information to the database.
 
            Call objInsertMTBO.InsertMeterInfo(sEmployeeID, sMeterDate, sRegion, sMeterSerialNo, sStatus)
                           
 ' End custom code
   
On Error GoTo ErrorHandler
   
ErrorHandler:

' Start cleanup of custom implementation's objects
    'Clean up memory by destroying the Instantiated object
    objInsertMTBO = Nothing
' End cleanup of custom implementation's objects
If Err.Number <> 0 Then
        HandleError ArchitectureError, cmCLASS_NAME, cMETHOD_NAME
    End If
End Function
'------------------------------------------------------------------------------
One more VB code
'--------------------------------------------------------------------------
Private Function InsertMeterInfo(ByVal sEmployeeID As String, _
                         ByVal sMeterDate As String, _
                         ByVal sRegion As String, _
                         ByVal sMeterSerialNo As String, _
                         ByVal sStatus As String) As Variant


    Const cSPInsert_MeterInfo As String = "ProcGasMeterInfo"    'Dim Variable to Store Stored procedure Name
    Const c_sParameterName As String = "InsertMeterInfo"              'Dim Variable to Store the Method Name
   
    Dim objDatabaseSvc As ACAIC.IDatabaseSvc        'Dim Variable to implement ACA database services
    Dim sConnectionString As String                 'Dim Variable to Store Connection String
    Dim avInputParam As Variant                     'Dim Variable to Store input Parameters for Stored Procedure
   
    On Error GoTo ErrorHandler

    'Instantiates the Data Base Factory Object
    Set objDatabaseSvc = DBSvcFactory(cmClassName)
   
    'Get connection string for the CMTBO from ACAConfig.xml
    sConnectionString = GetConnectionString(cmClassName)
   
    'Get the input parameter list and create parameter array
    avInputParam = Array(MakeParameter("sEmployeeID", adodb.adChar, sEmployeeID), _
                    MakeParameter("sMeterDate", adodb.adChar, sMeterDate), _
                    MakeParameter("sRegion", adodb.adChar, sRegion), _
                    MakeParameter("sMeterSerialNo", adodb.adChar, sMeterSerialNo), _
                    MakeParameter("sStatus", adodb.adChar, sStatus))

     'Calls the Stored Procedure 'ProcGasMeterInfo'
      Call objDatabaseSvc.RunSP(cSPInsert_MeterInfo, avInputParam, sConnectionString)
     
ErrorHandler:
    'Removes the objects from memory
    Set objDatabaseSvc = Nothing
    'Handle possible errors
    If Err.Number <> 0 Then
        HandleError ApplicationError, cmClassName, c_sParameterName
    End If
End Function
'------------------------------------------------------------------------------------

Can you guys help me resolve this issue.
I can explain indetail , if you guys need it

Thanks
Mike


0
Comment
Question by:MikeHall12
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:chisholmd
Comment Utility
Hmm there's allot of code there :)

correct me if I am wrong but in your asp you reference a method called oPC.ProcessPage

but in the VB code there is only "executePage"

Is that just a typo in this supplied example or are you troubleshooting the wrong VB code ?

Sure looks like the long way around of doing things but it mostly looks right, you are looping through up to 9 times, each time instantiating your object, calling the process/execute page passing in new values each time, and that function is calling a stored procedure to perform your insert each time.

On the surface I can't see why it is giving up after the first insert unless your data is not matching the conditional in your loop and inserting only one matching record.

As a point of performance, I don't think you should be creating your object within a loop. It chews up resources very fast. You might want to re-write your VB class so that it has a property for each field and a method that does the insert then you can just do this:

create class
for loop = 0 to 9
    class.FieldProperty1 = "value"
    class.FieldProperty1 = "value"
    class.FieldProperty2 = "value"
    class.insertMethod
next
set class= nothing

This would save you from using those dictionary objects as well that I don't think are very resource friendly.  Might be easier to debug as well. Although I suppose your constrained to using classes already defined by others within your organization.

Sorry I guess this isn't very helpfull

if I were in your shoes I'd be wlaking through one step at a time. How many times is my loop running? What are the values each time, how many match the if condition within the loop?  I'd have my vb code write debug info out to a text file error log so that I could see what was happening with each interation. Timeconsuming brute force debugging :)

dave










0
 

Author Comment

by:MikeHall12
Comment Utility
Thanks For your suggestion.

Here is my code, with layers
 ASP Code
<%@ Language=VBScript %>
<!--#include file="resources\incConstants.asp"-->
<%

'Function / Sub Variables
Dim objCon          'Used for database connection
Dim sTempStr     'Temporary variable to hold the date values
Dim sTmpStr          'Temporary variable to hold the date values
Dim iTempVal     'Temporary variable to hold the date values
Dim iTmpVal          'Temporary variable to hold the date values

'Page Variables
Dim sForm(2)     'Variable to hold the form values
Dim sData(9,1)     'Variable to hold the Meter data values
Dim sErrMsg          'Variable to hold the error messages
Dim sQuery          'Variable to hold the query value
Dim iLp               'Variable for looping the Meter Info
Dim iLoop          'Variable for looping the Meter Info
Dim bIsMeter     'Variable to check the flag for MeterInfo
Dim sRegions     'Variable to get the region info
Dim rsRegions     'Variable to loop the regions
Dim sEmployeeID               'Variable used to hold the employeeId of the Employee
Dim sMeterDate               'Variable used to hold the MeterDate for the Meter
Dim sRegion                    'Variable used to hold the region for the Meter
Dim sMeterSerialNo          'Variable used to hold the Meter SerialNo for the Meter
Dim nAutoID                    'Variable used to hold the AutoID
Dim sStatus                    'Variable used to hold the status IN/OUT for the Meter
Dim sReg(1)                    'Variable to hold the region value

'****************************************************
' Create/Format Input Dictionary to PageController  *
'****************************************************
Set oInputDict = Server.CreateObject("Scripting.Dictionary")
Set oInputDict = InitializeInput(cgFORMAT_AS_DICTIONARY, cgFORMAT_AS_DICTIONARY)
       
'**********************************************************    
' Create/Format Output Dictionary from PageController     *
'**********************************************************
Set oOutPutDict = Server.CreateObject("Scripting.Dictionary")
 
'Load IN/OUT Deafult
For iLp = 0 to 9
     sData(iLp,1) = "OUT"
Next

sReg(0) = "Bellwood"
sReg(1) = "Glen Ellyn"


'Get Passed Back Form Data After INSERT
If CBool(Request.QueryString("pass")) = True then
     sForm(0) = Request.QueryString("empid")
     sForm(1) = Request.QueryString("date")
     sForm(2) = Request.QueryString("reg")
End If

'Form Has Been Submitted
If Request.Form("Action") = "Add" then
     sErrMsg = ""

          'Collect Up The General Info
          For iLp = 0 to 2
               sForm(iLp) = Trim(Request.Form("f_"&iLp))
          Next

          'Collect Up The Meter Info
          For iLp = 0 to 9
               For iLoop = 0 to 1
                    sData(iLp,iLoop) = Trim(Request.Form("m_"&iLoop&"_"&iLp))
               Next
          Next

     'Validation of form with proper values
     If sErrMsg = "" then
          'validation for Employee ID
          If (sForm(0) = "") or (sForm(0) = "99999") or not (IsNumeric(sForm(0)))or (Len(sForm(0)) <> 5) then
                    If sForm(0) = "" then
                         sErrMsg = "Error: Employee ID - Required field."
                    Elseif sForm(0) = "99999" or not IsNumeric(sForm(0))or (Len(sForm(0)) <> 5) then
                    sErrMsg = "Error: Employee ID - Invalid Value."
                    End If
               Else
         
                    'validation for Date
                    If sForm(1) = "" then
                         sErrMsg = "Error: Date - Required Field."
                    Else
                         sForm(1) = PadDate(sForm(1))
                         If ValidateDate(sForm(1),sErrMsg) = True then
                              sForm(1) = sErrMsg
                              sErrMsg = ""
         
                              'validation for Region
                              If sForm(2) = "" then
                                   sErrMsg = "Error: Region - Required Field."
                              Else
                              sForm(2) = SetCap(sForm(2))

                              'validation for Meter Info
                              bIsMeter = False
                              'If meter details yes, check for valid Meter info
                              For iLp = 0 to 9
                                   If sData(iLp,0) <> "" then
                                        If Left(sData(iLp,0),1) = "7" then
                                             sErrMsg = "Error: Meter No (" & sData(iLp,0) & ") - Can't Start With 7."
                                        Else
                                             If Len(sData(iLp,0)) <> 7 then
                                                  sErrMsg = "Error: Meter No (" & sData(iLp,0) & ") - Wrong Length."
                                             Else
                                                  bIsMeter = True
                                             End If
                                        End If
                                                                 
                                        If sErrMsg <> "" then
                                             iLp = 9
                                        End If
                                   End If
                              Next

                                   'Checking for Meter Details
                                   If sErrMsg = "" then
                                   'All Ok - INSERT Details into DB
                                        If bIsMeter = False then
                                             sErrMsg = "Error: Meter No Details - Required."
                                        Else
                                             If sErrMsg = "" then
                                                  For iLp = 0 to 9
                                                       If sData(iLp,0) <> "" then
                                                            sEmployeeID = SQL(sForm(0))
                                                            sMeterDate = sForm(1)
                                                            sRegion = SQL(sForm(2))
                                                            sMeterSerialNo = SQL(sData(iLp,0))
                                                            sStatus = sData(iLp,1)
                                                            'Add the values to input dictionary
                                                            oInputDict.Add "sEmployeeID", sEmployeeID
                                                            oInputDict.Add "sMeterDate", sMeterDate
                                                            oInputDict.Add "sRegion", sRegion
                                                            oInputDict.Add "sMeterSerialNo", sMeterSerialNo
                                                            oInputDict.Add "sStatus", sStatus
                                                            '**********************************************************
                                                            'Call the Page controller.
                                                            '**********************************************************
                                                            Set oPC = Server.CreateObject ("CmpMTCTRL.CMTCTRL")
                                                            lPCResponseCode = oPC.ProcessPage(oInputDict, oOutputDict, sRedirectURL)
                                                       End If
                                                  Next
                                                  Response.Redirect "MeterTracking.asp?pass=True&empid=" & sForm(0) & "&date=" & sForm(1) & "&reg=" & sForm(2)
                                             End If
                                        End If
                                   End If
                              End If
                         End If
                    End If
          End If
     End If
End If

CloseDB
%>
<html>
     <head>
          <title>Meter Information</title>
     </head>
<body>
     <table width="500" cellspacing="1" cellpadding="0" border="0" bgcolor="#000000" align=center>
          <form name="Reading" method="post" action="MeterTracking.asp">
               <tr bgcolor="#FFFFFF">
                    <td>
                         <table width="500" cellspacing="0" cellpadding="2" border="0">
                              <tr>
                                   <td height="30"><b>M E T E R&nbsp;&nbsp;&nbsp;I N F O R M A T I O N</b></td>
                              </tr>
                         </table>
               <td>
               </tr>
               <%If sErrMsg <> "" then%>
               <tr bgcolor="#FFFFFF">
                    <td>
                         <table width="500" cellspacing="0" cellpadding="2" border="0">
                              <tr>
                                   <td height="30"><font color="#FF0000"><%=sErrMsg%></font>
                                   </td>
                              </tr>
                         </table>
                    </td>
               </tr>
               <%End If%>
               <%If CBool(Request.QueryString("pass")) = True then%>
               <tr bgcolor="#FFFFFF">
                    <td>
                         <table width="500" cellspacing="0" cellpadding="2" border="0">
                              <tr>
                                   <td height="30">Notice: Info Successfully inserted into DB.
                                   </td>
                              </tr>
                         </table>
                    </td>
               </tr>
               <%End If%>
               <tr bgcolor="#FFFFFF">
                    <td>
                         <table width="500" cellspacing="0" cellpadding="2" border="0">
                              <tr>
                                   <td colspan="2" height="30"><b>General Details:</b></td>
                              </tr>
                              <tr>
                                   <td width="100" height="25">*Employee ID:
                                   </td>
                                   <td width="400">
                                        <input type="text" name="f_0" size="5" maxlength="5" value="<%=sForm(0)%>">
                                   </td>
                              </tr>
                              <tr>
                                   <td height="25">*Date:
                                   </td>
                                   <td>
                                        <input type="text" name="f_1" size="10" maxlength="10" value="<%=sForm(1)%>">(Ex-01/01/2004)
                                   </td>
                              </tr>
                              <tr>
                                   <td height="25">*Region:
                                   </td>
                                   <td>
                                        <select name="f_2">
                                             <%If sForm(2) = "" then%>
                                                  <option value="">Please select</option>
                                             <%End If
                                             For iLp = 0 to UBound(sReg)
                                                  If sForm(2) = sReg(iLp) then%>
                                                       <option value="<%=sReg(iLp)%>" selected><%=sReg(iLp)%></option>
                                                  <%Else%>
                                                       <option value="<%=sReg(iLp)%>"><%=sReg(iLp)%></option>
                                                  <%End If
                                            Next%>
                                        </select>
                                   </td>
                              </tr>
                         </table>
                    </td>
               </tr>
               <tr bgcolor="#FFFFFF">
                    <td>
                         <table width="500" cellspacing="0" cellpadding="2" border="0">
                              <tr>
                                   <td colspan="4" height="30"><b>Meter Numbers:</b>
                                   </td>
                              </tr>
                              <%For iLp = 0 to 9%>
                              <tr>
                                   <td width="100" height="25">Meter No:
                                   </td>
                                   <td width="125">
                                        <input type="text" name="m_0_<%=iLp%>" size="6" maxlength="7" value="<%=sData(iLp,0)%>"">(7 Digits)
                                   </td>
                                   <td width="50">Status:
                                   </td>
                                   <td width="225">
                                        <input type="radio" name="m_1_<%=iLp%>" value="OUT" <%If sData(iLp,1) = "OUT" then%>checked<%End If%>>&nbsp;OUT&nbsp;&nbsp;
                                        <input type="radio" name="m_1_<%=iLp%>" value="IN" <%If sData(iLp,1) = "IN" then%>checked<%End If%>>&nbsp;IN
                                   </td>
                              </tr>
                              <%Next%>
                         </table>
                    </td>
               </tr>
               <tr bgcolor="#FFFFFF">
                    <td>
                         <table width="500" cellspacing="0" cellpadding="2" border="0">
                              <tr>
                                   <td height="30" align="center">
                                        <input type="hidden" name="Action" value="Add">
                                        <input type="submit" name="Button" value="Submit">
                                        <input id=reset name=reset type=reset value=Reset></TD>
                                   </td>
                              </tr>
                         </table>
                    </td>
               </tr>
          </form>
     </table>
</body>
</html>
<%
'Function for Date value
Function PadDate(Value)
If Len(Value) = 0 then
     PadDate = Value
Else
     If IsDate(Value) then
          sTmpStr = ""
          sTempStr = ""
          iTempVal = 0
          For iLp = 1 to Len(Value)
               If IsNumeric(Mid(Value,iLp,1)) then
                    sTempStr = sTempStr & Mid(Value,iLp,1)
               Else
               If Len(sTempStr) > 2 then
                    PadDate = Value
               Else
                    sTempStr = Left("00",2-Len(sTempStr)) & sTempStr & "/"
                    sTmpStr = sTmpStr & sTempStr
                    sTempStr = ""
               End If
               End If
          Next
               If Len(sTempStr) > 4 then
                    PadDate = Value
               Else
                    PadDate = sTmpStr & Left("2000",4-Len(sTempStr)) & sTempStr
               End If
     Else
          PadDate = Value
     End If
End If
End Function

'Function for validating Date value entered by user
Function ValidateDate(Value, sErrMsg)
If Len(Value) <> 10 then
     ValidateDate = False
     sErrMsg = "Error: Date - Invalid."
Else
     If IsNumeric(Mid(Value,1,2)) and IsNumeric(Mid(Value,4,2)) and IsNumeric(Mid(Value,7,4)) then
          Value = Mid(Value,1,2) & "/" & Mid(Value,4,2) & "/" & Mid(Value,7,4)
          If IsDate(Value) then
               ValidateDate = True
               sErrMsg = Value
          Else
               ValidateDate = False
               sErrMsg = "Error: Date - Invalid."
          End If
     Else
          ValidateDate = False
          sErrMsg = "Error: Date - Invalid."
     End If
End If
End Function

'Function to replace quotes
Function SQL(Value)
SQL = Replace(Value,"'","''")
End Function

'Function used for capitilizing the values
Function SetCap(Value)
If Value <> "" Then
     sTempStr = ""
     sTempStr = sTempStr & UCase(Mid(Value, 1, 1))
     For iTempval = 2 To Len(Value)
          If Mid(Value, iTempval-1, 1) = " " Then
               sTempStr = sTempStr & UCase(Mid(Value, iTempval, 1))
          Else
          sTempStr = sTempStr + Mid(Value, iTempval, 1)
          End If
     Next
     SetCap = sTempStr
End If
End Function

%>


'------------------------------------------------------------------------------------------------
1stlayer - VB CODe
Private Function ExecutePage(oInputDict As Scripting.Dictionary, oOutputDict As Scripting.Dictionary, sRedirectURL As String) As Long
Const cMETHOD_NAME As String = "ExecutePage"
   
' Start custom implementation code for declarations
    Dim sEmployeeID As String       'Variable used to hold the employeeId of the Employee
    Dim sMeterDate As String        'Variable used to hold the MeterDate for the Meter
    Dim sRegion As String    'Variable used to hold the region for the Meter
    Dim sMeterSerialNo As String    'Variable used to hold the Meter SerialNo for the Meter
    Dim nAutoID As Integer        'Variable used to hold the AutoID
    Dim sStatus As String   'Variable used to hold the status IN/OUT for the Meter
    Dim avRegions          'Array of regions to get records from database
    Dim objGetRegionsBO As CmpServerInterfaceMT.IMT    'Create objGetRegionsBO instance
    Dim objInsertMTBO As CmpServerInterfaceMT.IMT  'Create objInsertMTBO instance
   
   
    'Instantiate the CMTBO object
    Set objInsertMTBO = CreateObject("CmpMTBO.CMTBO")
    'Set objGetRegionsBO = CreateObject("CmpMTBO.CMTBO")
' End custom implementation code for declarations

' Start custom code
    'Add avRegions to Output Dictionary
    'oOutputDict.Add "avRegions", objGetRegionsBO.GetRegions()
 
    ' Add values to the Input Dictionary

    'If the data entered by the user is valid then get the values from the input dictionary
   
        ' Add values to the input dictionary
        sEmployeeID = Trim(CStr(oInputDict.Item("sEmployeeID")))
        sMeterDate = Trim(CStr(oInputDict.Item("sMeterDate")))
        sRegion = Trim(CStr(oInputDict.Item("sRegion")))
        'nAssocID = oInputDict.Item("nAssocID")
        sMeterSerialNo = oInputDict.Item("sMeterSerialNo")
        sStatus = oInputDict.Item("sStatus")
 
        'call the function to add the information to the database.
 
            Call objInsertMTBO.InsertMeterInfo(sEmployeeID, sMeterDate, sRegion, sMeterSerialNo, sStatus)
                           
 ' End custom code
   
On Error GoTo ErrorHandler
   
ErrorHandler:

' Start cleanup of custom implementation's objects
    'Clean up memory by destroying the Instantiated object
    objInsertMTBO = Nothing
' End cleanup of custom implementation's objects
If Err.Number <> 0 Then
        HandleError ArchitectureError, cmCLASS_NAME, cMETHOD_NAME
    End If
End Function
'-----------------------------------------------------------------------------------------------------------------------------------------------------------
2nd LayerVB CODe
Private Function InsertMeterInfo(ByVal sEmployeeID As String, _
                         ByVal sMeterDate As String, _
                         ByVal sRegion As String, _
                         ByVal sMeterSerialNo As String, _
                         ByVal sStatus As String) As Variant


    Const cSPInsert_MeterInfo As String = "ProcGasMeterInfo"    'Dim Variable to Store Stored procedure Name
    Const c_sParameterName As String = "InsertMeterInfo"              'Dim Variable to Store the Method Name
   
    Dim objDatabaseSvc As ACAIC.IDatabaseSvc        'Dim Variable to implement ACA database services
    Dim sConnectionString As String                 'Dim Variable to Store Connection String
    Dim avInputParam As Variant                     'Dim Variable to Store input Parameters for Stored Procedure
   
    On Error GoTo ErrorHandler

    'Instantiates the Data Base Factory Object
    Set objDatabaseSvc = DBSvcFactory(cmClassName)
   
    'Get connection string for the CMTBO from ACAConfig.xml
    sConnectionString = GetConnectionString(cmClassName)
   
    'Get the input parameter list and create parameter array
    avInputParam = Array(MakeParameter("sEmployeeID", adodb.adChar, sEmployeeID), _
                    MakeParameter("sMeterDate", adodb.adChar, sMeterDate), _
                    MakeParameter("sRegion", adodb.adChar, sRegion), _
                    MakeParameter("sMeterSerialNo", adodb.adChar, sMeterSerialNo), _
                    MakeParameter("sStatus", adodb.adChar, sStatus))

     'Calls the Stored Procedure 'ProcGasMeterInfo'
      Call objDatabaseSvc.RunSP(cSPInsert_MeterInfo, avInputParam, sConnectionString)
     
ErrorHandler:
    'Removes the objects from memory
    Set objDatabaseSvc = Nothing
    'Handle possible errors
    If Err.Number <> 0 Then
        HandleError ApplicationError, cmClassName, c_sParameterName
    End If
End Function
'------------------------------------------------------------------------------
3rd layer VB code - With Public Class
'-----------------------------------------------------------------------------------
Public Function InsertMeterInfo(ByVal sEmployeeID As String, _
                         ByVal sMeterDate As String, _
                         ByVal sRegion As String, _
                         ByVal sMeterSerialNo As String, _
                         ByVal sStatus As String) As Variant
End Function
'---------------------------------------------------------------------------------
Stored Procedure
CREATE Procedure procGasMeterInsert

(@sEmployeeID           varchar(20),
@sMeterDate             varchar(30),
@sRegion             varchar(128),
@sMeterSerialNo             varchar(128),
@sStatus                     varchar(20)
    )

As


INSERT INTO GasMeterTrack (EmployeeID, MeterDate, Region, MeterSerialNo, Status) VALUES(
          @sEmployeeID,
                   @sMeterDate,
                    @sRegion,
                   @sMeterSerialNo,
                    @sStatus
                  )
GO

'----------------------------------------------------------------------------
How come it is inserting 1 row, Why it is not able to connect to VB code and inserting other records, please help me correct this issue.
When I debug, it issaying that ObjectVariable Or with Block variable not set,
Please help, what that means. it cannot call multiple times....
Any help is apreciated
0
 
LVL 7

Accepted Solution

by:
chisholmd earned 240 total points
Comment Utility
layers?

btw: in your main loop you are creating that object and never destroying it:
      Set oPC = Server.CreateObject ("CmpMTCTRL.CMTCTRL")
      lPCResponseCode = oPC.ProcessPage(oInputDict, oOutputDict, sRedirectURL)
    End If
Next

Not a good practice at all. All you should have to do is move the "set oPC" line to just before the "For " statement. Then after the "Next" statement add "set oPC = nothing"

Also,  is lPCResponseCode just a throwaway return value from the method or are you supposed to be doing something with it?  Cause you are simply overwritting it in your loop.

What line is it referenceing when you get the error: "ObjectVariable Or with Block variable not set"  This error means you are trying to reference something as an object that has not been instantiated as an object.  

I mentioned that your asp is calling "processPage" but I can only find a function called "executePage"  This could be related to your error.







 

                                                 
0
 

Author Comment

by:MikeHall12
Comment Utility
chisholmd,
 Thanks for your work
Unfortuantely I changed the code to connect to SQL server directly from asp page, through include file.

But anyways, Since you worked to reolve the issue, I am going to give the point
Thanks
Mike
0
 
LVL 7

Expert Comment

by:chisholmd
Comment Utility
thanks...good luck
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to solve this equation 3 47
Classic ASP - SQL Server connection problem 5 49
Help with stored procedure 30 51
INNER JOIN ? 8 29
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now