split array and display table in ASP classic? how to? - vbscript

Table Room
ID:1 | OFName: Room1
ID:2 | OFName: Room2
ID:3 | OFName: Room3
Table Document
ID:12 | Code:123/PA | RoomID: 1,2,3
ID:13 | Code:12/HC | RoomID: 2
ID:14 | Code:121/CA | RoomID: 2,3
ID:15 | Code:141/PC | RoomID: 1,3
And I want display like this
Room1
ID | Code
12 | 123/PA
15 | 141/PC
Room2
ID | Code
12 | 123/PA
13 | 12/HC
15 | 141/PC
I write like this but err !
<%
SQLDV = " Select ID,OFName From Room"
CREATECONNECTION()
rs.open SQLDV,ObjConn,1 ,3
While not rs.eof
response.write("" & rs(" OFName ") & "")
%>
<%
Create2ndRs()
SQLSearch = "SELECT ID,Code From Document"
ListArray = split(RoomID, ",")
For i = 0 to UBound(ListArray)-1
sqlWhere =sqlWhere & " (ListArray(i)=" & rs("ID") & ") "
Next
SQLSearch = SQLSearch & "where" & sqlWhere
rs1.open SQLSearch,ObjConn,1 ,3
While not rs1.eof
response.write("" & rs1("ID") & "","" & rs1("Code") & "")
rs1.movenext
wend
rs1.close
rs.movenext
wend
CLOSECONNECTION()%>

You have four lines of code which are just not going to work, each of these will give you its own error. You cant do this:
response.write(" & "rs(" OFName ") & "")
This should be something like (always use trim even if you don't think you need it, its just a good practice...):
response.write trim(rs("OFName"))
The way you ahve 'ListArray(i)' is inside a string. You cant do this:
sqlWhere = sqlWhere & " (ListArray(i)=" & rs("ID") & ") '"
This should be something like:
sqlWhere = sqlWhere & "(" & trim(ListArray(i)) & "=" & trim(rs("ID")) & ")"
You dont have a space after our table name and before the where, so this:
SQLSearch = SQLSearch & "where" & sqlWhere
should be
SQLSearch = SQLSearch & " where " & sqlWhere
Nor can you do this:
response.write("" & rs1("ID") & "","" & rs1("Code") & "")
I imagine you need:
response.write trim(rs1("ID")) & "," & trim(rs1("Code"))

Related

case statements for different date columns

I'm facing issues while writing the below code in SQL developer:
'If Trim$(psFromDate) <> "" and NOT ISNULL(psFromDate) AND Trim$(psToDate) <> "" and NOT ISNULL(psToDate) Then
select case ps_datetype
CASE "CTA"
wc = wc & " AND (trunc(sf_get_local (p_con.created_date,p_con.cdate_tz_code)) Between "
wc = wc & " TO_DATE (" & "'" & sFromDate & "'" & ", 'DD/MM/YYYY') "
wc = wc & " AND TO_DATE (" & "'" & sToDate & "'" & ", 'DD/MM/YYYY'))"
'CASE "ATA"
CASE "VAD"
wc = wc & " AND trunc(sf_get_local(route_s.orgn_vsl_arvl_date,route_s.orgn_vsl_arvl_date_tz_code)) Between "
wc = wc & " TO_DATE (" & "'" & sFromDate & "'" & ", 'DD/MM/YYYY') "
wc = wc & " AND TO_DATE (" & "'" & sToDate & "'" & ", 'DD/MM/YYYY')"
CASE "ETA"
wc = wc & " AND TRUNC(sf_get_local(route_s.arrival_date,route_s.arrival_date_tz_code)) Between "
wc = wc & " TO_DATE (" & "'" & sFromDate & "'" & ", 'DD/MM/YYYY') "
wc = wc & " AND TO_DATE (" & "'" & sToDate & "'" & ", 'DD/MM/YYYY')"
END SELECT
'End If
I tried the below code but no luck:
Where (case when pstatustype='CTA' then (p_con.created_date Between to_date('&1','DD-MON-YYYY:HH24:MI:SS')
AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))
when pstatustype='VAD' then (route_s.orgn_vsl_arvl_date Between to_date('&1','DD-MON-YYYY:HH24:MI:SS')
AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))
when pstatustype='ETA' then (route_s.arrival_date Between to_date('&1','DD-MON-YYYY:HH24:MI:SS')
AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))
else NULL end)
getting an error missing parenthesis. In then it is not taking BETWEEN operator.
Please help, how i can write this code in SQL developer.
Regards,
fuko
You can't put other conditions inside the case expression clauses.
You could either switch to simpler Boolean logic:
Where (pstatustype='CTA' AND p_con.created_date Between to_date('&1','DD-MON-YYYY:HH24:MI:SS')
AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))
OR (pstatustype='VAD' AND route_s.orgn_vsl_arvl_date Between to_date('&1','DD-MON-YYYY:HH24:MI:SS')
AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))
OR (pstatustype='ETA' AND (route_s.arrival_date Between to_date('&1','DD-MON-YYYY:HH24:MI:SS')
AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))
or just pick the relevant date column in the case expression and compare that with a single date range:
Where case when pstatustype='CTA' then p_con.created_date
when pstatustype='VAD' then route_s.orgn_vsl_arvl_date
when pstatustype='ETA' then route_s.arrival_date
else null -- default anyway
end Between to_date('&1','DD-MON-YYYY:HH24:MI:SS')
AND to_date('&2','DD-MON-YYYY:HH24:MI:SS')

vbscript not accessing outlook 2013/2016 subfolder off the inbox using redemption

I am running the below vbscript on outlook 2013/2016 and having issues trying to read emails in sub folders off the Inbox. I can read the Inbox emails. . Can anyone point me in the right directions?
thanks in advance.
Function CheckMail(strMailBox,strFolder,strFolderAbbr,strDetails)
'
olFolderInbox = 6
set Session = CreateObject("Redemption.RDOSession")
'
Set objOutlook = CreateObject("Outlook.Application")
Session.MAPIOBJECT = objOutlook.Session.MAPIOBJECT
set Store = Session.Stores.GetSharedMailbox(strMailBox)
set Inbox = Store.GetDefaultFolder(olFolderInbox)
'
Wscript.Echo "MailBox: " & Store.Name & " - " & Inbox.Name
If strFolder = "" then
set SubFolder = Inbox
strFolderAbbr = strMailBox & " Inbox"
Else
'set SubFolder = Inbox.Folders(strFolder)
'
set SubFolder = Inbox.Folders.Item(strFolder)
'
strFolderAbbr = strMailBox & " Inbox\" & strFolder
Wscript.Echo " Sub Folder: " & SubFolder
End If
'
nItems = SubFolder.Items.Count
If nHowlong > 1 Then
nHowlong = Round((nItems/110)/60,0)
strTime = " Hour(s)!!"
Else
nHowlong = Round(nItems/110,0)
strTime = " Minute(s)!!"
End If
Wscript.Echo nItems & " - Emails in folder " & strFolderAbbr & " About " & nHowlong & strTime
'" - " & nItems
'
for each Msg in SubFolder.Items
nCounter = nCounter + 1
'Wscript.Echo "Item " & nCounter & "/" & nItems & vbCRLF & "EID: " & Msg.EntryID & vbCRLF & "ABOUT: " & Msg.Subject & vbCRLF & "FROM: " & Msg.SenderName & vbCRLF & "LEVEL: " & IIf(Msg.Importance=2,"High",IIf(Msg.Importance=1,"Normal","Low")) & vbCRLF & "Status: " & IIf(Msg.UnRead, "Not Read", "Read") & vbCRLF & "Received: " & Msg.ReceivedTime & vbCRLF & "Body: " & Msg.Body
'& nCounter & "/" & nItems & vbCRLF & "EID: " & Msg.EntryID & vbCRLF & "ABOUT: " & Msg.Subject & vbCRLF & "FROM: " & Msg.SenderName & vbCRLF & "LEVEL: " & IIf(Msg.Importance=2,"High",IIf(Msg.Importance=1,"Normal","Low")) & vbCRLF & "Status: " & IIf(Msg.UnRead, "Not Read", "Read") & vbCRLF & "Received: " & Msg.ReceivedTime & vbCRLF & "Body: " & Msg.Body
'
' process all emails in the box
strRecords = strRecords & "REG-" &strFolderAbbr & "~" & Msg.Subject & "~" & Msg.ReceivedTime & "~" & IIf(Msg.UnRead, "Not Read", "Read") & "~" & Msg.SenderName & "~" &IIf(Msg.Importance=2,"High",IIf(Msg.Importance=1,"Normal","Low")) & "*"
On Error Resume Next
err.clear
if Err Then
'WScript.Echo "ReceivedTime was null"
End If
On Error GoTo 0
next
CheckMail = strRecords
End Function
Function IIf(bClause, sTrue, sFalse)
If CBool(bClause) Then
IIf = sTrue
Else
IIf = sFalse
End If
End Function
I finally figured out the code that works. I would first like to thank Dmitry for all the help he gave me. But this was a stuburn issue. the following code solved the problem. Please dont ask me to explain it just plain ole luck and trail and error.
set Session = CreateObject("Redemption.RDOSession")
Set objOutlook = CreateObject("Outlook.Application")
Session.MAPIOBJECT = objOutlook.Session.MAPIOBJECT
'Set Root foldedr of the mail box of the stores
set IPMRoot = Session.Stores.Item(strMailBox).IPMRootFolder
'Set the subfolder to the inbox
If strFolder = "" then
set subFolder = IPMRoot.Folders("InBox")
strFolderAbbr = strMailBox & " Inbox"
Else
'Set subfolder to subfolder chosen
set subFolder = IPMRoot.Folders("InBox").Folders(strFolder)
strFolderAbbr = strMailBox & " Inbox\" & strFolder
End If
'

