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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WaitForKeys and VB.Net 2

Status
Not open for further replies.

cbouknight

Programmer
Jan 5, 2008
12
US
I'm trying to use WaitForKeys as follows:

Code:
Proceed = Screen1.WaitForKeys(9000, "<Tab>")

If Proceed Then
   MessageBox.Show("Done.")
Else
   MessageBox.Show("No key pressed in 9 seconds.")
End If

I have "proceed" declared as boolean.

However, on executing the code, I get an error stating "Conversion from type '_ComObject' to type 'Boolean' is not valid."

How can I properly use this properly?
 
Hi,

Did you check Attachmate HELP???
[tt]
Return Value Description

UserKeys
The UserKeys keys that the user pressed.
empty string Indicates that no key was pressed within the specified time or that the key that the user pressed was not one of the UserKeys you supplied in the WaitForKeys method syntax.[/tt]

Copyright 1996 - 1999, Attachmate Corporation. All rights reserved.

Skip,
[sub]
[glasses]I'll be dressed to the nines this week, as I go to have my prostatectomy...
Because, if I'm gonna BE impotent, I want to LOOK impotent![tongue][/sub]
 
Yes. I read the help file as well as the document file before posting here, but I am still stuck since the example given in the document file was not very clear, and it is difficult to see how it translates to VB.Net.
 



Help CLEARLY answers your question,

"I have "proceed" declared as boolean.

However, on executing the code, I get an error stating "Conversion from type '_ComObject' to type 'Boolean' is not valid."

How can I properly use this properly?

Skip,
[sub]
[glasses]I'll be dressed to the nines this week, as I go to have my prostatectomy...
Because, if I'm gonna BE impotent, I want to LOOK impotent![tongue][/sub]
 
Still can't figure it out. Can you please give me an example?

If I do this:

Code:
Screen1.WaitForKeys(9000, "<Tab>")
MessageBox.Show("Done.")

It waits for nine seconds for the tab key to be pressed. Either way, the sub continues afterwards. What I am trying to do is prevent it from continuing if the tab key is NOT pressed. But I cannot figure out how to do this. The example uses WaitForKey$, which I am assuming is a string variable. However, assigning Screen1.WaitForKeys(9000, "<Tab>") to a string returns an error. Assigning it to an Object causes the code to immediately show the message box even though nine seconds has not elasped nor a key been pressed.

I guess it would really help if I knew for sure what type WaitForKey$ should be in Vb.Net since it does not use $. The help does not indicate what type WaitForKey$ is.
 





"I guess it would really help if I knew for sure what type WaitForKey$ should be in Vb.Net since it does not use $. The help does not indicate what type WaitForKey$ is."

If you read the help, it implicitly tells you what type of return value. My post from help has the answer!!!

If you cannot figure this out, you should not attempt to do this at home or any where else.

Skip,
[sub]
[glasses]I'll be dressed to the nines this week, as I go to have my prostatectomy...
Because, if I'm gonna BE impotent, I want to LOOK impotent![tongue][/sub]
 
cbouknight said:
I have "proceed" declared as boolean.
Return Value Description
UserKeys The UserKeys keys that the user pressed.
empty string Indicates that no key was pressed within the specified time or that the key that the user pressed was not one of the UserKeys you supplied in the WaitForKeys method syntax.

Perhaps the problem is that a boolean is not returned?

Code:
Dim UserKeys As String
UserKeys = Screen1.WaitForKeys(9000, "<Tab>")
If IsNull(UserKeys) Then
  Proceed = False
Else
  Proceed = True
End If

UserKeys may need to be an Object. IsNull may need to be changed to If UserKeys = "" Then. But, this should point you in the right direction.
 
Thanks, Skie.

I seems that no matter how it's chopped up, the WaitForKeys method does not work in VB.Net. I had similar experience with the WaitForStrings method. Both, as it appears, work perfectly withing Extra!Basic, but not in VB.Net. And, both work fine as long as you don't assign it to anything and expect a return value.

I pasted the following code straight from the help file but, since you have to assign Wait4Keys and can't use the $, I assigned it properly to a string.

Code:
    Private Sub RibbonTabItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RibbonTabItem2.Click

        Dim Sys As Object, Sess As Object, MyScreen As Object
        Dim Wait4Keys As String

        Sys = CreateObject("EXTRA.System")
        ' Assumes an open session
        Sess = Sys.ActiveSession
        MyScreen = Sess.Screen

        ' Method 1: As set in TimeoutValue property, 
        ' WaitForKeys will wait for nine seconds until 
        ' the "a" key is pressed
        Sys.TimeoutValue = 9000
        Wait4Keys = MyScreen.WaitForKeys("a")
        MsgBox("WaitForKeys returned " + Wait4Keys + ".")

        ' Method 2: As set in the Timeout parameter, 
        ' WaitForKeys will wait for nine seconds until 
        ' the "a" key is pressed

        Wait4Keys = MyScreen.WaitForKeys(9000, "a")
        MsgBox("WaitForKeys returned " + Wait4Keys + ".")

    End Sub

And, I promptly get the following error message:

Conversion from type '_ComObject' to type 'String' is not valid.

No matter what the variable Wait4Keys is assigned to, an error is produced in VB.Net. It works not with a String, Object, or otherwise. Just as I stated in my third post above.

