Runtime Error 424 Object Required - vb.net

Hey so I get this error in this code:
Private Sub Request_Stuff_button_Click()
Call Main.createObjects
Call My_Control.requestStuff
End Sub
at the 'Call My_Control.requestStuff' line.
The 'Main' module looks like this:
Public My_Control As ControlObject
Public Sub createObjects()
If My_Control Is Nothing Then
Set My_Control = New ControlObject
End If
End Sub
The weirdest thing is that when I add
Dim x As Integer
x = My_Control.dummyInt
right before the line that gets me the error, x gets the correct value right before the error happens which means My_Control is definitely an object and is definitely not nothing.
This error is killing me, thanks in advance.

Thanks but that wasn't the problem, the issue was actually in the requestStuff method but the debugger was freezing on that line instead of in the method and silly me forgot to check for that.

Related

Creating a new IUI Automation Handler object in order to subscribe to an automation event

So, here it goes. To start, A disclaimer, I understand that MS Access is not built for this kind of work. It is my only option at this time.
I have done just a bit of Automation using UIAutomationClient and I have successfully used its other features, however I cannot for the life of me get it to subscribe to events.
Normally, it is supposed to be a bit like this:
Dim CUI as new CUIAutomation
Dim FocusHandler as IUIAutomationFocusChangedEventHandler
Set FocusHandler = new IUIAutomationFocusChangedEventHandler(onFocusChanged)
C.AddFocusChangedEventHandler(Element,TreeScope_Children, null, FocusHandler)
end function
'
'
Function onFocusChanged(src as Object, args as AutomationEventArgs)
''my code here
end function
Yet when I attempt this, I get the error "expected end of statement" on the line:
FocusHandler = new IUIAutomationFocusChangedEventHandler(onFocusChanged)
additionally, if I leave off the (onFocusChanged) I get the error "Invalid use of new Keyword".
It seems like I am missing a reference somewhere. The usual drop down when using "new" does not contain the IUI handler classes though they are in the object library.
I am not sure if there is just some piece I am not accounting for in the code since I am using vba, but all examples seem to be for .net or C#/C++. Any help would be appreciated.
Additionally, I have no problem finding the element in question and all other pieces work fine. If you need any other pieces of the code let me know.
Edit: added set to line 3. No change in the problem though.
After two years this probably isn't relevant any more, but perhaps somebody else encounters this problem... The answer is to create a new class that implements the HandleAutomationEvent method.
Here I created a class named clsInvokeEventHandler and (importantly) set the Instancing property to PublicNotCreatable:
Option Explicit
Implements IUIAutomationEventHandler
Private Sub IUIAutomationEventHandler_HandleAutomationEvent(ByVal sender As UIAutomationClient.IUIAutomationElement, ByVal eventId As Long)
Debug.Print sender.CurrentName
End Sub
And to use it:
Sub StartInvokeHandler()
Dim oUIA As New CUIAutomation8
Dim oRoot As IUIAutomationElement
Dim InvokeHandler As clsInvokeEventHandler
Set InvokeHandler = New clsInvokeEventHandler
Set oRoot = oUIA.GetRootElement
oUIA.AddAutomationEventHandler UIA_Invoke_InvokedEventId, oRoot, TreeScope_Descendants, Nothing, InvokeHandler
End Sub

Difference between lambda syntax and addressof VB.NET

I've recently entered the joyful world of VB.NET, for the life of me however, I can't seem to figure out why the following is not working.
When I write this code here, all is well:
MyNavigationCommand = New RelayCommand(AddressOf Navigate)
Private Sub Navigate()
Navigator.NavigateTo(NavigationRoutes.DetailScreen)
End Sub
However, when I try to do exactly the same using the lambda syntax, my code inside the lambda doesn't get hit when I click the button that triggers the command.
The following line, doesn't work:
MyNavigationCommand = New RelayCommand(Sub() Navigator.NavigateTo(NavigationRoutes.DetailScreen))
This should work exactly the same as my previous approach, shouldn't it? Or am I missing something?
I'm not sure what's going wrong for you. This is my code that I wrote to test this:
Sub Main
Dim MyNavigationCommand = New RelayCommand(AddressOf Navigate)
Dim MyNavigationCommand2 = New RelayCommand(Sub() Console.WriteLine("!"))
Navigate
MyNavigationCommand
MyNavigationCommand2
End Sub
Public Delegate Sub RelayCommand
Public Sub Navigate()
Console.WriteLine("!")
End Sub
When run this code produces three lines of !.

