string compare | | |
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 | | | | 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] | | | | 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] | | | | 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] | | | | 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 | | | | 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] | | | | 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 |  | Similar Visual Basic .NET bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,510 network members.
|