Switch between IE browser tabs for specific time intervals using script - vbscript

Currently I'm using IE 11, I have 4 displays opened. I want to toggle between the tabs for specific intervals of time. We want this setup for monitoring purpose. I need a script for this task.

Kindly refer the following code :
set shellApp = createobject("shell.application")
do
for each sTitle in Array("v9", "Google", "Gmail", "ETC")
ShowIEWindow sTitle, shellApp, 10 ' sec
next
loop ' forever
sub ShowIEWindow(sTitle, oShell, nWaitsec)
for each w in oShell.windows
with w
if lCase(.LocationName) = lcase(sTitle) and InStr(lCase(.FullName),"iexplore") > 0then
w.Refresh
'w.visible = true ' show
wsh.sleep nWaitsec * 1000 ' milliseconds
' w.visible = false ' hide
end if
end with
next
end sub
Above code will refresh tabs that specified in the array if they are opened in internet explorer.
Now, instead of Refreshing the window, you need to find method that switches between different tabs.
I also tested the above code and working for me. Hope this will helps !! :)

Related

VB6 Debug Version works fine, compiled version wont start

I compile VB6 programs on Windows 10 regularly. I currently have a project which has worked on an old machine but I want to migrate this to new hardware and therefore a new windows install.
I have the code working fine when I run it in debug but as soon as I compile (and run as admin which is what I normally do to make sure registry values are retrieved correctly) it seems to get stuck. CPU usage goes up to 25% which is about double what is normal and the form never loads.
I have gone through the code and started commenting out lines to see what starts to make it work. Looking at the sub below this code works however if I uncomment any of the commented lines then it fails. I could understand this if maybe there was a loop or something which it gets stuck in but one of the lines is on;y changing the caption of the form!
As I mentioned earlier I think I have probably compiled projects on hardware and the windows install image 40-50 times never with this problem. What I don't understand for instance is why the frmlogin.show line is ok when me.show isnt?
The double commented lines are actual comments by the way.
Public Sub StartMainForm()
Dim x As Integer
FirstUpdate = True
' ' Lees de trek iconen in de imagelist in
'
' For x = 1 To 15
' imageListIcon.ListImages.Add x, "Icon" & Format(x, "00"), LoadResPicture(22000 + x, vbResIcon)
' Next x
'
' ' Scherm opbouw
'
' InitAssenControles
' Form_Resize
' ClearSelectie
'
' ' Form_Resize
' Me.Show
' Me.WindowState = vbMaximized
' DataBaseNaam = G.SDataFile
' Me.Caption = Replace(DataBaseNaam, ".MDB", "")
'
' ' start Update
'
' timStatusUpdate.Interval = gUpdateTime
' timStatusUpdate.Enabled = True
DoEvents
gCurrentUser = True
G.LoginName = "Supervisor"
G.Auth1 = True
G.Auth2 = True
G.Auth3 = True
G.Auth4 = True
G.Auth5 = True
G.Auth6 = True
G.Auth7 = True
G.Auth8 = True
G.Auth9 = True
G.Auth10 = True
frmLogin.Show vbModal
InitAssenControles
gAssenServer.SetNetwerkKast gNetwerkNummer
Exit Sub
End Sub

Reading and writing an INI file

