Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global Variable value not retaining

Status
Not open for further replies.

stonym

Technical User
Sep 13, 2011
3
US
I am creating a web page that performs a login to a outside source when clicking a Login button and then I want to perform a logout when clicking another button. The login succeeds fine but the values for the object is not retaining when the sub is exited. I declared the variable outside of the sub. Anything else I'm supposed to do? See code below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Home</title>
<style type="text/css">

p.margin
{
margin-left:87px;
}
</style>
<SCRIPT language="VBScript">
Dim QCConnection
Sub cmdLogin_OnClick
Set QCConnection = CreateObject("TDAPIOLE80.TDConnection.1")
QCConnection.InitConnectionEx " QCConnection.login frmLoginPage.txtLoginName.Value, frmLoginPage.txtPassword.Value 'This returns success
If (Not QCConnection.LoggedIn) Then
MsgBox Err.Description, vbOK, "Quality Center Login"
Exit Sub
end if
QCConnection.Connect frmLoginPage.cboDomain.options(frmLoginPage.cboDomain.SelectedIndex).Text, frmLoginPage.cboProj.options(frmLoginPage.cboDomain.SelectedIndex).Text 'This returns success
if (Not QCConnection.ProjectConnected) then
MsgBox Err.Description, vbOK, "Quality Center Login"
Exit Sub
end if
End Sub

Sub cmdLogout_OnClick
QCConnection.Disconnect 'gives error that there isn't a connection
QCConnection.Logout
QCConnection.ReleaseConnection
End Sub
</SCRIPT>
</head>

<h1><center><b><big>Automated Test Runs</big></b></center></h1>
<body>
<form Name=frmLoginPage>
<p>Quality Center Login</p>
<p>Login Name:&nbsp;&nbsp;<input size="30" name="txtLoginName"></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;Password:&nbsp;&nbsp;<input size="30" type=password name="txtPassword"></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Domain:&nbsp;&nbsp;<select name="cboDomain"><option>School_Systems</select></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Project:&nbsp;&nbsp;<select name="cboProj"><option>PSX_2010</select></p>
<p class="margin"><button type="submit" style="height: 25px; width: 100px" name="cmdLogin">Login</button><p>
<p class="margin"><button type="submit" style="height: 25px; width: 100px" name="cmdLogout">Logout</button><p>
</form>
</body>
</html>
 
Set QCConnection outside the cmdLogin_OnClick

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Thanks Geates but I had tried that and it didn't make a difference.
 
Bummer...
My suggestions are just shots in the dark on this one...

Form element values are populated in real time. No need to submit the form. There is no reason for the buttons to have a type. Also, each element value is being accessed by name (frmLoginPage.cboDomain.selectedIndex) - further need to not have a button type.


Code:
<p class="margin"><button [s][red]type="submit"[/red][/s] style="height: 25px; width: 100px" name="cmdLogin">Login</button><p>
<p class="margin"><button [s][red]type="submit"[/red][/s]  style="height: 25px; width: 100px" name="cmdLogout">Logout</button><p>

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Hmmm. Perhaps it has something to do with the rest of the code in the cmdLogin_OnClick. I would comment the rest of it out and msgbox isObject() to see if QCConnection is available in both subs. Then "comment in" each command until isObject returns false.

Code:
...
<SCRIPT language="VBScript">
	dim QCConnection
    
	Sub cmdLogin_OnClick
        Set QCConnection = CreateObject("TDAPIOLE80.TDConnection.1")
		msgbox isObject(QCConnection)
		'QCConnection.InitConnectionEx "[URL unfurl="true"]http://myserver"[/URL]
		'QCConnection.login frmLoginPage.txtLoginName.Value, frmLoginPage.txtPassword.Value 'This returns success
		'If (Not QCConnection.LoggedIn) Then
		'	MsgBox Err.Description, vbOK, "Quality Center Login"
		'	Exit Sub
        'end if        
   
		'QCConnection.Connect frmLoginPage.cboDomain.options(frmLoginPage.cboDomain.SelectedIndex).Text, frmLoginPage.cboProj.options(frmLoginPage.cboDomain.SelectedIndex).Text 'This returns success
		'if (Not QCConnection.ProjectConnected) then
		'	MsgBox Err.Description, vbOK, "Quality Center Login"
		'	Exit Sub
        'end if        
	End Sub
    
	Sub cmdLogout_OnClick
		msgbox isObject(QCConnection)
		'QCConnection.Disconnect 'gives error that there isn't a connection
		'QCConnection.Logout
		'QCConnection.ReleaseConnection
	End Sub
</SCRIPT>
...

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Taking the type="submit" out for the buttons did the trick. Thanks for all your help.
 
Ah, actually, that would make sense. What happens to an HTML document when a form is submitted? It get's reloaded, thus any previously defined elements would be redefined!

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top