string compare

  • Thread starter Thread starter Maileen
  • Start date Start date
M

Maileen

Hi,

I have the following code :
Function GetRequestType(ByVal EvDt As String, ByVal StPeriod As String,
ByVal EdPeriod As String, ByVal TaskType As String) As Integer
Dim strtest As String
Dim i, j As Integer
i = strtest.Compare(EvDt,StPeriod)
Select Case (TaskType)
Case "Old"
If (i < 0) Then 'EvDt is before StPeriod
Return (1)
Else
Return (0)
End If
Case "New"
If (i >= 0) Then 'EvDt is after of equal to StPeriod
j = strtest.Compare(EvDt, EdPeriod)
If (j < 0) Then 'EvDt is before EndPeriod (so, between
StPeriod and EdPeriod
Return (1)
End If
Else
Return (0)
End If
End Select

End Function

unfortunately, it does not work well...
if EvDt < StPeriod, i >0...and it should be i<0....
for example :

EvDt = 02.01.2005
StPeriod = 01.06.2005

thus i >0, how is it possible ?

thanks a lot,
Maileen
 
If EvDt = "02.01.2005" and StPeriod = "01.06.2005", then EvDt is greather
then StPeriod. And so 'i' ends up being greater then 0.

So what's the problem? Or am I not understanding something?
 
Hi Marina,

sorry but where i live January 02nd is before 1st june ;-)
so, string compare is it based on highest first characters found in string ?

in this case, how to compare date ?
because i will convert using CDate(EvDt) and CDate(StPeriod)

Maileen
 
Ok, well, I where live, the date format is month/day/year.

In any case, our preferred date formats are irrelevant. We are talking about
how string comparisons are done. And they are done the same way regardless
of what kind of meaning they have to you. And the fact is, "02.01.2005" is a
greater string then "01.06.2005".

This is just as the the string "10" will be considered less then the string
"2".

If you need date comparisons, you should use DateTime objects.
 
Maileen said:
Hi,

I have the following code :
Function GetRequestType(ByVal EvDt As String, ByVal StPeriod As String,
ByVal EdPeriod As String, ByVal TaskType As String) As Integer
Dim strtest As String
Dim i, j As Integer
i = strtest.Compare(EvDt,StPeriod)
Select Case (TaskType)
Case "Old"
If (i < 0) Then 'EvDt is before StPeriod
Return (1)
Else
Return (0)
End If
Case "New"
If (i >= 0) Then 'EvDt is after of equal to StPeriod
j = strtest.Compare(EvDt, EdPeriod)
If (j < 0) Then 'EvDt is before EndPeriod (so, between
StPeriod and EdPeriod
Return (1)
End If
Else
Return (0)
End If
End Select

End Function

unfortunately, it does not work well...
if EvDt < StPeriod, i >0...and it should be i<0....
for example :

EvDt = 02.01.2005
StPeriod = 01.06.2005

thus i >0, how is it possible ?

thanks a lot,
Maileen

Why are you not converting these to dates and then comparing them?

Chris
 
thanks Marina,

i was already exploring this DateTime type for my solution.
thanks for help.

maileen
 
Maileen,

In addition to the others

In almost every (non Coca Cola culture) dates are almost impossible to
compare by non humans.

Therefore is the ISO date written as Year, Month, Day, Hours, Minutes,
Seconds

The datetime in Net is in ticks as the number of 100-nanosecond intervals
that have elapsed since 12:00 A.M., January 1, 0001 using the Georgian
Calendar.

To compare dates behind that starting Georgian Calendar date is in my
opinion the datetime.ticks the most easy one.

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top