I do the following:
Select Case mDataType(mColumnToSort)
Case TypeCode.Int32
Result = CInt(xText).CompareTo(CInt(yText))
Case TypeCode.String
Result=...
I wonder if I could somehow write one statement that would compare all types
using mDataType(mColumnToSort) to automate the conversion? 9 2996
" **Developer**" <RE*************@a-znet.com> schrieb I do the following:
Select Case mDataType(mColumnToSort)
Case TypeCode.Int32
Result = CInt(xText).CompareTo(CInt(yText))
Case TypeCode.String
Result=... I wonder if I could somehow write one statement that would compare all types using mDataType(mColumnToSort) to automate the conversion?
result = directcast(xtext, icomparable).comparto(ytext)
Assumed that xtext implements IComparable. IComparable is there to support
the concept of comparing objects.
Armin
Added a litte more
I do the following:
Select Case mDataType(mColumnToSort)
Case TypeCode.Int32
Result = CInt(xText).CompareTo(CInt(yText))
Case TypeCode.Single
Result = CSng(xText).CompareTo(CSng(yText))
Case TypeCode.Double
Result = CDbl(xText).CompareTo(CDbl(yText))
Case TypeCode.String
Result=...
I wonder if I could somehow write one statement that would compare all
types
using mDataType(mColumnToSort) to automate the conversion?
Select Case mDataType(mColumnToSort)
Case TypeCode.Int32
Result = CInt(xText).CompareTo(CInt(yText))
Case TypeCode.Single
Result = CSng(xText).CompareTo(CSng(yText))
Case TypeCode.Double
Result = CDbl(xText).CompareTo(CDbl(yText))
Case TypeCode.String
Result=...
I added a little more above.
Notice the conversions before the comparisons.
I believe the suggestion below will always compare the text as text.
Thanks I wonder if I could somehow write one statement that would compare all types using mDataType(mColumnToSort) to automate the conversion?
result = directcast(xtext, icomparable).comparto(ytext)
Assumed that xtext implements IComparable. IComparable is there to support the concept of comparing objects.
Armin
" **Developer**" <RE*************@a-znet.com> schrieb Select Case mDataType(mColumnToSort) Case TypeCode.Int32 Result = CInt(xText).CompareTo(CInt(yText)) Case TypeCode.Single Result = CSng(xText).CompareTo(CSng(yText)) Case TypeCode.Double Result = CDbl(xText).CompareTo(CDbl(yText)) Case TypeCode.String Result=...
I added a little more above. Notice the conversions before the comparisons. I believe the suggestion below will always compare the text as text.
If xText and yText are strings, you are right. What types do you expect? If
it's Int32, Single and double only, you could simplify it by using cdbl for
these types because the value range includes the other types. String must be
handled seperatly. As there is no general parse method for all data types,
you will have to handle them individually.
Armin As there is no general parse method for all data types, you will have to handle them individually.
That what I was wondering about.
Thanks
**Developer**
In addition to the other comments.
I would use something like:
Dim dataType As TypeCode
Dim xText, yText As String
Dim xObject, yObject As Object
Dim result As Integer
xObject = Convert.ChangeType(xText, dataType)
yObject = Convert.ChangeType(yText, dataType)
result = Comparer.Default.Compare(xObject, yObject)
- or -
result = Comparer.DefaultInvariant.Compare(xObject, yObject)
Convert.ChangeType will change the text variable to the requested type code
(Int32 for example). Be certain to review ChangeType's overloads!
Comparer.Default does the comparison based on Thread.CurrentCulture, while
Comparer.DefaultInvariant does the comparison based on
CultureInfo.InvariantCulture.
Hope this helps
Jay
" **Developer**" <RE*************@a-znet.com> wrote in message
news:Oe**************@TK2MSFTNGP14.phx.gbl...
|I do the following:
|
| Select Case mDataType(mColumnToSort)
|
| Case TypeCode.Int32
|
| Result = CInt(xText).CompareTo(CInt(yText))
|
| Case TypeCode.String
|
| Result=...
|
|
|
| I wonder if I could somehow write one statement that would compare all
types
| using mDataType(mColumnToSort) to automate the conversion?
|
|
That's great. Just what I wanted!
One aside, Some numbers as text are of format 123,456,789
If I used Cint it is smart enough to handle them.
But Convert.Change to Int32 is not.
I can make this a special case but do you happen to know a type that
supports numbers like that?
Thanks a lot
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2*****************@TK2MSFTNGP15.phx.gbl... **Developer** In addition to the other comments.
I would use something like:
Dim dataType As TypeCode Dim xText, yText As String Dim xObject, yObject As Object Dim result As Integer
xObject = Convert.ChangeType(xText, dataType) yObject = Convert.ChangeType(yText, dataType)
result = Comparer.Default.Compare(xObject, yObject)
- or -
result = Comparer.DefaultInvariant.Compare(xObject, yObject)
Convert.ChangeType will change the text variable to the requested type code (Int32 for example). Be certain to review ChangeType's overloads!
Comparer.Default does the comparison based on Thread.CurrentCulture, while Comparer.DefaultInvariant does the comparison based on CultureInfo.InvariantCulture.
Hope this helps Jay
" **Developer**" <RE*************@a-znet.com> wrote in message news:Oe**************@TK2MSFTNGP14.phx.gbl... |I do the following: | | Select Case mDataType(mColumnToSort) | | Case TypeCode.Int32 | | Result = CInt(xText).CompareTo(CInt(yText)) | | Case TypeCode.String | | Result=... | | | | I wonder if I could somehow write one statement that would compare all types | using mDataType(mColumnToSort) to automate the conversion? | |
**Developer**,
Have you looked at the overloads to ChangeType? One of them accepts a format
provider, Is there a format provider you can pass that will ignore the
commas?
If I get a chance to later I will look. Post if you find something.
Hope this helps
Jay
" **Developer**" <RE*************@a-znet.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
| That's great. Just what I wanted!
|
| One aside, Some numbers as text are of format 123,456,789
|
| If I used Cint it is smart enough to handle them.
|
| But Convert.Change to Int32 is not.
| I can make this a special case but do you happen to know a type that
| supports numbers like that?
|
|
| Thanks a lot
|
|
| "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
| news:%2*****************@TK2MSFTNGP15.phx.gbl...
| > **Developer**
| > In addition to the other comments.
| >
| > I would use something like:
| >
| > Dim dataType As TypeCode
| > Dim xText, yText As String
| > Dim xObject, yObject As Object
| > Dim result As Integer
| >
| > xObject = Convert.ChangeType(xText, dataType)
| > yObject = Convert.ChangeType(yText, dataType)
| >
| > result = Comparer.Default.Compare(xObject, yObject)
| >
| > - or -
| >
| > result = Comparer.DefaultInvariant.Compare(xObject, yObject)
| >
| >
| > Convert.ChangeType will change the text variable to the requested type
| > code
| > (Int32 for example). Be certain to review ChangeType's overloads!
| >
| > Comparer.Default does the comparison based on Thread.CurrentCulture,
while
| > Comparer.DefaultInvariant does the comparison based on
| > CultureInfo.InvariantCulture.
| >
| > Hope this helps
| > Jay
| >
| >
| > " **Developer**" <RE*************@a-znet.com> wrote in message
| > news:Oe**************@TK2MSFTNGP14.phx.gbl...
| > |I do the following:
| > |
| > | Select Case mDataType(mColumnToSort)
| > |
| > | Case TypeCode.Int32
| > |
| > | Result = CInt(xText).CompareTo(CInt(yText))
| > |
| > | Case TypeCode.String
| > |
| > | Result=...
| > |
| > |
| > |
| > | I wonder if I could somehow write one statement that would compare all
| > types
| > | using mDataType(mColumnToSort) to automate the conversion?
| > |
| > |
| >
| >
|
|
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:Oz**************@TK2MSFTNGP14.phx.gbl... **Developer**, Have you looked at the overloads to ChangeType? One of them accepts a format provider, Is there a format provider you can pass that will ignore the commas?
I'll check but if that doesn't work out I just pass Nothing or Empty or
something to indicate comma seperated integer. I'd maybe make it the Option
default value but I like String for that. If I get a chance to later I will look. Post if you find something.
Don't spend any more time on it. I really appreciate the help. Hope this helps Jay
| But Convert.Change to Int32 is not. | I can make this a special case but do you happen to know a type that | supports numbers like that? |
All I had to do is check the TypeCode enum and I could answer my own
question: No there isn't. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Matt |
last post by:
I'm new to Java but experienced with PL/SQL. I've found what appears to be
strange behaviour (a bug?) when attempting to create java stored objects
using the UNIX version of Oracle SQL*PLUS...
|
by: Dany |
last post by:
I am trying to find a nice way to compare objects (tables, colums,
indexes, primary and fk) between my production and my test dabatase.
I would like to known if their are tricks or tools...
|
by: Kenneth Baltrinic |
last post by:
I am trying to compare values coming out of a database record with known
default values. The defaults are in an array of type object (because they
can be of any basic data type, I am not working...
|
by: Frank |
last post by:
I have 2 objects that have the same complex structure and I would like
to know if a member has change and which one(s).
For example:
public struct Person
{
public long m_nID;
public...
|
by: tony |
last post by:
Hello!
When exactly is it important or advisable to use this form load event
handler compare to using the C-tor.
For example here I create an event handler called dataBoundGridForm that is...
|
by: mailsandiproy |
last post by:
case:
class employee
{
int roll;
string name;
}
just try to sort an array of 10 objects using the name field ( asceding / descending)
|
by: sammyboy78 |
last post by:
I'm trying to display an array of objects using a GUI. My instructions are that the CD class and it's sublcass don't need to change I just need to modify class CDInventory to include the GUI. I'm not...
|
by: nagarwal |
last post by:
hi frnds,
I am facing a prblm in displaying the contents of an ArrayList which contains 'String' Objects using logic:iterate tag..
example:
in the Action :
String s=null;
String s1=null;...
|
by: vai |
last post by:
hi all,
i'm developing a stock management system.
in this system i'm developing a billing system which on daily & monthly basis.
i'm using ms-acess database as backend & visual baic as front end....
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |