I'm trying to add some data that is pulled from a database in the format of HH:MM:SS I'm trying to get them to add together so if we have 00:00:05 then 00:00:10 so we have 00:00:15
I have attempted both TimeSpan, DateTime but I get the following error:
Microsoft VBScript runtime error '800a01a8'
Object required: 'TimeSpan'
Script Location, line 157
This is the code:
While Not objRS.EOF
activecalls = activecalls + objRS("talkingagents")
callswaiting = callswaiting + objRS("callswaiting")
averagetalkingtime = averagetalkingtime + objRS("convavgtalkduration")
totalqueue = totalqueue + 1
totalcalls = totalcalls + objRS("totalcalls")
newWait = objRS("convavgwaitduration")
TimeSpan t1 = TimeSpan.Parse(newWait)
TimeString FormattedDate = t1.Add(FormattedDate)
timeString = timeString.Add(t1).ToString("dd\.hh\:mm\:ss")
Not clear with your code but this probably what you are looking for.
t1 = CDate("00:00:05")
t2 = CDate("00:00:10")
t3 = t1 + t2
MsgBox Right("00" & Hour(t3), 2) + ":" + Right("00" & Minute(t3), 2) + ":" + Right("00" & Second(t3), 2)
Related
Below is my query which is created in .Net code for insertion in oracle table. I found other related articles but they are different and not answering this. I was creating below query using a datatable.
`Public Sub UpdateOracleRecordset(dtTable As DataTable)
Dim sql As String = String.Empty
Dim i As Integer = 0
sql = "insert into " + dtTable.TableName + "("
For Each dc As DataColumn In dtTable.Columns
sql = sql + dc.ToString() + ","
Next
sql = sql.TrimEnd(",") + ")" + " select "
Dim rowVal As String = String.Empty
For Each dtRow As DataRow In dtTable.Rows
For Each dc As DataColumn In dtTable.Columns
rowVal = rowVal + dtRow(dc).ToString() + ","
Next
rowVal = rowVal.TrimEnd(",")
Next
sql = sql + rowVal
ExecuteSQL(sql)
End Sub`
"insert into CS_INV(LOANNO,CASENUMBER,INQ_TYPE,FUP_REASON,FUP_DATE,FUP_PROM,USERID,DATA_DAT,UNIT) values ( 5735985,103550709,399,58,9/24/2018 1:37:01 AM,9/25/2018 12:00:00 AM,Anurag,9/24/2018 1:37:08 AM,1 ) "
Wenfried is right and I used prepared statements which helped to resolve the issue
Dim conn As New OracleConnection(oradb)
conn.Open()
Dim sql As String = String.Empty
Dim sqlValues As String = String.Empty
Dim i As Integer = 0
sql = "insert into " + dtTable.TableName + "("
For Each dc As DataColumn In dtTable.Columns
sql = sql + dc.ToString() + ","
sqlValues = sqlValues + ":" + dc.ToString() + ","
Next
sql = sql.TrimEnd(",") + ")" + " values ( " + sqlValues.TrimEnd(",") + ")"
Dim commandText = sql
Dim Command As New OracleCommand(sql, conn)
For Each dtRow As DataRow In dtTable.Rows
For Each dc As DataColumn In dtTable.Columns
Command.Parameters.Add(New OracleParameter(dc.ToString(), dtRow(dc)))
Next
Next
Command.ExecuteNonQuery()
conn.Close()
i try to make auto number based on format string, date and counter like USR20180815001, USR20180815002, when the day/date change it reset the counter to USR20180806001, USR20180806001, and so on. here is my code so far....
Sub AutomaticNumber()
Call Connection
Set Rs_User = New ADODB.Recordset
Rs_User.Open "SELECT * FROM TBL_USER WHERE id_user IN (SELECT
MAX(id_user)FROM TBL_USER)ORDER BY id_user DESC", Conn
Rs_User.Requery
Dim x As String * 15
Dim count As Long
With Rs_User
If .EOF Then
x = "USR" + Format(Date, "yyyymmdd") + "001"
NewNumber = x
Else
If Left(!id_user, 8) <> Format(Date, "yyyymmdd") Then
x = "USR" + Format(Date, "yyyymmdd") + "001"
Else
Count = Right(!id_user, 3) + 1
x = "USR" + Format(Date, "yyyymmdd") + Right("00" &
Count, 2)
End If
End If
NewNumber = x
End With
End Sub
this code can result USR20180805001, but when i try to add another record to databases, it can not add since the code failed to counter/increase the last 3 digit on the right. hence show error duplicate entry. thank you for the attention.
I have a script that is running on login to do some profile manipulation and it's returning an incorrect SID. When a do the same with powershell, I get the correct SID. I've been researching for a day solid now and cannot seem to determine what part of this script would cause an incorrect SID to be returned.
Could it be something with the domain infrastructure?
Given a good SAM below, I'm getting a good SID returned, but it's not the correct SID. There is no SID history for this user object, so I'm perplexed as to why I'm getting an incorrect SID.
'* Build LDAP query to lookup user
Set rootDSE = GetObject("LDAP://RootDSE")
base = "<LDAP://" & rootDSE.Get("defaultNamingContext") & ">"
'* Filter on user objects with the given account name
fltr = "(&(objectClass=user)(objectCategory=Person)" & _
"(sAMAccountName=" & strSamAccountName & "))"
'* Add other attributes according to your requirements
attr = "distinguishedName,sAMAccountName,objectSid,userPrincipalName"
scope = "subtree"
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADsDSOObject"
conn.Open "Active Directory Provider"
Set cmd = CreateObject("ADODB.Command")
Set cmd.ActiveConnection = conn
cmd.CommandText = base & ";" & fltr & ";" & attr & ";" & scope
outFile.WriteLine("Command Text" & cmd.CommandText)
outFile.WriteLine()
'* Retrieve SID from user object, convert to decimal and hex values
Set rs = cmd.Execute
Do Until rs.EOF
arrSid = rs.Fields("objectSid").Value
strSidHex = OctetToHexStr(arrSid)
strSidDec = HexStrToDecStr(strSidHex)
'strUPN = rs.Fields("userPrincipalName").Value
Dim objTranslator
Set objTranslator = CreateObject("NameTranslate")
objTranslator.Init 3, ""
objTranslator.Set 3, strUPN
strGUID = objTranslator.Get(7)
outFile.WriteLine("DN: " & rs.Fields("distinguishedName").Value)
outFile.WriteLine("SID: " & strSidDec)
outFile.WriteLine("UPN: " & rs.Fields("userPrincipalName").Value)
outFile.WriteLine()
rs.MoveNext
Loop
rs.Close
conn.Close
'* Function to convert OctetString (byte array) to Hex string.
Function OctetToHexStr(arrbytOctet)
Dim k
OctetToHexStr = ""
For k = 1 To Lenb(arrbytOctet)
OctetToHexStr = OctetToHexStr _
& Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
Next
End Function
'* Function to convert hex Sid to decimal (SDDL) Sid.
Function HexStrToDecStr(strSid)
Dim arrbytSid, lngTemp, j
ReDim arrbytSid(Len(strSid)/2 - 1)
For j = 0 To UBound(arrbytSid)
arrbytSid(j) = CInt("&H" & Mid(strSid, 2*j + 1, 2))
Next
HexStrToDecStr = "S-" & arrbytSid(0) & "-" _
& arrbytSid(1) & "-" & arrbytSid(8)
lngTemp = arrbytSid(15)
lngTemp = lngTemp * 256 + arrbytSid(14)
lngTemp = lngTemp * 256 + arrbytSid(13)
lngTemp = lngTemp * 256 + arrbytSid(12)
HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)
lngTemp = arrbytSid(19)
lngTemp = lngTemp * 256 + arrbytSid(18)
lngTemp = lngTemp * 256 + arrbytSid(17)
lngTemp = lngTemp * 256 + arrbytSid(16)
HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)
lngTemp = arrbytSid(23)
lngTemp = lngTemp * 256 + arrbytSid(22)
lngTemp = lngTemp * 256 + arrbytSid(21)
lngTemp = lngTemp * 256 + arrbytSid(20)
HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)
lngTemp = arrbytSid(25)
lngTemp = lngTemp * 256 + arrbytSid(24)
HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)
End Function
Your function HexToDecStr() assumes that a binary SID will always be 26 bytes long. That isn't necessarily true. Try this instead:
Function DecodeSID(binSID)
Dim i, sid
ReDim bytes(LenB(binSID))
For i = 1 To LenB(binSID)
bytes(i-1) = AscB(MidB(binSID, i, 1))
Next
sid = "S-" & CStr(bytes(0)) & "-" & _
Arr2Str(Array(bytes(2), bytes(3), bytes(4), bytes(5), bytes(6), bytes(7)))
For i = 8 To (4 * bytes(1) + 4) Step 4
sid = sid & "-" & Arr2Str(Array(bytes(i+3), bytes(i+2), bytes(i+1), bytes(i)))
Next
DecodeSID = sid
End Function
Function Arr2Str(arr)
Dim i, v
v = 0
For i = 0 To UBound(arr)
v = v * 256 + arr(i)
Next
Arr2Str = CStr(v)
End Function
Is there a function to convert a specified number of seconds into a week/day/hour/minute/second time format in vbscript?
eg: 969234 seconds = 1wk 4days 5hrs 13mins 54secs
Dim myDate
dim noWeeks
dim noDays
dim tempWeeks
dim pos
myDate = DateAdd("s",969234,CDate(0))
tempWeeks = FormatNumber(myDate / 7,10)
pos = instr(tempWeeks, ".")
if pos > 1 then
tempWeeks = left(myDate, pos -1)
end if
noWeeks = Cint(tempWeeks)
noDays = Cint(((myDate / 7) - noWeeks) * 7)
wscript.echo noWeeks & "wk " & noDays & "days " & datepart("h", myDate) & "hrs " & datepart("n", myDate) & "mins " & datepart("s", myDate) & "secs"
No built in function to do that.
Here is a quick and dirty one:-
Function SecondsToString(totalSeconds)
Dim work : work = totalSeconds
Dim seconds
Dim minutes
Dim hours
Dim days
Dim weeks
seconds = work Mod 60
work = work \ 60
minutes = work Mod 60
work = work \ 60
hours = work Mod 24
work = work \ 24
days = work Mod 7
work = work \ 7
weeks = work
Dim s: s = ""
Dim renderStarted: renderStarted = False
If (weeks <> 0) Then
renderStarted = True
s = s & CStr(weeks)
If (weeks = 1) Then
s = s & "wk "
Else
s = s & "wks "
End If
End If
If (days <> 0 OR renderStarted) Then
renderStarted = True
s = s & CStr(days)
If (days = 1) Then
s = s & "day "
Else
s = s & "days "
End If
End If
If (hours <> 0 OR renderStarted) Then
renderStarted = True
s = s & CStr(hours)
If (hours = 1) Then
s = s & "hr "
Else
s = s & "hrs "
End If
End If
If (minutes <> 0 OR renderStarted) Then
renderStarted = True
s = s & CStr(minutes)
If (minutes = 1) Then
s = s & "min "
Else
s = s & "mins "
End If
End If
s = s & CStr(seconds)
If (seconds = 1) Then
s = s & "sec "
Else
s = s & "secs "
End If
SecondsToString = s
End Function
You wantto use timer pseudo-variable :
start = timer
Rem do something long
duration_in_seconds = timer - start
wscript.echo "Duration " & duration_in_seconds & " seconds."
In Powerdesign would like to create a VBscript to rename/reform the following names in powerdesigner- Conceptural or Physical model
Alternative/Unique Key Name:
UQ {table_name} {tablecolumnname} ///////
Example = UQ_Account_AccountNumber
Relationship Name:
FK_{table_name}_{reference_table_name}_{reference_column_name}
//////Example = FK_Account_AccountPhone_HomePhoneID
Problem is, how do I get the "table_column_name" and "reference_column_name"?
Here's something I used to rename the 'friendly' names, plus the constraint names of all my references. Maybe it will help you out.
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
Dim mdl
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no current Model"
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
MsgBox "The current model is not a Physical Data model."
Else
ProcessFolder mdl
End If
Private sub ProcessFolder(folder)
Dim Tab, Key, Rel
for each Rel in Folder.References
Rel.ForeignKeyConstraintName = "FK_" + UCASE(Rel.ParentTable.Name) + "_" + UCASE(Rel.ParentKeyColumnList) + "_" + UCASE(Rel.ChildTable.Name) + "_" + UCASE(Rel.ForeignKeyColumnList)
Rel.Name = "FK_" + UCASE(Rel.ParentTable.Name) + "_" + UCASE(Rel.ParentKeyColumnList) + "_" + UCASE(Rel.ChildTable.Name) + "_" + UCASE(Rel.ForeignKeyColumnList)
next
end sub