Showing posts with label english. Show all posts
Showing posts with label english. Show all posts

Monday, March 26, 2012

The conversion of a char data type to a datetime data type resulted in an out-of-range dat

getting this error - i think its because im trying to put english date
format into american date format
(asp to sql server 2000)

im getting the date using
mortsourcedlabel.Text = Date.Today
mortsourcedlabel.Visible = True
mortsourced.Visible = False

which throws the date out (in uk format) to 13/02/2004 - all well and good
but -
im assuming that its going out of range as sql needs 02/13/2004
heh im guessing ive been testing code the past 2 weeks -- and now its the
13th which has now thrown up the error!
how do i change the date format not in the code above (i still need to see
the date in english-UK format on the page) but before the sql statement
(maybe in my stored procedure?)
thanks

marknm i sussed it with :-

Dim msl As String = mortsourcedlabel.Text.ToString ' date
Dim day, month, year As String
If mortsourcedlabel.Text.ToString = "" Then
msl = "01/01/1900"
Else
Dim mydate As Date
mydate = mortsourcedlabel.Text.ToString
day = mydate.Day.ToString
month = mydate.Month.ToString
year = mydate.Year.ToString
msl = month + "/" + day + "/" + year
End If

cheers

mark

Saturday, March 24, 2012

The difference between creating an instance of an object

Could someone tell me in plain english was is the difference between


Dim MyObject As SomeType

and


Dim MyObject As New SomeType

and


Dim MyObject = New SomeType
Dim MyObject as SomeType = Creating a variable that holds an object of SomeType.

Dim MyObject as New SomeType = Creating and instantiating an object of SomeType.

Dim MyObject = New SomeType = Invalid syntax in vb.net. You need to specify the default type as variant is no longer supported in ASP.NET.
Ok, now I understand.

So if I have something like Fruit.Apple and Value is part of this as in Fruit.Apple.Value, I can do this...

Dim Food As Fruit.Apple

Food.Value

It looks like a way of shortening the name of an object.

Now, I have another question. How do you know when is the appropriate time to create and instantiate a new object rather than just use the above method?

Sorry if my question seems too easy, but I didn't do much of this stuff in regular ASP.
Well yes and no.

Lets think of this another way. Lets take your Fruit object. Your fruit has properties - color, weight, type, etc. You would create a class that describes this like so:


Public Class Fruit
Private _type As String
Private _color As String
Private _weight As Decimal

Public Property Type() As String
Get
Return _type
End Get
Set(ByVal Value As String)
_type = Value
End Set
End Property
' Add other properties for color and weight also

End Class

Then in your code you would instantiate a new Fruit object like:


Dim objFruit as New Fruit
'Then set properties of the fruit
With objFruit
.Type = "Apple"
.Color = "Red"
.Weight = 2.2
End With

It is appropriate to create a class whenever you are going to possibly reference the object from multiple places in your code.

Greg