Solved

For Crin--handling class messages

Posted on 2002-05-30
7
153 Views
Last Modified: 2010-05-02
I'm currently trying to work out a strategy for dealing with user-defined error messages occurring inside a user control, and I'm looking for advice.

Crin, since BirdsOfFire1 gave me what probably should be your points, I will offer this to you, although other experts with wwrthy ideas will also get points.

The idea is this:
I have a user control with a combobox and a command button entitled add.

The combobox lists item-IDs in a database, and when the user clicks Add, a new form appears that lets the user add a new record.

Since the database is not random-access, the user must define the ID.

If the ID is a duplicate, I intercept it during the add process and indicate that I will be appending a digit to make it unique.

---
Recently, I was told that I should offer the user the option to replace the existing record, ignore the add, or insert a new record.

Since the ID verification process is occurring inside the function that checks the ID and returns a new-unqiue-ID, what's the best way to pass back a message to the calling routine(s) so that these routines can figure out how to handle this situation?
0
Comment
Question by:rspahitz
  • 3
  • 3
7 Comments
 
LVL 1

Expert Comment

by:soferstam
ID: 7045271
public event NewID(sID as string)
...
raise event NewID ("Your ID")
0
 
LVL 22

Author Comment

by:rspahitz
ID: 7045363
That's good soferstam, but I want the event to be captured from within the control.  This may not be the best choice in the long run, but since there is a need to handle the event both within and outside the control, and all the current code is within, I'd like to simply find a new place within the control to put the message besides the sub-sub-sub-function.  I guess that technically I need to subclass some of this, but I don't want to begin that at this stage in the development cycle.
0
 
LVL 2

Expert Comment

by:Crin
ID: 7046982
Hi,

If I understood right you need return more than two parameters from the function - one for new ID and second - for the message.

soferstam is quite correct about RaiseEvent, it will fire appropriate routine in all "subscribed"  modules and classes which has defined this class variable using WithEvents keyword.

However, if you only have to get second value I'd perform it in other way - by passing some variable using ByRef.

Function VerifyID(ID as long, ByRef Message as long) as long

If ID is incorrect then
  VerifyID = newID
  Message = 1
else
  VerifyID = ID
  Message = 2
end if

end function


Sub Caller()
Dim Ret as long, ID as long, tmpID as long

ID = GetIDfromTheForm

SomeActions(SomeParameters)

tmpID = VerifyID(ID, Ret)

Select case Ret
  Case 1 'incorrect ID
     AppropriateActions1

  Case 1 'incorrect ID
     AppropriateActions2

End Select

End sub


Actually, I didn't quite understand the issue, so would you please explain with more details the GOAL you want to achieve?

Sincerely,
Crin
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Author Comment

by:rspahitz
ID: 7047192
GOAL:
Have a subprocedure return a value from a calculation.  If an error occurs during the calculation, also return that.

I guess what I'm looking for is soemthing like the error object...how does VB handle that?  And how would you handle it from within a user-control?

Note: I was considering using a ByRef to return a value, but it goes against the very nature of a function which, by definition, returns a single value, and I'm trying to do things "right."
0
 
LVL 2

Accepted Solution

by:
Crin earned 100 total points
ID: 7048965
Hi,

Ok, if the function expected should NOT be placed within any class the you can use user defined type variable.
In class module you can add additional class property to appropriate value and then read it.

To do user defined type crete new project and add module, further code is obvious:

This goes for module:
----------------------------------------------------
Public Type ReturnValue
  ID As Long
  Message As Long
End Type


Public Function Check(ID As Long) As ReturnValue

If ID = 0 Then
  Check.ID = 1
  Check.Message = 0
Else
  Check.ID = ID
  Check.Message = 1
End If

End Function


And this - for some form with Command1 button on it:
----------------------------------------------------
Private Sub Command1_Click()
Dim a As New Class1, FuncResult As ReturnValue

FuncResult = a.Check(1)

If FuncResult.Message = 0 Then
  MsgBox "Error occured"
Else
  MsgBox "No error found" & FuncResult.ID
End If

End Sub

This is really more adequate way to handle numerous results passing from one function.
Ask for more details if needed.

Sincerely,
Crin



0
 
LVL 22

Author Comment

by:rspahitz
ID: 7051350
That UDT worked quite well in VB6.

I guess .net will probably change everything, but I'll worry about that in 6 months!

Thanks.
0
 
LVL 2

Expert Comment

by:Crin
ID: 7052136
I bet UDT will not change, except one good ability - to use them within classes, for VB6 it is restricted...

Sincerely,
Crin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
DO Loop not working 4 72
VB error "Type mismatch" 2 49
Can we place a tooltip on the actual vb6 form 5 35
Help me. 3 45
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now