Unless someone here is successfully using this method in VB.Net, then it may well be a bug.

I feared that this would not work simply because I had the similar nightmare converting some code from Delphi to VB.Net. The WaitForString and WaitForKeys methods work perfectly in Delphi like this:

Code:
 if Screen1.WaitForString('years', 21, 31) then
  begin
   {Add Customer Information To Record}
   qryCARES.Edit;
   qryCARES.FieldByName('Customer_ID').AsString := Screen1.GetString(4, 38, 9);
   qryCARES.FieldByName('First_Name').AsString := Trim(Proper(Screen1.GetString(5, 12, 12)));
   qryCARES.FieldByName('Last_Name').AsString := Trim(Proper(Screen1.GetString(5, 52, 12)));
   qryCARES.Post;
   Screen1.sendkeys('<Pf3>');
   Screen1.sendkeys('<Pf3>');
  end;

The above code works very well in Delphi and will wait properly for the string "years" to appear on the screen as part of a process of navigating through screens. However, there is no way that I have found to make it work in VB.Net.
 



Just..
Code:
Dim Wait4Keys

Skip,
[sub]
[glasses]I'll be dressed to the nines this week, as I go to have my prostatectomy...
Because, if I'm gonna BE impotent, I want to LOOK impotent![tongue][/sub]
 
This is getting fun. :)

Using the same example code, and:

Code:
    Private Sub RibbonTabItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RibbonTabItem2.Click

        Dim Sys As Object, Sess As Object, MyScreen As Object
        Dim Wait4Keys

        Sys = CreateObject("EXTRA.System")
        ' Assumes an open session
        Sess = Sys.ActiveSession
        MyScreen = Sess.Screen

        ' Method 1: As set in TimeoutValue property, 
        ' WaitForKeys will wait for nine seconds until 
        ' the "a" key is pressed
        Sys.TimeoutValue = 9000
        Wait4Keys = MyScreen.WaitForKeys("a")
        MsgBox("WaitForKeys returned " + Wait4Keys + ".")

        ' Method 2: As set in the Timeout parameter, 
        ' WaitForKeys will wait for nine seconds until 
        ' the "a" key is pressed

        Wait4Keys = MyScreen.WaitForKeys(9000, "a")
        MsgBox("WaitForKeys returned " + Wait4Keys + ".")

    End Sub

Produces the following error --> Operator '+' is not defined for string "WaitForKeys returned " and type '_ComObject'.

The important realization is that the method actually does not wait for any amount of time nor a keypress when Wait4Keys is declared as any type at all. It immediately jumps to the next line of code and produces an error.

If I simply call MyScreen.WaitForKeys("a") without Wait4Keys (no return value), then it executes fine. It will wait for either 9 seconds to elaspe or "a" to be pressed, but you have no way to compare the return value to decide what to do if the user does not press "a".
 



Use an AMPERSAND rather than the PLUS sign for string concatenation.

Skip,
[sub]
[glasses]I'll be dressed to the nines this week, as I go to have my prostatectomy...
Because, if I'm gonna BE impotent, I want to LOOK impotent![tongue][/sub]
 
Thanks, Skip. I did see that and made the change shortly after my last post, but it did not change the outcome.
 




I run it and get a return value using...
Code:
    Dim datarefreshed
    
    With oScrn
        datarefreshed = .WaitForKeys(9000, "a")
        
        MsgBox ("WaitForKeys returned " & datarefreshed & ".")
got WaitForKeys returned a. in my msgbox.

Skip,
[sub]
[glasses]I'll be dressed to the nines this week, as I go to have my prostatectomy...
Because, if I'm gonna BE impotent, I want to LOOK impotent![tongue][/sub]
 
Interesting.

What are you using? Are you doing this in Extra!Basic or using VB.Net?
 



VBA.

Skip,
[sub]
[glasses]I'll be dressed to the nines this week, as I go to have my prostatectomy...
Because, if I'm gonna BE impotent, I want to LOOK impotent![tongue][/sub]
 
I thought so. It seems that the WaitForKeys method works in everything but VB.Net. :)

I did send this one to Attachmate Support this morning to see what their take is on this.
 



I'd be posting in a .net forum

Skip,
[sub]
[glasses]I'll be dressed to the nines this week, as I go to have my prostatectomy...
Because, if I'm gonna BE impotent, I want to LOOK impotent![tongue][/sub]
 
Conversion from type '_ComObject' to type 'Boolean' is not valid.
Conversion from type '_ComObject' to type 'String' is not valid.
I've tested the WaitForKeys method in VS 2005 and I get the exact same messages. When I defined the return value of WaitForKeys as an Object, I don't hit any error messages, but debug.print shows _ComObject. When I have time, I'll play with this a little more to see if I can come up with anything.
 
Just confirming what WinblowsMe found.

Code:
Dim Wait4Keys As Object
Dim sWait4Keys As String
Wait4Keys = Screen.WaitForKeys(9000, "a")
sWait4Keys = Wait4Keys.ToString
MsgBox sWait4Keys

This returns System.__ComObject instantly.
 
Thanks, Winblows and Skie. :)

I was extremely helpful to know that this is indeed a real problem, and that I was correct that this method certainly does not work as expected using OLE with VB.Net. You will find that the WaitForString method has the very same problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top