I have been toying with the below script to be able to read settings for use with my HTA (creating a game launcher).
Here is my current HTA:
http://pastebin.com/skTgqs5X
It doesn't quite work, it complains of the WScript object being required. While I understand Echo will not work like that in a HTA I am having trouble modifying the code so it will work. Even just removing all Echo references it still has an issue with objOrgIni on line 200 of the below code (with the WScript references removed):
http://pastebin.com/pGjv4Gh1
I don't even need that level of error checking as the INI will exist etc, I just need a simple way to read from and write to an INI in my scripting. Any help you guys can give me in achieving that would be great, it's a little advanced for me just yet, but I'd love an explanation as to why it fails.
There is no easy way to use INI files with VBScript. You'd have to write the functionality yourself or find some existing code that does it.
But do you really need an INI specifically or just a way to save settings? You could just keep all of your settings in a Dictionary object and serialize it as needed.
For example, here are two functions -- LoadSettings and SaveSettings -- that do just that.
Public Function LoadSettings(strFile)
Set LoadSettings = CreateObject("Scripting.Dictionary")
Dim strLine, a
With CreateObject("Scripting.FileSystemObject")
If Not .FileExists(strFile) Then Exit Function
With .OpenTextFile(strFile)
Do Until .AtEndOfStream
strLine = Trim(.ReadLine())
If InStr(strLine, "=") > 0 Then
a = Split(strLine, "=")
LoadSettings.Add a(0), a(1)
End If
Loop
End With
End With
End Function
Sub SaveSettings(d, strFile)
With CreateObject("Scripting.FileSystemObject").CreateTextFile(strFile, True)
Dim k
For Each k In d
.WriteLine k & "=" & d(k)
Next
End With
End Sub
Imagine you had the following settings file saved at c:\settings.txt:
Count=2
Name=Obama
You'd use the functions above like this:
Const SETTINGS_FILE = "c:\settings.txt"
Dim Settings
Set Settings = LoadSettings(SETTINGS_FILE)
' Show all settings...
WScript.Echo Join(Settings.Keys, ", ") ' => Count, Name
' Query a setting...
WScript.Echo Settings("Count") ' => 2
' Update a setting...
Settings("Count") = Settings("Count") + 1
' Add a setting...
Settings("New") = 1
' Save settings...
SaveSettings Settings, SETTINGS_FILE

Dynamic Link in UFT automation?

I want to write a dynamic VBScript for my web automation in UFT 12.02. I would like to pass a dynamic value as part of the link. here is my sample Line code:
set ObjExcel = CreateObject("Excel.application")
ObjExcel.workbooks.open "F:\Automation\Web\Business\WebTestData.xls"
For Curr= 1 To 20
USD = ObjExcel.sheets(1).cells(Curr,1).Value
If Browser("...").Page("...").Exist Then
Browser("...").Page("...").WebElement("WebElement").Click
'Attempt to click on Drop Down Link
Browser("...").Page("...").Link("USD").Click
End If
Next
"USD" will keep changing, i.e. I will be picking it from Excel.
Expected Result:
Generate a script that will attempt to click on different links as below:
Browser("...").Page("...").Link("EURO").Click
Browser("...").Page("...").Link("BP").Click
Browser("...").Page("...").Link("AED").Click
Browser("...").Page("...").Link("KSH").Click
Browser("...").Page("...").Link("IR").Click
Yes, you should use USD without double quote.
Dim currType, ObjExcel
set ObjExcel = CreateObject("Excel.application")
ObjExcel.workbooks.open "F:\Automation\Web\Business\WebTestData.xls"
For Curr= 1 To 20
currType = ObjExcel.sheets(1).cells(Curr,1).Value
If Browser("...").Page("...").Exist Then
Browser("...").Page("...").WebElement("WebElement").Click
'Attempt to click on Drop Down Link
Browser("...").Page("...").Link(currType).Click
End If
Next
set ObjExcel = Nothing
Note: I've changed USD with currType.
I have zero experience with UFT, but shouldn't using the variable USD instead of the string "USD" do what you want?
For Curr= 1 To 20
USD = ObjExcel.sheets(1).cells(Curr,1).Value
If Browser("...").Page("...").Exist Then
Browser("...").Page("...").WebElement("WebElement").Click
'Attempt to click on Drop Down Link
Browser("...").Page("...").Link(USD).Click
End If
Next

Reduced performance when creating object in classic asp