Write Double Quotation Mark

I am trying to overwrite specific lines in a sequential file
For example if file has:
"1"
"Kii"
"Kii"
"Kii"
"Kii"
"2"
"Troy Martinez"
"Edoy"
"Edoy"
"69"
"3"
"Snoop Dogg"
"Weed"
"President Troy"
"420"
And I have this code to overwrite
Private Sub OverWrite()
Dim Count As Integer
On Error GoTo ErrSub
LineCount = 1
Open App.Path & "\Data.txt" For Input As #1
Do While Not EOF(1)
If LineCount < ((IDCount - 1) * 5) + 1 Or LineCount >= (IDCount * 5) + 1 Then
For Count = 0 To 4
Input #1, TextTemp
FileText = FileText & """ & Text1(Count) & """ & vbCrLf
LineCount = LineCount + 1
Next Count
Else
For Count = 0 To 4
Input #1, TextTemp
FileText = FileText & """ & TextTemp & """ & vbCrLf
LineCount = LineCount + 1
Next Count
End If
Loop
Close
Open App.Path & "\Data.txt" For Output As #1
Print #1, FileText
Close
ErrSub:
Resume Next
End Sub
Assuming my IDCount is 2, the text file becomes
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
" & TextTemp & "
" & TextTemp & "
" & TextTemp & "
" & TextTemp & "
" & TextTemp & "
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
How do I fix this? Thanks
I am very noob
Edit: My Option Explicit Is
Option Explicit
Dim IDCount As Integer
Dim LineCount As Integer
Dim FileText As String
Dim TextTemp
4 quotes ("""") escape a single quote (") so:
FileText = FileText & """" & Text1(Count) & """" & vbCrLf
(chr$(34) also outputs a ")

ThisWorkbook.Path for Mac returns (error 68)

I downloaded a spreadsheet which seems to be originally written for windows. The file is here http://www.automateexcel.com/2004/12/15/create_an_rss_feed_with_excel/.
For line RssLocation = ThisWorkbook.Path & "\" & FeedSheet.Cells(5, 2).Value
I have replaced "\" with with "/user/desktop/rsscreate.xlsm" but I still get the error.
I have also, tried "& Application.PathSeparator &" but still the error.
Any suggestions?
The code for the macro is below.
Sub WriteRss()
Dim X As Long
Dim FeedSheet As Worksheet
Dim RssLocation As String
Dim DomainName As String
Dim DomainDescription As String
Dim DomainTitle As String
'Change the word "Sheet1" to the tabname of
'the sheet where you keep your feeds list
Set FeedSheet = Sheets("Sheet1")
'Your domain name(include the http://)
DomainName = FeedSheet.Cells(2, 2).Value
'Your Site's Title
DomainTitle = FeedSheet.Cells(3, 2).Value
'Your Site's Description
DomainDescription = FeedSheet.Cells(4, 2).Value
'Location to write file, defaults to workbook directory
RssLocation = ThisWorkbook.Path & "\" & FeedSheet.Cells(5, 2).Value
'Kill the file if it already exists
If Len(Dir(RssLocation)) > 0 Then
Kill RssLocation
End If
Open RssLocation For Append As #1
Print #1, "<?xml version=""1.0""" & " encoding=""iso-8859-1""?>"
Print #1, "<rss version=" & """" & "2.0" & """" & _
" xmlns:content = ""http:" & _
"//purl.org/rss/1.0/modules/content/"">"
Print #1, " <channel>"
Print #1, " <title>" & DomainTitle & "</title>"
Print #1, " <link>" & DomainName & "</link>"
Print #1, " <description>" & DomainDescription & "</description>"
Print #1, " <language>en-us</language>"
'Loop through sheet specified
'Start # row 2
'ColumnA=Title, ColumnB=Link, ColumnC=Description
For X = 9 To FeedSheet.Range("A" & FeedSheet.Rows.Count) _
.End(xlUp).Row
Print #1, " <item>"
Print #1, " <title>" & FeedSheet.Cells(X, 1).Value & _
"</title>"
Print #1, " <link>" & FeedSheet.Cells(X, 2).Value & _
"</link>"
Print #1, "<description>"
Print #1, "<![CDATA["
Print #1, FeedSheet.Cells(X, 3).Value
Print #1, " ]]> "
Print #1, "</description>"
Print #1, " </item>"
Next
Print #1, " </channel>"
Print #1, "</rss>"
Close #1
MsgBox "Your new RSS feed can be found here: " & RssLocation
End Sub
Sub InsertNew()
Range("A9:C17").Select
Selection.Cut
Range("A10:C18").Select
ActiveSheet.Paste
Range("A18:C18").Select
Selection.Copy
Range("A9:C9").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End Sub
EDIT: adding the following from the Answers section.
I tried the code in previous answer. I'm still getting error at line If Len(Dir(RssLocation)) > 0
Any suggestions on how can use MacId and ThisWorkbook.Path instead of Applcaton.PathSeparator?. Siddharth your thoughts?
Try this (Untested)
RssLocation = ThisWorkbook.Path & "\" & FeedSheet.Cells(5, 2).Value
RssLocation = Replace(RssLocation ,"\", Application.PathSeparator)
'Debug.Print RssLocation

Ping script with email in vbs

i know i asked already the question about the ping script but now i have a new question about it :-) I hope someone can help me again.
strText = "here comes the mail message"
strFile = "test.log"
PingForever strHost, strFile
Sub PingForever(strHost, outputfile)
Dim Output, Shell, strCommand, ReturnCode
Set Output = CreateObject("Scripting.FileSystemObject").OpenTextFile(outputfile, 8, True)
Set Shell = CreateObject("wscript.shell")
strCommand = "ping -n 1 -w 300 " & strHost
While(True)
ReturnCode = Shell.Run(strCommand, 0, True)
If ReturnCode = 0 Then
Output.WriteLine Date() & " - " & Time & " | " & strHost & " - ONLINE"
Else
Output.WriteLine Date() & " - " & Time & " | " & strHost & " - OFFLINE"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "noreply#test.net"
objEmail.To = "test#test.net"
objEmail.Subject = "Computer" & strHost & " is offline"
objEmail.Textbody = strText
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"smtpadress"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End If
Wscript.Sleep 2000
Wend
End Sub
My problem is now, the mail comes all 2 seconds, when the computer are offline. Can someone show me how to make it with flags? So only one mail comes when its offline?
Thanks for your help.
Use a flag and report only when state changes
FLAG0 = "ON"
While(True)
ReturnCode = Shell.Run(strCommand, 0, True)
If ReturnCode = 0 Then
Output.WriteLine Date() & " - " & Time & " | " & strHost & " - ONLINE"
FLAG0 = "ON"
Else
Output.WriteLine Date() & " - " & Time & " | " & strHost & " - OFFLINE"
IF FLAG0 = "ON" THEN
FLAG0 = "OFF"
Set objEmail = CreateObject("CDO.Message")
...... rest of mailing code
END IF
End If

Resources