VBA runtime error 91 even though variable is set

I am struggling with a piece of code that places a custom class in a collection. Every time I run the code I get a runtime error 91. The error is occuring on the Set pjt = New CProject line.
Dim Projects As Collection
Private Sub BuildProjects()
Dim pjt As CProject
Set Projects = New Collection
Set pjt = New CProject '<-----ERROR OCCURS HERE
'Do some other stuff
End Sub
This is obviously the simplest form of the Sub, but it still throws the error! What am I doing wrong? Do I need to set the access for the CProject class file somehow?
All your help will be greatly appreciated.
The line Set pjt = New CProject is calling the constructor for CProject.
The error will most likely be in the constructor of CProject.
Error 91 is a null reference

VBA Excel "Variables are required"

Got a trouble in a VBA excel program.
Sub code(s)
...
code = t
End Sub
And then :
Sub CommandButton1_Click()
...
For i = 0 To size
current_y = code(string_array(i))
...
End Sub
When i run the program, i got this error "Variables are required" (not sure, i'm working on a japanese version of excel). Sub CommandButton1_Click is highlighted and code is selected inside CommandButton1_Click. Can't figure out why, though it must be simple...
You're trying to return a result from a Sub. Try declaring it as a function instead, as this is able to return values to the caller:
Function code(s)
...
code = t
End Function
If it makes it any clearer, on my English version the error message is:
Expected Function or variable
Does the code include Option Explicit? Perhaps the error translates to "Variable declaration required"? Try removing option explicit - if that fixes it remove that line, then go through checking all variables are declare (e.g. dim current_y as string).

How to view VB6 control-level variables in WinDbg?

I have a crash file where I can see that one of my own VB6 user controls is responsible for the crash; i.e. one of its methods is part of the stack trace and I can see the line responsible.
From here, I'd like to inspect the state of its member variables. How do I do this?
Note: I also have the private symbols for my controls. The problem is being able to inspect "Me". The command !object address_of_Me doesn't seem to do the trick and so I'm at a loss.
Thank you.
It's been 10 years since I had to do this in VB6, but I remember a lot of Printer.Print statements in my past life :)
I used to do things like this for debugging (but not for release code)
Sub MySub
On Error Goto ErrorTrap
Dim intX as integer
Dim intY as integer
' do some horrible error here
Exit Sub
ErrorTrap:
Printer.Print "Error"
Printer.Print intX
Printer.Print intY
Printer.Print ...
End Sub
well, codeSMART have one option install global handle on your application first call to SetUnhandledExceptionFilter (win api) is should be installed when load your module main or master form when is closing the program so call to SetUnhandledExceptionFilter.
The code is little long so copy methods names y api calls
Public Sub InstallGlobalHandler()
On Error Resume Next
If Not lnFilterInstalled Then
Call SetUnhandledExceptionFilter(AddressOf GlobalExceptionHandler)
lnFilterInstalled = True
End If
End Sub
Public Sub UninstallGlobalExceptionHandler()
On Error Resume Next
If lnFilterInstalled Then
Call SetUnhandledExceptionFilter(0&)
lnFilterInstalled = False
End If
End Sub
Also here is Record Structure y apis declarations for the module
- CopyMemory
- SetUnhandledExceptionFilter
- RaiseException
' Public enums
-EExceptionType
-EExceptionHandlerReturn
-Private Const EXCEPTION_MAXIMUM_PARAMETERS = 15
' Private record structure
-Private Type CONTEXT
'Structure that describes an exception.
-Private Type EXCEPTION_RECORD
'Structure that contains exception information that can be used by a debugger.
-Private Type EXCEPTION_DEBUG_INFO
-Private Type EXCEPTION_POINTERS
Take a revised that How to route the exe exception back to VB6 app?