Trying to measure a website performance I created a simple logging sub to see what parts are slow during the execution of a classic asp page.
sub log(logText)
dim fs, f
set fs = Server.CreateObject("Scripting.FileSystemObject")
set f = fs.OpenTextFile("log.txt", 8, true)
f.WriteLine(now() & " - " & logText)
f.Close
set f = Nothing
set fs = Nothing
end sub
log "Loading client countries"
set myR = Server.CreateObject("ADODB.RecordSet")
myR.ActiveConnection = aConnection
myR.CursorLocation=2
myR.CursorType=3
myR.LockType=2
myR.Source = "SELECT * FROM CC ORDER BY ccName ASC"
log "Opening db connection"
myR.open()
log "Opened db connection"
Here are the results (only showing the time part):
...
11:13:01 - Loading client countries
11:13:06 - Opening db connection
11:13:06 - Opened db connection
...
Creating the ADODBRecordSet and setting a few properties takes about 5 seconds. This does not always happen, sometimes the code is executed fast, but usually when I reload the page
after a few minutes the loading times are more or less the same as the example's. Could this really be a server/resources issue or should I consider rewriting the code? (My best option would be to write this in C#, but I have to study this code first before moving forward anyway).
Update: I added more code after receiving 1st comment to present a few more code. Explanation: The code creates a combobox (selection menu) with the retrieved countries (it continues where the previous piece of code stopped).
if not myR.eof then
clientCountries = myR.getrows
send("<option value='0'>Select country</option>")
log "Creating combobox options"
for i = 0 to ubound(clientCountries, 2)
if cstr(session("clientCountry")) <> "" then
if cstr(clientCountries(1, i)) = cstr(session("clientCountry")) then
isSelected = "selected" else isSelected = ""
end if
end if
if cstr(session("clientCountry")) = "" then
if cstr(clientCountries(1, i)) = "23" then
isSelected = "selected"
else
isSelected = ""
end if
end if
optionString = ""
optionString = clientCountries(2, i)
send("<option value='" & clientCountries(1, i) & "' " & isSelected & ">" & convertToProperCase(optionString) & "</option>")
next
log "Created combobox options"
end if
myR.Close
myR.ActiveConnection.close
myR.ActiveConnection = nothing
set myR = nothing
log "Loaded client countries"
The next two log entries are as follows:
11:13:06 - Creating combobox options
11:13:06 - Created combobox options
...
So far, the SELECT query as the rest of the page (2 or 3 queries more) is executed within the next second more or less. The only part slowing the page down is what you can see in the first part of the log. I'm not sure if I can profile the SQLServer, because I only have cPanel access. This is the only way I know of, unless there's something else I could have a look at.
First, Check your connection string, I've experienced slower times with certain providers. The best provider I've found for classic asp is sqloledb
Second, I would close my SQL object before I did the For statement on the GetRows() array. You don't want to keep that open if you don't need to.
Third, I'd use stored procedures. You'll get a performance improvement by saving on compile time.
Fourth, I would avoid doing a SELECT * statement at all cost, instead I would return ONLY the columns I need. (Your code looks like it only needs 2 columns)
Fifth, I would build indexes on the tables taking longer than expected.
If this doesn't resolve the issue, I would consider other languages/solutions. Not sure what the dataset looks like, so can't say if a flat-file database should be considered or not.
Also, try this for a recordset instead and see what happens:
Set myR = Server.CreateObject("Adodb.Recordset")
myR.Open "SELECT * FROM CC ORDER BY ccName ASC", aConnection
If myR.RecordCount > 0 Then clientCountries = myR.GetRows()
myR.Close
Set myR = Nothing
If IsArray(myR) Then
For ....

VB6 application : WebBrowser.Navigate refresh every 3 minutes

I am making an application using VB6 in which a WebBrowser window is launched using this code:
Private Sub Form_Load()
WebBrowser1.Navigate ("http://google.com")
End Sub
How can I make the window refresh the same url every let's say 3 minutes ?
I know it should be something well known but i am still searching my way through VB programming
You don't need 2 timers. just have a global variable globalTimer As Date that keeps the last time you navigated
You can set Timer1 to run every second or minute. To be more accurate, I recommend every second.
Dim globalTimer As Date
...
Private Sub Timer1_Timer()
If Now >= DateAdd("n", 3, globalTimer) Then ' its been at least 3 minutes since last Navigation
WebBrowser1.Navigate ("http://google.com") ' Navigate
globalTimer = Now ' store the new navigation time
End If
End Sub
You can use a timer to run code at a regular interval.
As the VB6 timer has a maximum interval of ~65s, you can set it to a 60,000ms interval, and keep a separate counter and when it gets to 3, reset it back to 0 and perform a refresh.
Private Sub Timer_Timer
'Increment minute count
FireCount = FireCount + 1
If FireCount = 3 then
'Reset to 0 for next time
FireCount = 0
'Refresh web browser
End If
End Sub

Resources