I wish to use a customized string for use in an OnExceptionAspect.
Say I created a string named "message" and then in:
Method A: message = "Could not record your personal data"
Method B: message = "Could not record your date of birth" etc.
Then, in the OnExceptionAspect, the string would be obtained from the method that threw the exception and include it in the resultant messagebox or whatever, for example:
If(MethodThatThrewException) has string "message";
exceptionMessage = (MethodThatThrewExption).message;
Is the above possible or is there another way of doing this.
I decided it's easier to pass the variable as a parameter to the aspect eg...
[ExceptionDialog(null, "This is my custom message")]
Related
I am working on a flutter app and wanted one of my classes to have the same id property. This is because I can have either an event or an exception, but I would like the same function to manage both. To do this, I have a switch statement that checks res.id to determine which type of event it is. The response can either be an Event instance or an Exception instance.
Exception is an import class and I'd rather not have to wrap it in an Event instance so I thought I could just hardcode id = EventIds.error. This way every error will have an id that matches an error event - thus it can be accessed and dealt with in the original switch statement.
My issue is I don't want to have to go all throughout my code and add a new argument to each instantiation. See the code below.
Exception.dart
class Exception {
/// Always initialize with id that is error id
/// This is for onCaptureEvent
int id = EventIds.error;
int code = 0;
String message = 'no error';
String? method;
String? details;
Exception(id, this.code, this.message, [this.method, this.details]);
}
Instantiation Current
Exception ex = new Exception(-93, 'Unable to validate')
I want to be able to have every instance of Exception have an id of EventIds.error WITHOUT having to go through every instantiation in my code and add it like so:
Exception ex = new Exception(EventIds.error, -93, 'Unable to validate')
Is this achievable in Flutter?
It was really simple. I just needed to write out my Exception class like so:
Exception.dart
class Exception {
/// Always initialize with id that is error id
/// This is for onCaptureEvent
int id = EventIds.error;
int code = 0;
String message = 'no error';
String? method;
String? details;
Exception(this.code, this.message, [this.method, this.details]);
}
This way the instances will always use the default value for id. This is also safer bc now the user cannot change the ID if they wanted to provide another argument (Exception(supplied_id, code, message)) because it will throw a syntax error saying the second argument is supposed to be a string.
enter image description here
I am trying to use textMapper to change the text shown in NumberPicker.
I found the TextMapper class, but I don't know how to use it.
Please tell me how to use textMapper
Its basically a method that takes a String argument and returns a String value that transforms the input.
eg:
String modifyText(String s){
return "Value " +s; // Appends "Value" to the String s
}
Can be set to the textMapper property to show the values in the picker as "Value ..." instead of just '...'
When I submit the form, input error is occur. JourneyDate is instance of 'Date'. But ,here it become String which is not accepted by the setter and getter.
<s:hidden name="JourneyDate" value="%{JourneyDate}"></s:hidden>
I want JourneyPlan as Date Type, but it become String.
Try intercepting the value before passing it to the getter/setter. For example send JourneyDateString from your form, create a Date from the String, and then pass that to your getter/setter. Something like:
public void setJourneyDateString(String journeyDateString)
{
//journeyDateString could be "2013-03-28" for example
Date journeyDate = new SimpleDateFormat("yyyy-MM-dd").parse(journeyDateString);
setJourneyDate(journeyDate);
}
The object that you've set in the value attribute will keep it's type as Date. Then you need to define corresponding setter in the action to set the value of the Date. It will convert to string if you place the value in the body of the tag.
I'm working on a new application and i need to make a messages interface with lookup, using the key to find the value (like ConstantsWithLookup, but capable to receive parameters). I have being investigating Dictionary class functionality but it lacks message customization through parameters.
With ConstantsWithLookup i can make the following:
myConstantsWithLookupInterface.getString("key");
and get something like:
Field must be filled with numbers
But i need to do this:
myMessagesWithLookupInterface.getString("key", "param1", "param2",...);
and get something like:
Field _param1_ must be filled with numbers greater than _param2_
I have no clue how to do this.
Use GWT regular expressions:
//fields in your class
RegEx pattern1 = RegEx.compile("_param1_");
RegEx pattern2 = RegEx.compile("_param2_");
public String getString(String key, String replace1, String replace2){
// your original getString() method
String content = getString(key);
content = pattern1.replace(content,replace1);
content = pattern2.replace(content,replace2);
return content;
}
If your data contains Field _param1_ must be filled with numbers greater than _param2_ then this will replace _param1_ with content of string replace1.
I have a custom class module in VBA (Access) that is supposed to handle a large amount of external data. Currently I have two functions Read(name) and Write(name, value) that allows to read and set dynamic properties.
Is there a way to define a more syntactic way to read and write those data? I know that some objects in VBA have a special way of accessing data, for example the RecordSet, which allows to read and set data using myRS!property_name. Is there a way to do exactly the same for custom class modules?
The exclamation mark syntax is used to access members of a Scripting.Dictionary instance(you'll need to add a reference to Microsoft Scripting Runtime through Tools > References first). To use this syntaxyou'll need to be storing the information internally in a dictionary.
The quickest way to use it in a class is to give your class an object variable of type Scripting.Dictionary and set it up as follows:
Option Explicit
Dim d As Scripting.Dictionary
Private Sub Class_Initialize()
Set d = New Scripting.Dictionary
End Sub
Private Sub Class_Terminate()
Set d = Nothing
End Sub
Public Property Get IntData() As Scripting.Dictionary
Set IntData = d
End Property
Now you can access properties using myinstance.IntData!MyProperty = 1... but to get to where you want to be you need to use Charlie Pearson's technique for making IntData the default member for your class.
Once that's done, you can use the following syntax:
Dim m As MyClass
Set m = New MyClass
Debug.Print "Age = " & m!Age ' prints: Age =
m!Age = 27
Debug.Print "Age = " & m!Age ' prints: Age = 27
Set m = Nothing
Okay, thanks to Alain and KyleNZ I have now found a working way to do this, without having a collection or enumerable object below.
Basically, thanks to the name of the ! operator, I found out, that access via the bang/pling operator is equivalent to accessing the default member of an object. If the property Value is the default member of my class module, then there are three equivalent statements to access that property:
obj.Value("param")
obj("param")
obj!param
So to make a short syntax working for a custom class module, all one has to do is to define a default member. For example, I now used the following Value property:
Property Get Value(name As String) As String
Value = SomeLookupInMyXMLDocument(name)
End Property
Property Let Value(name As String, val As String) As String
SetSomeNodeValueInMyXMLDocument(name, val)
End Property
Normally, you could now access that like this:
obj.Value("foo") = "New value"
MsgBox obj.Value("foo")
Now to make that property the default member, you have to add a line to the Property definition:
Attribute Value.VB_UserMemId = 0
So, I end up with this:
Property Get Value(name As String) As String
Attribute Value.VB_UserMemId = 0
Value = SomeLookupInMyXMLDocument(name)
End Property
Property Let Value(name As String, val As String) As String
Attribute Value.VB_UserMemId = 0
SetSomeNodeValueInMyXMLDocument(name, val)
End Property
And after that, this works and equivalent to the code shown above:
obj("foo") = "New value"
MsgBox obj("foo")
' As well as
obj!foo = "New value"
MsgBox obj!foo
' Or for more complex `name` entries (i.e. with invalid identifier symbols)
obj![foo] = "New value"
MsgBox obj![foo]
Note that you have to add the Attribute Value.VB_UserMemId = 0 in some other editor than the VBA editor that ships with Microsoft Office, as that one hides Attribute directives for some reason.. You can easily export the module, open it in notepad, add the directives, and import it back in the VBA editor. As long as you don't change too much with the default member, the directive should not be removed (just make sure you check from time to time in an external editor).
See this other question: Bang Notation and Dot Notation in VBA and MS-Access
The bang operator (!) is shorthand for
accessing members of a Collection or
other enumerable object
If you make your class extend the Collection class in VBA then you should be able to take advantage of those operators. In the following question is an example of a user who extended the collection class:
Extend Collections Class VBA