Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run-time error '13': Type mismatch #10

Open
tothzola opened this issue Apr 5, 2021 · 5 comments
Open

Run-time error '13': Type mismatch #10

tothzola opened this issue Apr 5, 2021 · 5 comments

Comments

@tothzola
Copy link

tothzola commented Apr 5, 2021

error

Hello, If I want to implement a validation to ComboBox control
and have the following error: Run-time error '13': Type mismatch on this line when it evaluates to TRUE:

If Not Validator Is Nothing Then
    BindingBase.AsINotifyValidationError.RegisterHandler ValidationManager
End If

BindPropertyPath:

Context.Bindings.BindPropertyPath ViewModel, "ComboBoxItemIndex", Me.ComboBox, _
            Mode:=TwoWayBinding, _
            UpdateTrigger:=OnPropertyChanged, _
            Validator:=New RequiredSelectionValidator, _
            ValidationAdorner:=ValidationErrorAdorner.Create(Target:=Me.ComboBox, _
            TargetFormatter:=ValidationErrorFormatter.WithErrorBorderColor.WithErrorBackgroundColor)

RequiredSelectionValidator Class:

'@ModuleDescription "A validator that requires a ComboBox Item to be selected."
Option Explicit

Implements IValueValidator

Private Function IValueValidator_IsValid(ByVal value As Variant, ByVal Source As IBindingPath, ByVal Target As IBindingPath) As Boolean
    IValueValidator_IsValid = value > -1
End Function

Private Property Get IValueValidator_Message() As String
    IValueValidator_Message = "Value cannot be empty."
End Property

Private Property Get IValueValidator_Trigger() As BindingUpdateSourceTrigger
    IValueValidator_Trigger = OnExit
End Property

Any suggestions?

@retailcoder
Copy link
Member

Hi there!

It looks like ValidationManager isn't implementing INotifyValidationError - I think I was working around that area (that and ListBox bindings) when I last touched this code.

Assuming the ViewModel property is a Long, then the binding itself seems fine... I'll take a look at my local copy of the workbook/project to see if there aren't any changes I haven't pushed, but it looks like validation is kind of broken at the moment.

Note, I'm still not convinced writing a MVVM framework in VBA is the best idea... thinking twinBASIC could be what we're missing to make this happen (without needing to import hundreds of classes in a VBA project). At this stage MVVM in VBA is very much at proof-of-concept level, I wouldn't push to use it for real production work (although that could be very cool!)

@tothzola
Copy link
Author

tothzola commented Apr 8, 2021

Hello @retailcoder, 😊. Thanks for the quick feedback.

Well I didn't notice that with the ValidationManager, maybe because I'm not that familiar with this whole framework.
Have to admit that I'm novice in some areas and struggling to understand the whole picture.

In other order of thinking maybe you are right abought VBA -> and the MVVM pattern maybe it should be done as a Library,
or in my case is this overkill? I don't know.

How would you advise or do such a complex project (see further down)?
Would you implement this pattern (MVVM) or just a combination of MVC-MVP?

If you have a little time to investigate the concept of the project what I'm trying to achieve in excel,
to have an idea, could you please look at the project (debitor-crud) I wrote some time ago,
you probably will have a laugh about the style I wrote it.
Everything lives in Excel, and that is the whole point because the file is placed on SharePoint
where different users have access and can fill in the data's/values in a UserForm presented, values must be validated.
It is database of customers data incapsulated in excel.

Back then I didn't know anything about OOP or how could I write some concepts more efficiently.
I was so happy when I found your tutorials and Rubberduck-VBA, finally something else then a simple macro.
Rubberduck-VBA changed everything a thought I knew about VBA and programming! 🤷‍♂️
Starving to read more about your knowledge to VBA and patterns! 👏

It is really hard to find some good tutorials/examples in VBA for my case, that can be maintained easily for future changes.
Exactly the principals of SOLID-> (O-Open for extensions and closed for modifications) in OOP programming this is my vision of how I would, try to build the project.

That is may real problem because the project pointed in this message works and currently used in production,
but every new changes more or less I must change half of the code I wrote
and some times (mostly😫) this becomes very time consuming and frustrating.
BIG BIG thanks, looking forward hearing from you cheers.

@retailcoder
Copy link
Member

I downloaded your project (and added myself as a watcher on your repository), I'll have a look and come back here with my findings. MVVM in VBA is definitely very very much an experimental thing, but it should be possible to incrementally refactor your existing working code into a more OOP design like Model-View-Presenter.

The central idea is always the same: separate the data from the rest of the code, then isolate and abstract away & inject/set the dependencies from the outside.

I'm not promising anything, but do you mind if I go ahead and refactor your code and then write a blog post (or series) about the refactoring process, showing the thought process and explaining the code changes along the way?

@tothzola
Copy link
Author

tothzola commented Apr 8, 2021

@retailcoder Wow, thank you. 😌

That would be awesome to read about!
Glad that you are interested and willing to refactor and document it as a post or series.

Looking forward to read about it.

You made my Day, awesome!!! Thanks
Cheers

@tothzola
Copy link
Author

tothzola commented Jun 3, 2021

Hello @retailcoder , I hade some other projects ongoing so I hade no time to investigate further this problem.
Still have a question regarding MVVM Framework. If you consider building with twinBASIC as a library than the file must be installed on a local computer in order to have it work with the excel project.
If that is the case, that in my case it can't be as a solution. I need the framework to be available without installation, project file sits on website (SharePoint) and is is used by 50+ colleges which all have excel 2019 local installed without the possibility to install other add ins, installations are generally blocked by system admin.

Could you please advise how can the Validation type mismatch error be fixed?
Due to the complexity I still can't figure this out.

Thanks for your reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants