Connecting Tech Pros Worldwide Forums | Help | Site Map

string compare

Maileen
Guest
 
Posts: n/a
#1: Nov 21 '05
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

Marina
Guest
 
Posts: n/a
#2: Nov 21 '05

re: string compare


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?

"Maileen" <noemail@nospam.com> wrote in message
news:%2369E%23C2nFHA.3036@TK2MSFTNGP14.phx.gbl...[color=blue]
> 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[/color]


Maileen
Guest
 
Posts: n/a
#3: Nov 21 '05

re: string compare


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

Marina wrote:[color=blue]
> 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?
>
> "Maileen" <noemail@nospam.com> wrote in message
> news:%2369E%23C2nFHA.3036@TK2MSFTNGP14.phx.gbl...
>[color=green]
>>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[/color]
>
>
>[/color]
Marina
Guest
 
Posts: n/a
#4: Nov 21 '05

re: string compare


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" <noemail@nospam.com> wrote in message
news:%238x3VQ2nFHA.2472@TK2MSFTNGP15.phx.gbl...[color=blue]
> 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
>
> Marina wrote:[color=green]
>> 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?
>>
>> "Maileen" <noemail@nospam.com> wrote in message
>> news:%2369E%23C2nFHA.3036@TK2MSFTNGP14.phx.gbl...
>>[color=darkred]
>>>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[/color]
>>
>>[/color][/color]

Chris
Guest
 
Posts: n/a
#5: Nov 21 '05

re: string compare


Maileen wrote:[color=blue]
> 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[/color]

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

Chris
Maileen
Guest
 
Posts: n/a
#6: Nov 21 '05

re: string compare


thanks Marina,

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

maileen

Marina wrote:[color=blue]
> 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" <noemail@nospam.com> wrote in message
> news:%238x3VQ2nFHA.2472@TK2MSFTNGP15.phx.gbl...
>[color=green]
>>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
>>
>>Marina wrote:
>>[color=darkred]
>>>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?
>>>
>>>"Maileen" <noemail@nospam.com> wrote in message
>>>news:%2369E%23C2nFHA.3036@TK2MSFTNGP14.phx.gbl. ..
>>>
>>>
>>>>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
>>>
>>>[/color][/color]
>[/color]
Cor Ligthert [MVP]
Guest
 
Posts: n/a
#7: Nov 21 '05

re: string compare


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


Closed Thread


Similar Visual Basic .NET bytes