I am a newbie when it comes to VB Script and I am trying to make a Combo box with an onchange event.
Here is the code that i have so far:
' Report Version
If FieldID = 36 Then
If IsLIXIJob Then
'first get the field id of the fields you want to hide or display
SQLQuery = "SELECT FieldID, FieldName FROM Fields WITH (NOLOCK) " & _
" WHERE [Table] = 'Valuations' AND " & _
" FieldName IN ('RiskTenderPriceDisplay', 'RiskProgressPaymentScheduleDisplay')"
Set LIXITBEFields = dbConn.Execute(SQLQuery)
TBEFieldsOn = ""
TBEFieldsOff = ""
If Not LIXITBEFields.EOF Then
Do While Not LIXITBEFields.EoF
TBEFieldsOn = TBEFieldsOn & "if (IsDefined ('StandardField_" & LIXITBEFields ("FieldID") & "')) $('StandardField_" & LIXITBEFields ("FieldID") & "').style.display = ''; " & vbCrLf
TBEFieldsOff = TBEFieldsOff & "if (IsDefined ('StandardField_" & LIXITBEFields ("FieldID") & "')) $('StandardField_" & LIXITBEFields ("FieldID") & "').style.display = 'none'; " & vbCrLf
LIXITBEFields.MoveNext ()
Loop
End If
LIXITBEFields.Close ()
Set LIXITBEFields = Nothing
End If
Select Case Output
Case 0
RunAtEnd = "AllFields(); " & TBEFieldsOff
Case 1
RunAtEnd = "StandardMode(); " & TBEFieldsOff
Case 2
RunAtEnd = "StrataMode();" & TBEFieldsOff
Case 3
RunAtEnd = "TBEMode();" & TBEFieldsOn
Case 4
RunAtEnd = "TBEUnitMode();" & TBEFieldsOn
Case 5
RunAtEnd = "RenoMode(); " & TBEFieldsOff
Case 6
RunAtEnd = "RenoUnitMode(); " & TBEFieldsOff
Case 7
RunAtEnd = "VacantLandMode();" & TBEFieldsOff
End Select
%>
<select name="ReportList" id="ReportList" onchange="ReportList_SelectedIndexChanged()">
<option value="All Fields">All Fields</option>
<option value="Existing Building">Existing Building</option>
<option value="xisting Building - Strata">Existing Building - Strata</option>
<option value="To Be Erected">To Be Erected</option>
<option value="To Be Erected - Strata">To Be Erected - Strata</option>
<option value="Extension & Renovation">Extension & Renovation</option>
<option value="Extension & Renovation - Strata">Extension & Renovation - Strata</option>
<option value="Vacant Land">Vacant Land</option>
</select>
<%
End If
I tried making a Sub statement enclosing the Select Case but it didn't work.
I also made a Private Sub outside the If statement and called in on the onchange for the comboBox:
Private Sub ReportList_SelectedIndexChanged()
Dim selectedInd
selectedInd = ReportList.SelectedIndex
Dim selectedIt
selectedIt = ReportList.SelectedItem.Text
If selectedIt = "All Fields" Then
RunAtEnd = "AllFields(); " & TBEFieldsOff
End If
If selectedIt = "Existing Building" Then
RunAtEnd = "StandardMode(); " & TBEFieldsOff
End If
If selectedIt = "Existing Building - Strata" Then
RunAtEnd = "StrataMode();" & TBEFieldsOff
End If
If selectedIt = "To Be Erected" Then
RunAtEnd = "TBEMode();" & TBEFieldsOn
End If
If selectedIt = "To Be Erected - Strata" Then
RunAtEnd = "TBEUnitMode();" & TBEFieldsOn
End If
If selectedIt = "Extension & Renovation" Then
RunAtEnd = "RenoMode(); " & TBEFieldsOff
End If
If selectedIt = "Extension & Renovation - Strata" Then
RunAtEnd = "RenoUnitMode(); " & TBEFieldsOff
End If
If selectedIt = "Vacant Land" Then
RunAtEnd = "VacantLandMode();" & TBEFieldsOff
End If
End Sub
I'm really stuck at this bit. Anyway I can make this work?
Related
I am getting error 424 on this line, can anyone help me please.
lblprvbal.Text = Val(NewItem.SubItems(11))
Private Sub cmdShow_Click()
'lblTotPur/lblTotPayRet/lblBalance
Dim strShow, mSlNo
Dim rsShow As New ADODB.Recordset
Dim NewItem As Variant
If Trim(txtCustomer.Text) = "" Then
MsgBox "Please select customer to proceed...", vbCritical, POPUP_COMP
Exit Sub
End If
Dim recCnt
pgrPartyLedger.Min = 0
recCnt = 0
'VOUCHMST_P//VNO,DATED,VTYPE,REMARKS,byUser CASH PURCHASE RETURN
strShow = "select Count(*) as mCnt from VOUCHMST A,VOUCHDAT B, Prevbal C "
strShow = strShow & " where A.VNO=B.VNO and B.IDNO=C.obd and (A.REMARKS='CASH SALE RETURN' OR A.REMARKS='CREDIT SALE RETURN' OR A.REMARKS='CREDIT SALE' OR A.REMARKS='CASH SALE' OR A.REMARKS='RECEIPT' OR A.REMARKS='CREDIT NOTE') "
strShow = strShow & " and A.DATED between #" & Format(dtFrom.Value, "MM/dd/yyyy") & "# "
strShow = strShow & " and #" & Format(dtTo.Value, "MM/dd/yyyy") & "# "
strShow = strShow & " and B.IDNO = '" & Trim(txtCustomerId.Text) & "' "
'strShow = strShow & " order by A.ID,A.DATED,A.VNO"
rsShow.Open strShow, cn
recCnt = rsShow("mCnt")
rsShow.Close
pgrPartyLedger.Max = recCnt + 1
'VOUCHMST_P//VNO,DATED,VTYPE,REMARKS,byUser
strShow = "select A.Id,A.cmnt,A.ADV,A.VNO,A.DATED,B.IDNO,B.IDNAME,B.AMOUNT,B.DR_CR,B.VNARRATION,A.REMARKS,B.CQ_TYPE, B.BANKNAME, B.BANKBRANCH, B.CQ_NO, C.amnt from VOUCHMST A,VOUCHDAT B, Prevbal C "
strShow = strShow & " where A.VNO=B.VNO and B.IDNO=C.obd and (A.REMARKS='CASH SALE RETURN' OR A.REMARKS='CREDIT SALE RETURN' OR A.REMARKS='CREDIT SALE' OR A.REMARKS='CASH SALE' OR A.REMARKS='RECEIPT' OR A.REMARKS='CREDIT NOTE') "
strShow = strShow & " and A.DATED between #" & Format(dtFrom.Value, "MM/dd/yyyy") & "# "
strShow = strShow & " and #" & Format(dtTo.Value, "MM/dd/yyyy") & "# "
strShow = strShow & " and B.IDNO = '" & Trim(txtCustomerId.Text) & "' "
strShow = strShow & " order by A.ID,A.DATED,A.VNO"
rsShow.Open strShow, cn
Dim mPur, mPayRet, mAnyAdv, mTempVNO
mPur = 0
mPayRet = 0
mAnyAdv = 0
mSlNo = 1
ShowPaymentHeader
Do While Not rsShow.EOF
mTempVNO = rsShow("VNO")
Set NewItem = listViewPayment.ListItems.Add(, "C" & mSlNo, Format(rsShow("DATED"), "dd/MM/yyyy"))
NewItem.SubItems(1) = mTempVNO
NewItem.SubItems(2) = IIf(IsNull(rsShow("IDNAME")), "", CommaFilterText(rsShow("IDNAME"), 1))
NewItem.SubItems(11) = rsShow("amnt")
If Trim(rsShow("REMARKS")) = "CASH SALE" Then
NewItem.SubItems(3) = FormatTakaPaisa(rsShow("AMOUNT"))
NewItem.SubItems(4) = FormatTakaPaisa(rsShow("AMOUNT"))
ElseIf Trim(rsShow("REMARKS")) = "CREDIT SALE" Then
mAnyAdv = ShowPartialAdvance(rsShow("VNO"))
NewItem.SubItems(3) = FormatTakaPaisa(rsShow("AMOUNT") + Val(mAnyAdv))
If Val(mAnyAdv) > 0 Then
NewItem.SubItems(4) = FormatTakaPaisa(mAnyAdv)
Else
NewItem.SubItems(4) = ""
End If
Else
NewItem.SubItems(3) = ""
NewItem.SubItems(4) = FormatTakaPaisa(rsShow("AMOUNT"))
NewItem.SubItems(7) = rsShow("CQ_TYPE")
NewItem.SubItems(8) = rsShow("BANKNAME")
NewItem.SubItems(9) = rsShow("BANKBRANCH")
NewItem.SubItems(10) = rsShow("CQ_NO")
NewItem.SubItems(13) = "" & rsShow("cmnt")
End If
NewItem.SubItems(6) = rsShow("IDNO")
mPur = mPur + Val(NewItem.SubItems(3))
mPayRet = mPayRet + Val(NewItem.SubItems(4))
NewItem.SubItems(5) = rsShow("REMARKS")
NewItem.SubItems(12) = GetVoucherRefNo(mTempVNO)
pgrPartyLedger.Value = mSlNo
mSlNo = mSlNo + 1
rsShow.MoveNext
Loop
rsShow.Close
lblprvbal.Text = Val(NewItem.SubItems(11))
lblTotPur.Caption = FormatTakaPaisa(mPur) + Val(lblprvbal.Text)
lblTotPayRet.Caption = FormatTakaPaisa(mPayRet)
lblBalance.Caption = FormatTakaPaisa(mPur - mPayRet) + Val(lblprvbal.Text)
pgrPartyLedger.Value = 0
End Sub
Looks like lblprvbal isn't an object. Meaning, you don't have a TextBox called lblprvbal in your form, even if you think you do. Maybe because its real name is lblPrvBal? That would be consistent with your other object names. As a side note, you probably don't want to start a TextBox with lbl, which suggests it's a label.
Try below. value in the sub item is null and hence the error.
If IsDBNull(NewItem.SubItems(11)) Then
lblprvbal.Text = ""
Else
lblprvbal.Text = Val(NewItem.SubItems(11))
End If
Check if not NewItem is Nothing.
I've got a page that will either display information in an HTML table or output that same info as an excel file.
The HTML view is working fine, but the excel portion fails with : (500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed.)
Ideally, if its possible to separate the excel portion of the code I'd rather have that as the final product, but I need to get it working first. I'd appreciate any ideas.
<%# Language=VBScript %>
<% Session("CurrentPageTitle") = "Test Transaction Summary" %>
<%
Response.Buffer = TRUE
if Request.Form("present") = "xls" then
set objXL = CreateObject("Excel.Application")
Set objWB = objXL.WorkBooks.Open("C:\Inetpub\wwwroot\temp\xl.xlsx")
Set objWS = objXL.ActiveWorkBook.WorkSheets("Sheet1")
numRow = 9
end if
if Request.Form("present") <> "xls" then
%>
<!--#include file="../common/header.inc"-->
<%
end if
varState = Request.QueryString("state")
varCustomerIdentifier = Request.Form("Customer")
CustomerArray = Split(varCustomerIdentifier,",")
varCustomer = CustomerArray(0)
varSub = CustomerArray(1)
varCity = CustomerArray(2)
if Request.Form("Summary") = "user" and varState <> "u" then
'Should not be here, form navigation glitch - go to GetUserParam.asp
location.href="GetUserParam.asp?f=" & varCustomerIdentifier & "&t=user"
else
if varState = "u" then
varYesterday = Request.Form("Smonth") + "/" + Request.Form("Sday")+ "/" + Request.Form("Syear")
varToday = Request.Form("Emonth") + "/" + Request.Form("Eday")+ "/" + Request.Form("Eyear")
elseif varState = "m" then
varYesterday = month(date()) & "/1/" & year(date())
varToday = date()
strYesterday = dateadd("d",-1,date())
elseif varState = "y" then
varYesterday = "1/1/" & year(date())
varToday = date()
strYesterday = dateadd("d",-1,date())
elseif varState = "s" then
varYesterday = Request.Form("Smonth") + "/" + Request.Form("Sday")+ "/" + Request.Form("Syear")
varToday = Request.Form("Emonth") + "/" + Request.Form("Eday")+ "/" + Request.Form("Eyear")
varInterval = Request.Form("Interval")
else
varYesterday = cdate(datepart("m",date()-1) & "/" & datepart("d",date()-1) & "/" & datepart("yyyy",date()-1))
varToday = cdate(datepart("m",date()) & "/" & datepart("d",date()) & "/" & datepart("yyyy",date()))
end if
if varCustomer = "0" then
strSQL = "select CustomerNo, SubNo, City, CustomerName from Customer order by CustomerName"
else
strSQL = "select CustomerNo, SubNo, City, CustomerName from Customer where CustomerNo = " & varCustomer & " and SubNo = " & varSub & " and City = " & varCity & " order by CustomerName"
end if
' sjs
dim DBCONN
set DBCONN = Server.CreateObject("ADODB.Connection")
DBCONN.CommandTimeout = 60000
DBCONN.ConnectionTimeout = 60000
DBCONN.Open "DSN=***;UID=***;PWD=***;"
set DBConnection = DBCONN
set DBQuery = Server.CreateObject("ADODB.Command")
DBQuery.ActiveConnection = DBConnection
DBQuery.CommandType = 1
DBQuery.CommandText = strSQL
DBQuery.CommandTimeout = 900
Err.Clear
set dbRS = DBQuery.Execute
AllUpdateCount = 0
AllInquiryCount = 0
AllMTCount = 0
AllETCount = 0
AllTotalCount = 0
index = 0
while not dbRS.EOF
index = index + 1
if Request.Form("Summary") = "prevd" then
strType = "Yesterday"
strNote = "(from " & varYesterday & ")"
strFormatSQL = "select distinct [Format] 'formatid' from TransactionSummary where CustomerNo = " & dbRS.Fields("CustomerNo").Value & " and SubNo = " & dbRS.Fields("SubNo").Value & " and City = " & dbRS.Fields("City").Value & " and TransactionDate = '" & varYesterday & "'"
elseif Request.Form("Summary") = "user" then
strType = "User Specified"
strFormatSQL = "select distinct [Format] 'formatid' from TransactionSummary where CustomerNo = " & dbRS.Fields("CustomerNo").Value & " and SubNo = " & dbRS.Fields("SubNo").Value & " and City = " & dbRS.Fields("City").Value & " and TransactionDate >= '" & varYesterday & "' and TransactionDate <= '" & varToday & "'"
strNote = "(from " & varYesterday & " to " & varToday & ")"
elseif Request.Form("Summary") = "mtd" then
strType = "Month To Date"
strFormatSQL = "select distinct [Format] 'formatid' from TransactionSummary where CustomerNo = " & dbRS.Fields("CustomerNo").Value & " and SubNo = " & dbRS.Fields("SubNo").Value & " and City = " & dbRS.Fields("City").Value & " and TransactionDate >= '" & varYesterday & "' and TransactionDate < '" & varToday & "'"
strNote = "(from " & varYesterday & " through " & varToday & ")"
elseif Request.Form("Summary") = "ytd" then
strType = "Year To Date"
strFormatSQL = "select distinct [Format] 'formatid' from TransactionSummary where CustomerNo = " & dbRS.Fields("CustomerNo").Value & " and SubNo = " & dbRS.Fields("SubNo").Value & " and City = " & dbRS.Fields("City").Value & " and TransactionDate >= '" & varYesterday & "' and TransactionDate < '" & varToday & "'"
strNote = "(from " & varYesterday & " through " & varToday & ")"
elseif Request.Form("Summary") = "stats" then
strType = "Usage Statistics"
strFormatSQL = "select TransactionDate from TransactionDetail where CustomerNo = " & dbRS.Fields("CustomerNo").Value & " and SubNo = " & dbRS.Fields("SubNo").Value & " and City = " & dbRS.Fields("City").Value & " and TransactionDate >= '" & varYesterday & "' and TransactionDate <= '" & varToday & " 11:59:59 PM'"
strNote = "(from " & varYesterday & " to " & varToday & ")"
else
strFormatSQL = ""
end if
'very top
if Request.Form("present") = "xls" then
if varCustomer = "0" and index = 1 then
objXL.Cells(5,2) = strType & " Summary For ALL Customers"
objXL.Cells(6,2) = strNote
end if
if varCustomer ="0" then
else
objXL.Cells(5,2) = strType & " Summary For Customer: " & Trim(dbRS.Fields("CustomerName").Value) & " - City " & Trim(dbRS.Fields("City").Value)
objXL.Cells(6,2) = strNote
end if
elseif Request.Form("present") <> "xls" then
if varCustomer = "0" and index = 1 then
Response.Write("<h3>" & strType & " Summary for All Customers<br>" & chr(13))
Response.Write("<font size=""-1"">" & strNote & "</font></h3>" & chr(13))
Response.Write("<table border=""1"" id=""exCity"" runat=""server"">" & chr(13))
Response.Write("<tr>" & chr(13))
Response.Write("<td align=""center""><strong>Customer</strong></td>" & chr(13))
Response.Write("<td align=""center""><strong>City</strong></td>" & chr(13))
Response.Write("<td align=""center""><strong>Inquiry</strong></td>" & chr(13))
Response.Write("<td align=""center""><strong>Update</strong></td>" & chr(13))
Response.Write("<td align=""center""><strong>Total</strong></td>" & chr(13))
Response.Write("</tr>" & chr(13))
end if
' Customer and City for ALL Customers added above each record top
if varCustomer = "0" then
' Response.Write("<h3><i>" & Trim(dbRS.Fields("CustomerName").Value) & " - Po------------rt " & Trim(dbRS.Fields("City").Value) & "</i></h3>" & chr(13))
'Customer and City for a single Customer added to very top
else
Response.Write("<h3>" & strType & " Summary for Customer: " & Trim(dbRS.Fields("CustomerName").Value) & " - City " & Trim(dbRS.Fields("City").Value) & "<br>" & chr(13))
Response.Write("<font size=""-1"">" & strNote & "</font></h3>" & chr(13))
'start a table with format request name transatctions at the top
Response.Write("<table border=""1"" id=""exCity"" runat=""server"">" & chr(13))
Response.Write("<tr>" & chr(13))
Response.Write("<td align=""center""><strong>Customer</strong></td>" & chr(13))
Response.Write("<td align=""center""><strong>City</strong></td>" & chr(13))
Response.Write("<td align=""center""><strong>Inquiry</strong></td>" & chr(13))
Response.Write("<td align=""center""><strong>Update</strong></td>" & chr(13))
Response.Write("<td align=""center""><strong>Total</strong></td>" & chr(13))
Response.Write("</tr>" & chr(13))
end if
end if
'query db for one Customer
DBQuery.CommandText = strFormatSQL
Err.Clear
set dbRS3 = DBQuery.Execute
UpdateTotalCount = 0
InquiryTotalCount = 0
MTTotalCount = 0
ETTotalCount = 0
CustomerTotalCount = 0
IntervalCounter = 0
IntervalStart = varYesterday & " 12:00:00 AM"
while not dbRS3.EOF
if varState = "s" then
Difference = datediff("n", IntervalStart, dbRS3.Fields("TransactionDate").Value)
if (CInt(Difference) < CInt(varInterval)) then
IntervalCounter = IntervalCounter + 1
else
IntervalNext = dateadd("n", varInterval, IntervalStart)
Response.Write("<tr><td align=""left"">" & IntervalStart & " to <br>" & IntervalNext & "</td><td align=""center"" valign=""middle"">" & IntervalCounter & "</td></tr>" & chr(13))
IntervalCounter = 0
IntervalStart = IntervalNext
end if
else
if Request.Form("Summary") = "prevd" then
strSQL = "select Sum(s.TransactionCount) 'hits', r.RequestName from TransactionSummary as s LEFT JOIN RepositoryDB.dbo.BLS_REQ as r ON s.[Format] = r.RequestID where s.CustomerNo = " & dbRS.Fields("CustomerNo").Value & " and s.SubNo = " & dbRS.Fields("SubNo").Value & " and s.City = " & dbRS.Fields("City").Value & " and s.TransactionDate = '" & varYesterday & "' and s.[Format] = " & dbRS3.Fields("formatid").Value & " GROUP BY r.RequestName"
else
strSQL = "select sum(s.TransactionCount) 'hits', r.RequestName from TransactionSummary as s LEFT JOIN RepositoryDB.dbo.BLS_REQ as r ON s.[Format] = r.RequestID where s.CustomerNo = " & dbRS.Fields("CustomerNo").Value & " and s.SubNo = " & dbRS.Fields("SubNo").Value & " and s.City = " & dbRS.Fields("City").Value & " and s.TransactionDate >= '" & varYesterday & "' and s.TransactionDate <= '" & varToday & "' and s.[Format] = " & dbRS3.Fields("formatid").Value & " GROUP BY r.RequestName"
end if
DBQuery.CommandText = strSQL
Err.Clear
set dbRS2 = DBQuery.Execute
If Err.Number <> 0 Then
Response.Write("Could not get Transaction Summary - database error. SQL Script = " & strSQL)
End If
' Count the hits into their respective total
If (Trim(dbRS3.Fields("formatid").Value) = 25) or (Trim(dbRS3.Fields("formatid").Value) = 425 )Then
MTTotalCount = MTTotalCount + dbRS2.Fields("hits").value
ElseIf (Trim(dbRS3.Fields("formatid").Value = 23)) Then
ETTotalCount = ETTotalCount + dbRS2.Fields("hits").value
ElseIf (Trim(dbRS3.Fields("formatid").Value) = 38) or _
((Trim(dbRS3.Fields("formatid").Value) >= 400) and _
(Trim(dbRS3.Fields("formatid").Value) <= 499) or _
((Trim(dbRS3.Fields("formatid").Value) >= 800) and _
(Trim(dbRS3.Fields("formatid").Value) <= 899))) Then
UpdateTotalCount = UpdateTotalCount + dbRS2.Fields("hits").value
Else
InquiryTotalCount = InquiryTotalCount + dbRS2.Fields("hits").value
End If
set dbRS2 = nothing
end if
dbRS3.MoveNext
wend
set dbRS3 = nothing
UpdateTotalCount = UpdateTotalCount + MTTotalCount + ETTotalCount
CustomerTotalCount = UpdateTotalCount + InquiryTotalCount
' show totals
if Request.Form("present") = "xls" then
objXL.Cells(numRow,2) = Trim(dbRS.Fields("CustomerName").Value)
objXL.Cells(numRow,3) = Trim(dbRS.Fields("City").Value)
objXL.Cells(numRow,4) = UpdateTotalCount
objXL.Cells(numRow,5) = InquiryTotalCount
objXL.Cells(numRow,6) = CustomerTotalCount
objXL.Range("B" & numRow & ":F" & numRow).BORDERS.Weight = 2
numRow = numRow + 1
end if
if Request.Form("present") <> "xls" then
if varState <> "s" then
Response.Write("<tr>" & chr(13))
Response.Write("<td align=""left"">" & Trim(dbRS.Fields("CustomerName").Value) & "</td>" & chr(13))
Response.Write("<td align=""center"">" & Trim(dbRS.Fields("City").Value) & "</td>" & chr(13))
Response.Write("<td align=""center"">" & UpdateTotalCount & "</td>" & chr(13))
Response.Write("<td align=""center"">" & InquiryTotalCount & "</td>" & chr(13))
Response.Write("<td align=""center"">" & CustomerTotalCount & "</td>" & chr(13))
Response.Write("</tr>" & chr(13))
else
IntervalNext = dateadd("n", varInterval, IntervalStart)
Response.Write("<tr><td align=""left"">" & IntervalStart & " to <br>" & IntervalNext & "</td><td align=""center"" valign=""middle"">" & IntervalCounter & "</td></tr>" & chr(13))
end if
' Response.Write("</table>" & chr(13))
end if
'set dbRS2 = nothing
dbRS.MoveNext
AllUpdateCount = AllUpdateCount + UpdateTotalCount
AllInquiryCount = AllInquiryCount + InquiryTotalCount
AllMTCount = AllMTCount + MTTotalCount
AllETCount = AllETCount + ETTotalCount
AllTotalCount = AllTotalCount + CustomerTotalCount
'do grand totals
wend
set dbRS = nothing
if Request.Form("present") <> "xls" then
Response.Write("</table>" & chr(13))
if varCustomer = "0" and varState <> "s" then
Response.Write("<h3>Grand Total Update = " & AllUpdateCount & "</h3>" & chr(13))
Response.Write("<h3>Grand Total Inquiry = " & AllInquiryCount & "</h3>" & chr(13))
Response.Write("<h3>Grand Total for All Customers = " & AllTotalCount & "</h3>" & chr(13))
Response.Write("<h3>Grand Total Manual Transactions = " & AllMTCount & "</h3>" & chr(13))
Response.Write("<h3>Grand Total Early Transactions = " & AllETCount & "</h3>" & chr(13))
end if
end if
end if
if Request.Form("present") <> "xls" then
%><!--#include file="../Common/footer.inc"--><%
end if
if Request.Form("present") = "xls" then
objXL.Cells(numRow+1,4) = "Copyright " & Year(Date)
objXL.Cells(numRow+2,4) = "All Rights Reserved"
Set Fso = CreateObject("Scripting.FileSystemObject")
If (Fso.FileExists("C:\Inetpub\temp\xl2.xlsx")) Then
Set MyFile = Fso.GetFile("C:\Inetpub\temp\xl2.xlsx")
MyFile.Delete
Set MyFile=nothing
End If
Set Fso=nothing
objWB.SaveAs "C:\Inetpub\temp\xl2.xlsx"
objWB.Close
objXL.Quit
Response.Redirect "/temp/xl2.asp"
end if
%>
This section of your code:
if Request.Form("present") = "xls" then
objXL.Cells(numRow,2) = Trim(dbRS.Fields("CustomerName").Value)
objXL.Cells(numRow,3) = Trim(dbRS.Fields("City").Value)
objXL.Cells(numRow,4) = UpdateTotalCount
objXL.Cells(numRow,5) = InquiryTotalCount
objXL.Cells(numRow,6) = CustomerTotalCount
objXL.Range("B" & numRow & ":F" & numRow).BORDERS.Weight = 2
numRow = numRow + 1
end if
Is referring to the Cells and Range objects with the wrong parent object. The parent to these would be the worksheet, which you have previously set as objWS. Also note that you really should set objWS like this:
Set objWS = objWB.Worksheets("Sheet1")
because the ActiveWorkbook can change when you least expect it... :)
I have a VB script which scans the mentioned log file for errors and sends a notification through an email.
How can I scan the latest log file in the folder? For example, Filename1.070615 (Filename1.mmddyy) is a log file. After a certain size, the logfile switches to new file with the same name but different date: Filename1.070615.
cdoSendUsingPort = 2, _
Const ForReading = 1
Dim intStartAtLine, strFileCreateddate, i, strResults, strTextToScanFor, bStartFromScratch
Dim strLastCheckedFor, strArrayToString, strSubject, strMailFrom, strMailTo
strMailto = "<Emailaddress>"
strMailFrom = "<FromAddress>"
strSubject = "Log scanner"
strSMTPServer = "x.x.x.x"
FileToRead = "D:\LOG\filename1.mmddyy"
arrTextToScanFor = Array("error","another thing")
Set WshShell = WScript.CreateObject("WScript.Shell")
searchkey = replace(replace(filetoread,":",""),"\","_")
On Error Resume Next
strLastFileCheckedCreateDate = WshShell.RegRead("HKCU\Software\RDScripts\CheckTXTFile\" & searchkey & "\CreateDate")
strLastFileLastLineChecked = WshShell.RegRead("HKCU\Software\RDScripts\CheckTXTFile\" & searchkey & "\LastLineChecked")
strLastCheckedFor = WshSHell.RegRead("HKCU\Software\RDScripts\CheckTXTFile\" & searchkey & "\CheckForString")
iLastCheckedLine = WshSHell.RegRead("HKCU\Software\RDScripts\CheckTXTFile\" & searchkey & "\LastLineChecked")
On Error GoTo 0
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set varFile = objFSO.GetFile(FileToRead)
arrLastCheckedForText = split(strLastCheckedFor,",")
strFileCreateDate = varfile.datecreated
strFileModifiedDate = varfile.datelastmodified
sStatus = "<li>Using mail server: " & strSMTPServer & "</li><li>Running from: " & wscript.scriptfullname & "</li>"
Set objTextFile = objFSO.OpenTextFile(FileToRead, ForReading)
objTextFile.ReadAll
iLineCount = objTextFile.Line
objTextFile.close
If strLastCheckedFor = "" Then
bStartFromScratch = true
sStatus = sStatus & "<li>First run of script against string search</li>" & vbcrlf
ElseIf ubound(arrTextToScanFor) <> ubound(arrLastCheckedForText) Then
bStartFromScratch = true
sStatus = sStatus & "<li>Count of string search criteria has changed</li>" & vbcrlf
Else
For each strItem in arrTextToScanFor
Else
bStartFromScratch = true
'MsgBox strResults
End If
If bStartFromScratch = true Then
sStatus = sStatus & "<li>String search criteria does not match prior search</li>" & vbcrlf
End If
Next
End If
If cint(iLineCount) < cint(iLastCheckedLine) Then
bStartFromScratch = true
sStatus = sStatus & "<li>Last line checked (" & iLastCheckedLine & ") is greater than total line count (" & iLineCount & ") in file</li>"
End If
If CStr(strFileCreateDate) = CStr(strLastFileCheckedCreateDate) and bStartFromScratch <> true Then
intStartAtLine = strLastFileLastLineChecked
If bStartFromScratch <> true then
sStatus = sStatus & "<li>Continuing search from line " & intStartAtLine & "</li>" & vbcrlf
End If
ElseIf strFileCreateDate <> strLastFileCheckedCreateDate or bStartFromScratch = true Then
intStartAtLine = 0
If bStartFromScratch <> true then
sStatus = sStatus & "<li>File created date has changed, starting search from line 0</li>" & vbcrlf
End If
End If
i = 0
Dim strNextLine
For each strItem in arrTextToScanFor
strArrayToString = strArrayToString & delim & strItem
delim = ","
Next
Set objTextFile = objFSO.OpenTextFile(FileToRead, ForReading)
Do While objTextFile.AtEndOfStream <> True
If i < CInt(intStartAtLine) Then
objTextFile.skipline
Else
'MsgBox i
strNextLine = objTextFile.Readline
For each strItem in arrTextToScanFor
If InStr(LCase(strNextLine),LCase(strItem)) Then
strResults = "<span style='font-family:courier-new;color:#696969'><span style='font-weight:bold;background-color:#BEF3F3'>Line " & i & ":</span> " & replace(lcase(strNextLine),lcase(strItem),"<span style='background-color:#FFFF81'>" & strItem & "</span>") & "</span><br>" & vbcrlf & strResults
bSendMail = true
End If
Next
End If
i = i + 1
Loop
objTextFile.close
Set WshShell = CreateObject("WScript.Shell")
'Let's save our settings for next time.
WshShell.RegWrite "HKCU\Software\RDScripts\CheckTXTFile\" & searchkey & "\FileChecked", FileToRead, "REG_SZ"
WshShell.RegWrite "HKCU\Software\RDScripts\CheckTXTFile\" & searchkey & "\CreateDate", strFileCreateDate, "REG_SZ"
WshShell.RegWrite "HKCU\Software\RDScripts\CheckTXTFile\" & searchkey & "\LastLineChecked", i, "REG_SZ"
WshShell.RegWrite "HKCU\Software\RDScripts\CheckTXTFile\" & searchkey & "\LastScanned", Now, "REG_SZ"
WshShell.RegWrite "HKCU\Software\RDScripts\CheckTXTFile\" & searchkey & "\CheckForString",strArrayToString, "REG_SZ"
set WshShell = nothing
strFileSummary = "<tr><td style='font-family:calibri;font-weight:bold;color:darkblue;width:200px'>File path:</td><td>" & FileToRead & "</td></tr>"
strFileCreateDateSummary = "<tr><td style='font-family:calibri;font-weight:bold;color:darkblue;width:200px'>Created date:</td><td>" & strFileCreateDate & "</td></tr>"
strFileModifiedDateSummary = "<tr><td style='font-family:calibri;font-weight:bold;color:darkblue;width:200px'>Modified date:</td><td>" & strFileModifiedDate & "</td></tr>"
strArraySummary = "<tr><td style='font-family:calibri;font-weight:bold;color:darkblue;width:200px'>Text string(s):</td><td>" & strArrayToString & "</td></tr>"
strFileLineSummary = "<tr><td style='font-family:calibri;font-weight:bold;color:darkblue;width:200px'>Last line checked:</td><td>" & i & "</td></tr>"
strSummary = strFileSummary & strFileCreateDateSummary & strFileModifiedDateSummary & strArraySummary & strFileLineSummary
strBodyContent = "<table style='font-family:calibri;'>" & strSummary & "</table><br><br><span style='font-size:large;'>Entries:</span><br>" & strResults & "<div style='padding-top:30px;font-size:x-small'><br><div style='font-weight:bold;font-family:calibri;color:black;'>Job Details:<ul style='font-weight:normal;font-family:calibri;color:darkgray;'>" & sStatus & "</ul></div></div>"
on error goto 0
'Send the email if need be.
If bSendMail = true Then Call sendmail(strMailFrom,strMailTo,strSubject,strBodyContent)
'------------------------------------------------------------------------
'Function EmailFile - email the warning file
'------------------------------------------------------------------------
Function SendMail(strFrom,strTo,strSubject,strMessage)
Dim iMsg, iConf, Flds
On Error GoTo 0
'// Create the CDO connections.
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
'// SMTP server configuration.
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort
'// Set the SMTP server address here.
.Item(cdoSMTPServer) = strSMTPServer
.Update
End With
'// Set the message properties.
With iMsg
Set .Configuration = iConf
.To = strMailTo
.From = strMailFrom
.Subject = strSubject
.htmlbody = strMessage
End With
'iMsg.HTMLBody = strMessage
'// Send the message.
iMsg.Send ' send the message.
If CStr(err.number) <> 0 Then
Else
End If
End Function
It would be a bit easier if your log files were named filename1.yymmdd.
Nevertheless, we can use a regex to not only verify the filename but also swap the date components to put them in our desired format!
Set re = New RegExp
re.Pattern = "^(filename1\.)(\d{2})(\d{2})(\d{2})$"
Set fso = CreateObject("Scripting.FileSystemObject")
For Each objFile In fso.GetFolder("d:\log").Files
If re.Test(objFile.Name) Then
strCompareName = re.Replace(objFile.Name, "$1$4$2$3")
If strCompareName > strLatest Then strLatest = strCompareName
End If
Next
' Switch the name back...
strLatest = re.Replace(strLatest, "$1$3$4$2")
WScript.Echo "The latest file is: " & strLatest
This line:
strCompareName = re.Replace(objFile.Name, "$1$4$2$3")
changes the format from mmddyy to yymmdd and saves it in a string for comparison.
Once we've finished our comparisons, we just need to take the latest file we found and reverse the process:
strLatest = re.Replace(strLatest, "$1$3$4$2")
to get the original filename back!
I'm trying to make a VBScript that will allow me to select items from a drop down menu. If possible once an option is selected it will open a particular file or program. I'm not sure why it's not working? Any help would be very much appreciated.
Option Explicit
Dim objShell
Dim aOpt(6)
aOpt(0) = "Option 1"
aOpt(1) = "Option 2"
aOpt(2) = "Option 3"
aOpt(3) = "Option 4"
aOpt(4) = "Option 5"
aOpt(5) = " "
aOpt(6) = " "
SelectBox "Select an install option", aOpt
Function SelectBox(sTitle, aOptions)
Dim oIE, s, item
set oIE = CreateObject("InternetExplorer.Application")
With oIE
.ToolBar = False : .RegisterAsDropTarget = False
.StatusBar = False : .Navigate("about:blank")
While .Busy : WScript.Sleep 100 : Wend
With .document
With .parentWindow
if Instr(.navigator.appVersion, "MSIE 6") > 0 Then
oIE.FullScreen = True
End if
oIE.width = 400 : oIE.height = 600
oIE.left = .screen.width \ 2 - 200
oIE.top = .screen.height\ 2 - 75
End With ' ParentWindow
s = "<html><head><title>" & sTitle & " " & String(80, ".") _
& "</title></head><script language=vbs>bWait=true</script>" _
& "<body bgColor=Silver><center><b>" & sTitle & "<b><p>" _
& "<select id=entries size=1 style='width:250px'>" _
& " <option selected>" & sTitle & "</option>"
For each item in aOptions
s = s & " <option>" & item & "</option>"
Next
s = s & " </select><p>" _
& "<button id=but0 onclick='bWait=false'>OK</button>" _
& "</center></body></html>"
.WriteLn(s)
With .body
.scroll="no"
.style.borderStyle = "outset"
.style.borderWidth = "3px"
End With ' Body
.all.entries.focus
oIE.Visible = True
On Error Resume Next
While .ParentWindow.bWait
WScript.Sleep 100
if oIE.Visible Then SelectBox = ""
if Err Then Exit Function
Wend ' Wait
On Error Goto 0
With .ParentWindow.entries
SelectBox = .options(.selectedIndex).text
End With
End With ' document
.Visible = False
End With ' IE
Set objShell = WScript.CreateObject( "WScript.shell" )
If aOptions = aOpt(0) Then
objShell.Run("""Z:\folder\file""")
Set objShell = Nothing
End if
End Function
"It's not working" because
If aOptions = aOpt(0) Then
compares an array against an element of an other (?) array. By rights you should get an error message:
>> aOptions = Array()
>> If aOptions = "whatever" Then
>> WScript.Echo "bingo"
>> End If
>>
Error Number: 13
Error Description: Type mismatch
If not, you have disabled VBScript's error handling.
Can someone help me. I'm trying to display an alert msgbox with two different recordset in one form so whenever there is an expired medicine it will both display and alert at the same time. But it gives me an error "Duplicate error in current scope"
In this line
Dim expirationdate As Date
Do While Not Adodc2.Recordset.EOF = True
'----------'
Private Sub Form_Activate()
Dim expirationdate As Date
Me.AutoRedraw = True
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF = True
With Main
.Text4.Text = "" & Adodc1.Recordset.Fields("MedicineName")
.Text1.Text = Adodc1.Recordset.Fields("genericname")
.Text3.Text = Adodc1.Recordset.Fields("StockQuantity")
.Combo3.Text = Adodc1.Recordset.Fields("Expmonth")
.Combo4.Text = Adodc1.Recordset.Fields("Expday")
.Combo5.Text = Adodc1.Recordset.Fields("Expyear")
End With
expirationdate = CDate(Combo3 & "/" & Combo4 & "/" & Combo5)
datepicker.Value = Format(Now, "MMM-DD-yyyy")
If datepicker > expirationdate Then
MsgBox Text4.Text & " is Expired! ", vbExclamation, "Warning"
If MsgBox("Do you want to dispose " & Text4 & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
Adodc1.Recordset.Delete
Else
Exit Sub
End If
End If
Adodc1.Recordset.MoveNext
Loop
'________________'
Dim expirationdate As Date
Me.AutoRedraw = True
Adodc2.Recordset.MoveFirst
Do While Not Adodc2.Recordset.EOF = True
With Main
.Text10 = Adodc2.Recordset.Fields("roomno")
.Text11 = "" & Adodc2.Recordset.Fields("MedicineName")
.Text2 = Adodc2.Recordset.Fields("GenericName")
.Text12.Text = Adodc2.Recordset.Fields("StockQuantity")
.Combo10 = Adodc2.Recordset.Fields("Expmonth")
.Combo11 = Adodc2.Recordset.Fields("Expday")
.Combo12 = Adodc2.Recordset.Fields("Expyear")
End With
expirationdate = CDate(Combo10 & "/" & Combo11 & "/" & Combo12)
datepicker2.Value = Format(Now, "MMM-DD-yyyy")
If datepicker2 < expirationdate Then
MsgBox "OK!", vbInformation, "Working"
Else
MsgBox "Medicine Expired!.", vbExclamation, " Warning!"
If MsgBox("Do you want to delete " & Text11 & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
Adodc2.Recordset.Delete
Exit Sub
End If
End If
Adodc2.Recordset.MoveNext
Loop
End Sub
Try this. You are sometimes relying on the default properties of your controls. This is generally bad, so I added the properties. I also removed the Exit Sub line. If the user clicks No you don't want to exit the sub, you want to continue looping through the Adodc2 Recordset.
Me.AutoRedraw = True
Adodc2.Recordset.MoveFirst
Do While Not Adodc2.Recordset.EOF = True
With Main
.Text10.Text = Adodc2.Recordset.Fields("roomno")
.Text11.Text = "" & Adodc2.Recordset.Fields("MedicineName")
.Text2.Text = Adodc2.Recordset.Fields("GenericName")
.Text12.Text = Adodc2.Recordset.Fields("StockQuantity")
.Combo10.Text = Adodc2.Recordset.Fields("Expmonth")
.Combo11.Text = Adodc2.Recordset.Fields("Expday")
.Combo12.Text = Adodc2.Recordset.Fields("Expyear")
End With
expirationdate = CDate(Combo10.Text & "/" & Combo11.Text & "/" & Combo12.Text)
datepicker2.Value = Format(Now, "MMM-DD-yyyy")
If datepicker2.Value < expirationdate Then
MsgBox "OK!", vbInformation, "Working"
Else
MsgBox "Medicine Expired!.", vbExclamation, " Warning!"
If MsgBox("Do you want to delete " & Text11.Text & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
Adodc2.Recordset.Delete
End If
End If
Adodc2.Recordset.MoveNext
Loop