473,887 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Nov 21 '05 #1
6 2134
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" <no*****@nospam .com> wrote in message
news:%2******** **********@TK2M SFTNGP14.phx.gb l...
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

Nov 21 '05 #2
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:
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" <no*****@nospam .com> wrote in message
news:%2******** **********@TK2M SFTNGP14.phx.gb l...
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


Nov 21 '05 #3
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" <no*****@nospam .com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
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:
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" <no*****@nospam .com> wrote in message
news:%2******** **********@TK2M SFTNGP14.phx.gb l...
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

unfortunatel y, 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



Nov 21 '05 #4
Maileen wrote:
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
Nov 21 '05 #5
thanks Marina,

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

maileen

Marina wrote:
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" <no*****@nospam .com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
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:
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" <no*****@nospam .com> wrote in message
news:%2***** *************@T K2MSFTNGP14.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

unfortunate ly, 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

Nov 21 '05 #6
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
Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
8764
by: usgog | last post by:
I need to implement a function to return True/false whether String A contains String B. For example, String A = "This is a test"; String B = "is is". So it will return TRUE if String A includes two "i" and two "s". The function should also handle if String A and B have huge values, like two big dictionary. What's the best approach to achieve this with the best performance? what's the Big O then? I am thinking to put A and B into two...
32
49747
by: Wolfgang Draxinger | last post by:
I understand that it is perfectly possible to store UTF-8 strings in a std::string, however doing so can cause some implicaions. E.g. you can't count the amount of characters by length() | size(). Instead one has to iterate through the string, parse all UTF-8 multibytes and count each multibyte as one character. To address this problem the GTKmm bindings for the GTK+ toolkit have implemented a own string class Glib::ustring...
19
9540
by: David zhu | last post by:
I've got different result when comparing two strings using "==" and string.Compare(). The two strings seems to have same value "1202002" in the quick watch, and both have the same length 7 which I have tried to print out by debug.writeline(). But the "==" operator results false, and string.Compare() results true. Somebody helps me!
10
14499
by: lchian | last post by:
Hi, For two stl strings s1 and s2, I got different results from strcmp(s1.c_str(), s2.c_str()) and s1.compare(s2) can someone explain what these functions do? It seems that strcmp gives the "right" (i.e.wysiwyg) answer while compare() does not.
14
24296
by: Mosfet | last post by:
Hi, what is the most efficient way of doing a case insensitive comparison ? I am trying to write a universal String class and I am stuck with the case insensitive part : TCHAR is a char in MultiByte String env (MBCS) and wchar_t if UNICODE #if defined(WIN32) || defined(UNDER_CE)
11
2346
by: Tony | last post by:
Hello! Below I have two different ways to test if the instance tb.Text contains the string "Programmer" So which one to use is it just a matter of taste ? Or could it be some advantage to one before the other. In a book I read they had used the second one but I prefer the first one because it it clearer.
11
4387
by: blunt | last post by:
trying to write a program to write the configuration files for a load of wireless access points. i've never been a good programmer and haven't done any for nearly a decade so have obviously made some mistakes, i'm using cygwin on a windows pc and it seems that some functions cause stack overflows so am using fgets instead of fgetc (don't know y it solved the problem but that part is working). my problem now is that i am reading strings a few...
1
1758
by: blunt | last post by:
trying to write a program to write the configuration files for a load of wireless access points. i've never been a good programmer and haven't done any for nearly a decade so have obviously made some mistakes, i'm using cygwin on a windows pc and it seems that some functions cause stack overflows so am using fgets instead of fgetc (don't know y it solved the problem but that part is working). my problem now is that i am reading strings a few...
5
3633
by: erictheone | last post by:
so here is my code. My getlines for the strings keyword and phrase at lines 44 and 79 respectively don't work. Please help!!! #include <cstdlib> #include <string> #include <iostream> #include <fstream> using namespace std; string removeAllWhite( string eric) {
0
9957
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11173
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10875
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9593
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7988
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7141
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6011
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4238
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.