Array Definition Differences In VBScript - vbscript

I am trying to use ANSYS Maxwell Scripting via VBscript but I have a problem with the array definitions.
oModule.EditSetup "ParametricSetup1", Array("NAME:ParametricSetup1", "IsEnabled:=", _
true, Array("NAME:ProdOptiSetupDataV2", "SaveFields:=", false, "CopyMesh:=", false, "SolveWithCopiedMeshOnly:=", _
false), Array("NAME:StartingPoint"), "Sim. Setups:=", Array("Setup1"), Array("NAME:Goals", _
_
Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
Goals(i), "Name:=", "Goal" & cstr(i), Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a"))), _
Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
"avg(100 - Efficiency)", "Name:=", "Efficiency", Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a"))), _
Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
"avg(MassTotal)", "Name:=", "MassTotal", Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a"))), _
Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
"max(PhaseVoltage)", "Name:=", "PhaseVoltage", Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a"))), _
Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
"max(TorqueRipple)", "Name:=", "TorqueRipple", Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a"))), _
Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
"avg(st_length)", "Name:=", "StackLength", Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a"))), _
Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
"avg(L_q)/avg(L_d)", "Name:=", "Saliency", Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a")))))
This code is automatically generated via ANSYS and works great, however, I want to give the goals from variables in VBS so I wrote this.
Dim ArrS : ArrS = ArraySize + 1
Dim ANSYSGoals()
Redim ANSYSGoals(ArrS)
ANSYSGoals(0) = "NAME:Goals"
For i = 1 to ArraySize Step 1
ANSYSGoals(i) = Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
Goals(i-1), "Name:=", "Goal" & cstr(i-1), Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a")))
Next
oModule.EditSetup "ParametricSetup1", Array("NAME:ParametricSetup1", "IsEnabled:=", _
true, ANSYSGoals)
Although ANSYS accepts This kind of arrays (I had a code that does a similar thing but that code work) this piece of code is not working. However, if I change the code to this:
Dim ArrS : ArrS = ArraySize + 1
Dim ANSYSGoals()
Redim ANSYSGoals(ArrS)
ANSYSGoals(0) = "NAME:Goals"
For i = 1 to ArraySize Step 1
ANSYSGoals(i) = Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
Goals(i-1), "Name:=", "Goal" & cstr(i-1), Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a")))
Next
oModule.EditSetup "ParametricSetup1", Array("NAME:ParametricSetup1", "IsEnabled:=", _
true, Array(ANSYSGoals(0),ANSYSGoals(1),ANSYSGoals(2)))
It works. So my question is what is the difference between the 3 item array ANSYSGoals and Array(ANSYSGoals(0), ANSYSGoals(1), ANSYSGoals(2))?
Thank you in advance for your answers.

Related

Keep a VBScript window on top, as well as adding a logoff button

I have a piece of script, courtosey of the user Hackoo, but two things are wrong with it. First, the window needs to stay on top, it shouldn't be able to be exited from the taskbar, it needs to be on the bottom right corner of the screen (above the taskbar) and it needs to have a button on it below the text that says "Log off". Of course, the log off button needs to log off the computer. Here's the code:
Option Explicit
Dim Title,ws,nMinutes,nSeconds,sMessage
Title = "Session Timer"
Set ws = CreateObject("wscript.Shell")
nMinutes = 20
nSeconds = 0
sMessage = "<font color=Red size=2><b>You have"
'Open a chromeless window with message
with HTABox("lightBlue",100,250,0,630)
.document.title = "Session Timer"
.msg.innerHTML = sMessage
do until .done.value or (nMinutes + nSeconds < 1)
.msg.innerHTML = sMessage & "<br>" & nMinutes & ":" & Right("0"&nSeconds, 2) _
& " minutes of session time remaining</b></font><br>"
wsh.sleep 1000 ' milliseconds
nSeconds = nSeconds - 1
if nSeconds < 0 then
if nMinutes > 0 then
nMinutes = nMinutes - 1
nSeconds = 59
end if
end if
loop
.done.value = true
.close
end with
ws.Popup "Your session time has finished. You will now be logged off.","5",Title,0+48
'*****************************************************************
Function HTABox(sBgColor, h, w, l, t)
Dim IE, HTA, sCmd, nRnd
randomize : nRnd = Int(1000000 * rnd)
sCmd = "mshta.exe ""javascript:{new " _
& "ActiveXObject(""InternetExplorer.Application"")" _
& ".PutProperty('" & nRnd & "',window);" _
& "window.resizeTo(" & w & "," & h & ");" _
& "window.moveTo(" & l & "," & t & ")}"""
with CreateObject("WScript.Shell")
.Run sCmd, 1, False
do until .AppActivate("javascript:{new ") : WSH.sleep 10 : loop
end with 'WSHShell
For Each IE In CreateObject("Shell.Application").windows
If IsObject(IE.GetProperty(nRnd)) Then
set HTABox = IE.GetProperty(nRnd)
IE.Quit
HTABox.document.title = "HTABox"
HTABox.document.write _
"<HTA:Application contextMenu=no border=thin " _
& "minimizebutton=no maximizebutton=no sysmenu=no SHOWINTASKBAR=no >" _
& "<body scroll=no style='background-color:" _
& sBgColor & ";font:normal 10pt Arial;" _
& "border-Style:inset;border-Width:3px'" _
& "onbeforeunload='vbscript:if not done.value then " _
& "window.event.cancelBubble=true:" _
& "window.event.returnValue=false:" _
& "done.value=true:end if'>" _
& "<input type=hidden id=done value=false>" _
& "<center><span id=msg> </span><br>" _
& "<input type=button id=btn1 value=' OK ' "_
& "onclick=done.value=true><center></body>"
HTABox.btn1.focus
Exit Function
End If
Next
MsgBox "HTA window not found."
wsh.quit
End Function
Thanks,
Matthew
Note that i don't think that we can stay always on the top, but anyway just give a try for this modification, now you want it at the right corner not on the left and i added the button to Logoff the session:
Option Explicit
Dim Title,ws,nMinutes,nSeconds,sMessage,Command,Executer
Title = "Session Timer"
Set ws = CreateObject("wscript.Shell")
nMinutes = 20
nSeconds = 0
sMessage = "<font color=Red size=2><b>You have"
'Open a chromeless window with message
with HTABox("lightBlue",130,300,1070,600)
.document.title = "Session Timer"
.msg.innerHTML = sMessage
do until .done.value or (nMinutes + nSeconds < 1)
.msg.innerHTML = sMessage & "<br>" & nMinutes & ":" & Right("0"&nSeconds, 2) _
& " minutes of session time remaining</b></font><br>"
wsh.sleep 1000 ' milliseconds
nSeconds = nSeconds - 1
if nSeconds < 0 then
if nMinutes > 0 then
nMinutes = nMinutes - 1
nSeconds = 59
end if
end if
loop
.done.value = true
.close
end with
ws.Popup "Your session time has finished. You will now be logged off.","5",Title,0+48
Command ="cmd /c Shutdown.exe -l -f"
Executer = WS.Run(Command,0,False)
'*****************************************************************
Function HTABox(sBgColor,h, w, l, t)
Dim IE, HTA, sCmd, nRnd
randomize : nRnd = Int(1000000 * rnd)
sCmd = "mshta.exe ""javascript:{new " _
& "ActiveXObject(""InternetExplorer.Application"")" _
& ".PutProperty('" & nRnd & "',window);" _
& "window.resizeTo(" & w & "," & h & ");" _
& "window.moveTo(" & l & "," & t & ")}"""
with CreateObject("WScript.Shell")
.Run sCmd, 1, False
do until .AppActivate("javascript:{new ") : WSH.sleep 10 : loop
end with 'WSHShell
For Each IE In CreateObject("Shell.Application").windows
If IsObject(IE.GetProperty(nRnd)) Then
set HTABox = IE.GetProperty(nRnd)
IE.Quit
HTABox.document.title = "HTABox"
HTABox.document.write _
"<HTA:Application contextMenu=no border=thin " _
& "minimizebutton=no maximizebutton=no sysmenu=no SHOWINTASKBAR=no >" _
& "<body scroll=no style='background-color:" _
& sBgColor & ";font:normal 10pt Arial;" _
& "border-Style:inset;border-Width:3px'" _
& "onbeforeunload='vbscript:if not done.value then " _
& "window.event.cancelBubble=true:" _
& "window.event.returnValue=false:" _
& "done.value=true:end if'>" _
& "<input type=hidden id=done value=false>" _
& "<center><span id=msg> </span><br>" _
& "<input type=button id=btn1 value=' Log Off ' "_
& "onclick=done.value=true><center></body>"
HTABox.btn1.focus
Exit Function
End If
Next
MsgBox "HTA window not found."
wsh.quit
End Function

Solver VBA ignoring constraints and conditions on macOS

I have solver vba code working fine on Windows (Excel 2013), but there are some problems on macOS with Excel 2011. Here is a code :
SolverReset
SolverAdd CellRef:="$CB$2:$CB$" & LastRow, Relation:=5, FormulaText:="binary"
SolverAdd CellRef:="$CA$3", Relation:=1, FormulaText:="100000"
SolverAdd CellRef:="$CA$10", Relation:=2, FormulaText:="8"
SolverAdd CellRef:="$CA$7", Relation:=3, FormulaText:="3"
SolverAdd CellRef:="$CA$8", Relation:=3, FormulaText:="3"
SolverAdd CellRef:="$CA$9", Relation:=2, FormulaText:="=1"
SolverOptions MaxTime:=100, Iterations:=100, precision:=0.000001, Convergence:= _
0.0001, StepThru:=False, Scaling:=False, AssumeNonNeg:=True, Derivatives:=1
SolverOptions PopulationSize:=100, RandomSeed:=0, MutationRate:=0.075, Multistart _
:=False, RequireBounds:=True, MaxSubproblems:=0, MaxIntegerSols:=0, _
IntTolerance:=0, SolveWithout:=False, MaxTimeNoImp:=30
SolverOk SetCell:="$CA$4", MaxMinVal:=1, ValueOf:=0, ByChange:="$CB$2:$CB$" & LastRow,
_ Engine:=2, EngineDesc:="Simplex LP"
SolverSolve
Problem is that following conditions are missing from solver after applying above code :
SolverAdd CellRef:="$CB$2:$CB$" & LastRow, Relation:=5, FormulaText:="binary"
SolverOk SetCell:="$CA$4", MaxMinVal:=1, ValueOf:=0, ByChange:="$CB$2:$CB$" & LastRow,
_ Engine:=2, EngineDesc:="Simplex LP"
One interesting thing is that only SetCell and ByChange is not set up from second condition, but engine type "Simplex LP" is fine.
I got the code from by recording macro which I setted up manually, so there should not be any problems.
I managed to solve it after a lot of wasted time. It seems that there is a problem with "_" characted in :
SolverOk SetCell:="$CA$4", MaxMinVal:=1, ValueOf:=0, ByChange:="$CB$2:$CB$" & LastRow, _
Engine:=2, EngineDesc:="Simplex LP"
I solved it on following way :
SolverOk SetCell:="$CA$4", MaxMinVal:=1, ValueOf:=0, ByChange:="$CB$2:$CB$" & LastRow
SolverOk SetCell:="$CA$4", MaxMinVal:=1, ValueOf:=0, ByChange:="$CB$2:$CB$" & LastRow, _
Engine:=2, EngineDesc:="Simplex LP"

Number of query values and destination fields are not the same. Error Message

I'm having an error message with my codes in visual basic. Please help. Thanks.
The error says:
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim cmd As New OleDb.OleDbCommand
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
cmd.Connection = cnn
If Me.txtID.Tag & "" = "" Then
cmd.CommandText = "INSERT INTO ProfessorListTable(ID,LastName,FirstName,MI,Gender,Department,ContactNo,Address,EmailAddress,YearEmployed)" & _
" VALUES(" & Me.txtID.Text & ",'" & Me.txtLName.Text & "','" & _
Me.txtFName.Text & "','" & Me.txtMI.Text & "','" & _
Me.txtGender.Text & "','" & Me.txtDept.Text & "','" & _
Me.txtNo.Text & "','" & Me.txtAddress.Text & "','" & _
Me.txtEAdd.Text & "','" & Me.txtYear.Text & "',')"
cmd.ExecuteNonQuery()
Else
cmd.CommandText = "UPDATE ProfessorListTable " & _
" SET txtID=" & Me.txtID.Text & _
", LastName='" & Me.txtLName.Text & "'" & _
", FirstName='" & Me.txtFName.Text & "'" & _
", MI='" & Me.txtMI.Text & "'" & _
", Gender='" & Me.txtGender.Text & "'" & _
", Department='" & Me.txtDept.Text & "'" & _
", ContactNo='" & Me.txtNo.Text & _
", Address='" & Me.txtAddress.Text & "'" & _
", EmailAddress='" & Me.txtEAdd.Text & "'" & _
", YearEmployed='" & Me.txtYear.Text & _
" WHERE stdid=" & Me.txtID.Tag
cmd.ExecuteNonQuery()
End If
RefreshData()
End Sub
The
You had extra Comma (,) here
& Me.txtYear.Text & "','
So it's leads to 11 value instead of 10
And Address is reserved word so use it as [Address]
Try like this
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim cmd As New OleDb.OleDbCommand
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
cmd.Connection = cnn
If Me.txtID.Tag & "" = "" Then
cmd.CommandText = "INSERT INTO ProfessorListTable(ID,LastName,FirstName,MI,Gender,Department,ContactNo,[Address],EmailAddress,YearEmployed)" & _
" VALUES(" & Me.txtID.Text & ",'" & Me.txtLName.Text & "','" & _
Me.txtFName.Text & "','" & Me.txtMI.Text & "','" & _
Me.txtGender.Text & "','" & Me.txtDept.Text & "','" & _
Me.txtNo.Text & "','" & Me.txtAddress.Text & "','" & _
Me.txtEAdd.Text & "','" & Me.txtYear.Text & "')"
cmd.ExecuteNonQuery()
Else
cmd.CommandText = "UPDATE ProfessorListTable " & _
" SET txtID=" & Me.txtID.Text & _
", LastName='" & Me.txtLName.Text & "'" & _
", FirstName='" & Me.txtFName.Text & "'" & _
", MI='" & Me.txtMI.Text & "'" & _
", Gender='" & Me.txtGender.Text & "'" & _
", Department='" & Me.txtDept.Text & "'" & _
", ContactNo='" & Me.txtNo.Text & _
", [Address]='" & Me.txtAddress.Text & "'" & _
", EmailAddress='" & Me.txtEAdd.Text & "'" & _
", YearEmployed='" & Me.txtYear.Text & _
" WHERE stdid=" & Me.txtID.Tag
cmd.ExecuteNonQuery()
End If
RefreshData()
End Sub

What is wrong with this code that Windows 8 doesn't like, but Windows 7 runs fine?

Have errors on Line 59, Char 1.... "The Interface is Unknown"
The intent is to popup a simple user input box and capture the results into a variable, and then into a text file, so a 3rd party application can read it. I am not very good at coding VBS but I made this work perfectly in Windows 7.
I am looking to make this (VBscript) work in Windows 8 too. But I don't want to learn how to script or code in another language. I don't want to rewrite the whole thing in Javascript or .NET or whatever.
Please let me know what Windows 8 is doing differently from Windows 7 sp1.
Thanks.
'=======================[ ASK Password ]========================================'
Option Explicit
Dim strUserID, strPassword
AskPassword
Sub AskPassword()
Dim htmlPwdCode, objCodeFile, objFileSysObj, objBrowser, strButton
Const FOR_WRITING = 2
Set objFileSysObj = CreateObject("Scripting.FileSystemObject")
htmlPwdCode = "<SCRIPT LANGUAGE=" & Chr(34) & "VBScript" & Chr(34) & ">" & Chr(13) & _
"Sub RunScript" & Chr(13) & _
" OKClicked.Value = " & Chr(34) & "OK"& Chr(34) & Chr(13) & _
"End Sub" & Chr(13) & _
"Sub CancelScript" & Chr(13) & _
" OKClicked.Value = " & Chr(34) & "Cancelled" & Chr(34) & Chr(13) & _
"End Sub" & Chr(13) & _
"Sub Default_Buttons" & Chr(13) & _
" If Window.Event.KeyCode = 13 Then" & Chr(13) & _
" btnOK.Click" & Chr(13) & _
" End If" & Chr(13) & _
"End Sub" & Chr(13) & _
"</SCRIPT>" & Chr(13) & _
"<BODY onkeypress='vbs:Default_Buttons'><center><font size=" & Chr(34) & "2" & Chr(34) & " face=" & Chr(34) & "Arial" & Chr(34) & ">" & Chr(13) & _
"User name: " & Chr(13) & _
"<input type=" & Chr(34) & "text" & Chr(34) & " name=" & Chr(34) & "UserName" & Chr(34) & " size=" & Chr(34) & "30" & Chr(34) & "><br>" & Chr(13) & _
"Password : </font><font face=" & Chr(34) & "Arial" & Chr(34) & ">" & Chr(13) & _
"<input type=" & Chr(34) & "password" & Chr(34) & " name=" & Chr(34) & "UserPassword" & Chr(34) & _
" size=" & Chr(34) & "30" & Chr(34) & "></font></p>" & Chr(13) & _
"<input type=" & Chr(34) & "hidden" & Chr(34) & " name=" & Chr(34) & "OKClicked" & Chr(34) & " size = " & Chr(34) & "20" & Chr(34) & ">" & Chr(13) & _
"<input id=" & Chr(34) & "btnOK" & Chr(34) & " class=" & Chr(34) & "button" & Chr(34) & _
" type=" & Chr(34) & "button" & Chr(34) & " value=" & Chr(34) & " OK " & Chr(34) & _
" name=" & Chr(34) & "ok_button" & Chr(34) & " onClick=" & Chr(34) & "RunScript" & Chr(34) & ">" & Chr(13) & _
"<input id=" & Chr(34) & "btnCancel" & Chr(34) & " class=" & Chr(34) & "button" & Chr(34) & _
" type=" & Chr(34) & "button" & Chr(34) & " value=" & Chr(34) & "Cancel" & Chr(34) & _
" name=" & Chr(34) & "cancel_button" & Chr(34) & " onClick=" & Chr(34) & "CancelScript" & Chr(34) & "></center></BODY>"
Set objCodeFile = objFileSysObj.CreateTextFile("LoginPrompt.html", True)
objCodeFile.Write htmlPwdCode
objCodeFile.Close
Set objCodeFile = Nothing
Set objBrowser = CreateObject("InternetExplorer.Application")
With objBrowser
.Height = 200
.Width = 400
.Top = 200
.Left = 300
.StatusBar = True
.Toolbar = False
.Resizable = False
.Navigate CreateObject("Scripting.FileSystemObject").GetParentFolderName(Wscript.ScriptFullName) & "\LoginPrompt.html"
.Visible = True
End With
Do Until objBrowser.ReadyState = 4
'wait till page loads'
Loop
Do While objBrowser.Document.Body.All.OKClicked.Value = ""
Wscript.Sleep 50
Loop
strUserID = objBrowser.Document.Body.All.UserName.Value
strPassword = objBrowser.Document.Body.All.UserPassword.Value
strButton = objBrowser.Document.Body.All.OKClicked.Value
'''''''''''''''''''''''
Dim objFSO, strFile, objFile
Const ForWriting = 2
Const OpenAsASCII = 0
Const CreateIfNotExist = True
' Specify output file.
strFile = "C:\TEMP\MEX\UN.txt"
' Open the file.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, _
ForWriting, CreateIfNotExist, OpenAsASCII)
' write to file.
objFile.WriteLine strUserID
' Clean up.
objFile.Close
'''''''''''''''''''''''''''
Dim objFSO2, strFile2, objFile2
Const ForWriting2 = 2
Const OpenAsASCII2 = 0
Const CreateIfNotExist2 = True
' Specify output file.
strFile2 = "C:\TEMP\MEX\PW.txt"
' Open the file.
Set objFSO2 = CreateObject("Scripting.FileSystemObject")
Set objFile2 = objFSO2.OpenTextFile(strFile2, _
ForWriting2, CreateIfNotExist2, OpenAsASCII2)
' write to file.
objFile2.WriteLine strPassword
' Clean up.
objFile2.Close
'''''''''''''''''''''''''''
objBrowser.Quit
If strButton = "Cancelled" Then
MsgBox "Operation cancelled, script will now exit!"
Wscript.Quit
Else
'Credentials accepted for further processing
End If
objFileSysObj.DeleteFile "LoginPrompt.html", True
Set objBrowser = Nothing
Set objFileSysObj = Nothing
End Sub
'=======================[ GOT Password ]========================================'
Line 59: Do Until objBrowser.ReadyState = 4
The problem, according to MSDN: ReadyState Property Example (VBScript), is that the "ReadyState" feature has been removed.

VBScript If Instr with a recordset

I am trying to do an if statement with a recordset within VBScript to do a "like" compare a recordset.
While Not rs.EOF
result = result & "<tr style='" & FontStyle(FontFamily, FontSize) & _
" background-color: " & RowColors(number mod 2) & "'>" &_
Tdc(number) & Td(rs("Name")) & Tdc(rs("Machine Type")) & _
Tdc(ChooseStatusColor(rs("Backup Status"))) & _
Tdc(rs("Backup State")) & Td(rs("Last Backup Start")) & _
Td(rs("Last Backup End")) & _
If InStr(rs("Next Backup"), "*M") > 0 Then Td(rs("Next Backup")) Else Td(rs("Next Backup")) & "12:00:00 AM" & _
End If &_
"</tr>"
rs.MoveNext
number = number + 1
Wend
If I use just Td(rs("Next Backup")) & "12:00:00 AM" &_ it works fine but if I add the compare If Instr(rs("Next Backup"), "*M") > 0 then Td(rs("Next Backup")) Else Td(rs("Next Backup")) & "12:00:00 AM" &_, I get a VB compilation error. I am not sure where the error is in this logic or if I can even use a recordset in an InStr function. What am I doing wrong here?
I get the same result when I use multiple lines:
While Not rs.EOF
result = result & "<tr style='" & FontStyle(FontFamily, FontSize) & _
" background-color: " & RowColors(number mod 2) & "'>" & _
Tdc(number) & Td(rs("Name")) & Tdc(rs("Machine Type")) & _
Tdc(ChooseStatusColor(rs("Backup Status"))) & _
Tdc(rs("Backup State")) & Td(rs("Last Backup Start")) & _
Td(rs("Last Backup End")) & _
If InStr(1, (rs("Next Backup")), "*M") > 0 Then & _
Td(rs("Next Backup")) & _
Else Td(rs("Next Backup")) & "12:00:00 AM" & _
End If &_
"</tr>"
rs.MoveNext
number = number + 1
Wend
You can't inline conditionals like that in VBScript. Change your code to something like this:
While Not rs.EOF
result = result & "<tr style='" & FontStyle(FontFamily, FontSize) & _
" background-color: " & RowColors(number mod 2) & "'>" & _
Tdc(number) & Td(rs("Name")) & Tdc(rs("Machine Type")) & _
Tdc(ChooseStatusColor(rs("Backup Status"))) & _
Tdc(rs("Backup State")) & Td(rs("Last Backup Start")) & _
Td(rs("Last Backup End"))
If InStr(rs("Next Backup"), "M") > 0 Then
result = result & Td(rs("Next Backup"))
Else
result = result & Td(rs("Next Backup") & "12:00:00 AM")
End If
result = result & "</tr>"
rs.MoveNext
number = number + 1
Wend

Resources