Object variable not set error in vb6 - vb6

Private m_IncidentDateRange As New MCWebServiceCOMWrapper.DateRange
Public Property Get IncidentDateRange() As MCWebServiceCOMWrapper.DateRange
IncidentDateRange = m_IncidentDateRange
End Property
Public Property Let IncidentDateRange(ByRef vNewValue As MCWebServiceCOMWrapper.DateRange)
Set m_IncidentDateRange = vNewValue
End Property
Error comes up in Get method please help

I would check the documentation for the MCWebServiceCOMWrapper.DateRange object and see if you are required to initialized it with values before you can use it. (maybe set a beginning and end date).

Don't you need to use "Set" there?

Related

How to use polymorphism to remove a switch statement which compares strings?

I am new to Ruby, so let me describe the context of my problem first:
I have a json as input which has the following key / value pair:
{
"service": "update"
}
The value has many different values for example: insert,delete etc.
Next there is a method x which handles the different requests:
def x(input)
case input[:service]
services = GenericService.new
when "update"
result = services.service(UpdateService.new,input)
when "insert"
result = services.service(InsertService.new,input)
when "delete"
result = services.service(DeleteService.new,input)
....
....
else
raise "Unknown service"
end
puts JSON.pretty_generate(result)
end
What is bothering me is that I still need to use a switch statement to check the String values (reminds me of 'instance of' ugh..). Is there a cleaner way (not need to use a switch)?
Finally I tried to search for an answer to my question and did not succeed, if however I missed it feel free to comment the related question.
Update: I was thinking to maybe cast the string to the related class name as follows: How do I create a class instance from a string name in ruby? and then call result = services.services(x.constantize.new,input) , then the class names ofcourse needs to match the input of the json.
You can try something like:
def x(input)
service_class_name = "#{input[:service].capitalize}Service"
service_class = Kernel.const_get(service_class_name)
service_class.new(input).process
end
In addition you might want to check if this is a valid Service class name at all.
I don't understand why you want to pass the service to GenericService this seems strange. let the service do it's job.
If you're trying to instatiate a class by it's name you're actually speaking about Reflection rather than Polymorphism.
In Ruby you can achieve this in this way:
byName = Object.const_get('YourClassName')
or if you are in a Rails app
byName= 'YourClassName'.constantize
Hope this helps
Just first thoughts, but you can do:
eval(services.service("#{input[:service].capitalize}Service.new, #{input})") if valid_service? input[:service]
def valid_service?
w%(delete update insert).include? input[:service]
end
As folks will no doubt shout, eval needs to be used with alot of care

Error "object doesn't support this property or method: dbrowser.GetRoProperty"

I was trying to run below script, but it's giving me an error that says:
object doesn't support this property or method: "dbrowser.GetRoProperty"
SystemUtil.Run "iexplore.exe","http://usps.com/"
Set dbrowser = description.Create
dbrowser ("micclass").value = "Browser"
dbrowser("openurl").value = "https://www.usps.com"
dbrowser("title").value = "USPS - The United States Postal Service (U.S. Postal Service)"
print(dbrowser.getroproperty("title"))
Your dbrowser object is of type Description not Browser you need to create a Browser object based on this description. Replace the last line with:
Print Browser(dbrowser).GetROProperty("title")
Note, there are two changes here
Using Browser(dbrowser)
Removing the parens from the print sub.
Edit: also note that descriptions are regular expressions by default so the parens in the title may cause problems, you should mark it as not regex.
dbrowser("title").RegularExpression = False
Description.Create is used to create a 0-based Properties collection object. The variable dbrowser is preceded by the Set statement. Usage of Set statement binds an object as a reference to another object. Therefore, dbrowser becomes an object reference to the description object represented by Description.Create
A description object does not have a stand-alone use, but coupled with the ChildObjects method, it becomes an extremely powerful approach in dealing with AUT’s objects .For More Info, check link
So the code should be like
SystemUtil.Run "iexplore.exe","http://usps.com/"
wait(10)
Set dbrowser = description.Create
dbrowser ("micclass").value = "Browser"
dbrowser("openurl").value = "https://www.usps.com"
dbrowser("title").value = "USPS.*" ''Using Regular Expression here
Set colObject = Desktop.ChildObjects( dbrowser )
Print (colObject(0).GetROProperty("title"))

Co-ordinate conversion

I am making a simple coordinate converter with the help of eye4software. Following link provides the required Visual Basic 6 codes for the converter.
http://www.eye4software.com/products/gpstoolkit/source/vb/datumtransformation/
I have followed said process according to the given details in the link.
Private Sub Form1_Load()
Private objProjection As GpsProjection
Private objDatumSrc As GpsDatumParameters
Private objDatumDst As GpsDatumParameters
Set objProjection = CreateObject("Eye4Software.GpsProjection")
Set objDatumSrc = CreateObject("Eye4Software.GpsDatumParameters")
Set objDatumDst = CreateObject("Eye4Software.GpsDatumParameters")
End Sub
Option Explicit
Private objProjection As GpsProjection
Private objDatumSrc As GpsDatumParameters
Private objDatumDst As GpsDatumParameters
Private Sub CommandTranslate_Click()
' Set Source Datum ( WGS84 )
' The ID for WGS84 is 4326, see 'http://www.eye4software.com/resources/datums' for a full list of supported datums
' To convert from another datum, just change the code below (EPSG code)
objDatumSrc.LoadFromId (4326)
' Set Destination Datum ( NAD27 )
' The ID for NAD27 is 4267, see 'http://www.eye4software.com/resources/datums' for a full list of supported datums
' To convert to another datum, just change the code below (EPSG code)
objDatumDst.LoadFromId (4267)
' Set Source coordinates
objProjection.Latitude = CDbl(Textlat1.Text)
objProjection.Longitude = CDbl(Textlon1.Text)
' Perform the datum transformation
objProjection.TransformDatum objDatumSrc, objDatumDst
' Display the result
Textlat2.Text = objProjection.Latitude
Textlon2.Text = objProjection.Longitude
End Sub
But i am getting a run time error for this code (objDatumSrc.LoadFromId (4326)) saying object required. Since i'm a beginner i was unable to solve this. please help me.
You have two objDatumSrc variables.
One is a private variable inside Form_Load - you are initialising that one.
The other one is a module-level one and you are not initialising that one.
Delete the Private variable declarations inside Form_Load
To me, it looks like you aren't understanding scope, but the real problem is a non-instantiated variable. Your declaration of objDatumSrc in the form load event will not be able to be seen in the rest of the form because The variables you are declaring outside of a method are not being instantiated.
Replace your current code with this...
Option Explicit
Private objProjection As New GpsProjection
Private objDatumSrc As New GpsDatumParameters
Private objDatumDst As New GpsDatumParameters
Private Sub CommandTranslate_Click()
' Set Source Datum ( WGS84 )
' The ID for WGS84 is 4326, see 'http://www.eye4software.com/resources/datums' for a full list of supported datums
' To convert from another datum, just change the code below (EPSG code)
objDatumSrc.LoadFromId (4326)
' Set Destination Datum ( NAD27 )
' The ID for NAD27 is 4267, see 'http://www.eye4software.com/resources/datums' for a full list of supported datums
' To convert to another datum, just change the code below (EPSG code)
objDatumDst.LoadFromId (4267)
' Set Source coordinates
objProjection.Latitude = CDbl(Textlat1.Text)
objProjection.Longitude = CDbl(Textlon1.Text)
' Perform the datum transformation
objProjection.TransformDatum objDatumSrc, objDatumDst
' Display the result
Textlat2.Text = objProjection.Latitude
Textlon2.Text = objProjection.Longitude
End Sub
The code here so obviously shouldn't compile, it is obvious that you are not showing your real code. For instance, what is your error handling? If you have done something like On Error Resume Next, then if the following lines raise errors, then the errors won't be reported.
Set objProjection = CreateObject("Eye4Software.GpsProjection")
Set objDatumSrc = CreateObject("Eye4Software.GpsDatumParameters")
Set objDatumDst = CreateObject("Eye4Software.GpsDatumParameters")
Since they would be set to Nothing, if you tried to execute methods and properties on objProjection, objDatumSrc, and objDatumDst, they would raise the error "object required".
And since this is likely not the code you have tried to run, can you verify that all the Program Ids e.g. "Eye4Software.GpsProject" are correct? In fact - have you registered these components? And why can't you instantiate these objects using the slightly cleaner notation, e.g.
Set objProjection = New Eye4Software.GpsProjection
?
Try either:
Call objDatumSrc.LoadFromId(4326)
or
objDatumSrc.LoadFromId 4326
VB gets a little funky doing method calls with parameters. If it's not in the expected format, some results may vary.

How to create XML object from string using xml-mapping in Ruby

I'm using xml-mapping in Ruby (on Sinatra) for some XML stuff. Generally I follow this tutorial: http://xml-mapping.rubyforge.org/. I can create objects and write them to XML strings using
login.save_to_xml.to_s
But when I try
login = Login.load_from_xml(xml_string)
I get the following error:
XML::MappingError - no value, and no default value: Attribute username not set (XXPathError: path not found: username):
Here is the XML string I receive:
<login><username>ali</username><password>baba</password></login>
This is what the class looks like:
class Login
include XML::Mapping
text_node :username, "username"
text_node :password, "password"
end
So the class name is the same, the nodes are named the same. I actually get the exact same string when I create an instance of my object and fill it with ali/baba:
test = Login.new
test.username = "ali"
test.password = "baba"
p test.save_to_xml.to_s
<login><username>ali</username><password>baba</password></login>
What am I missing?
Thanks,
MrB
EDIT:
When I do
test = login.save_to_xml
And then
login = Login.load_from_xml(test)
it works. So the problem seems to be that I'm passing a string, while the method is expecting.. well, something else. There is definitely a load_from_xml(string) method in the rubydocs, so not sure what to pass here. I guess I need some kind of reverse to_s?
It looks like you save_to_xml creates a REXML::Element. Since that works, you may want to try:
Login.load_from_xml(REXML::Document.new(xml_string).root)
See the section on "choice_node" for a more detailed example http://xml-mapping.rubyforge.org/

EntLib Validation problem on GetType(object) - expects string not object?

I have an Address object that I am trying to validate data against using EntLib:
Given the following method:
<ValidatorComposition(CompositionType.And, Ruleset:="FraudAnalysis")> _
<NotNullValidator(MessageTemplate:="Billing address is required.", Ruleset:="FraudAnalysis")> _
<TypeConversionValidator(GetType(Address), MessageTemplate:="Billing address must be an address object.", Ruleset:="FraudAnalysis")> _
Public Property BillingAddress() As Address
Get
Return _BillingAddress
End Get
Set(ByVal value As Address)
_BillingAddress = value
End Set
End Property
I create an address object:
Address thisAddress = new Address();
thisAddress.Address1 = "12312 Long Street";
thisAddress.City = "Los Angeles";
thisAddress.State = "CA";
thisAddress.Zip = "93322";
// set billing address to address
cardX.BillingAddress = thisAddress;
So now at cardX.billingAddress = thisAddress, the BillingAddress property validator (GetType(Address)) should fire. It seems to fire, but returns this error:
Value to validate is not of the expected type: expected System.String but got Address instead.
Can anyone see the issue here / suggest a fix?
Thanks.
I would just get rid of the ValidatorComposition and TypeConversionValidator declarations as I think they are redundant here. That would get rid of your error and a couple of lines of code too.
The property is already strongly-typed to the Address class so there is no way you can set it in code to an object that isn't an Address or isn't polymorphic with Address - having an extra validator to check this is redundant.
The default composition of validators is logical AND anyway, you only need to specify validator composition when you want to OR a group, or use more complex groups that combine AND / OR.

Resources