|
Pierre besquent wrote: HOW to test if arr [0] == '0' or not??
Well you could use a simple expression like:
if (arr[0] == '0')
if (arr[0] == 0x30)
if (arr[0] == 48)
You need to try and clarify your question as it is still not obvious to us what your problem is.
The best things in life are not things.
|
|
|
|
|
You are debugging in an IDE. It is showing you the integer value as well as the character, in case it is an unprintable character. arr[0] is still equal to '0' and the problem is that the two tests in your code contradict each other.
(edit: oops, not a BBcode forum.)
|
|
|
|
|
hi
how can I perform a group by on a DataTable's rows using dynamically determined group-by-columns?
For example, below, I group by "Symbol" and "Measure" - however, what if group by column is passed into the function as argument IList<string> GroupByColumnNames
<br />
static void TestLINQGroupBy()<br />
{<br />
#region Construct dummy data<br />
Random rnd;<br />
IList<string> Measures = new List<string>() { "eps", "bps", "close" };<br />
IList<string> Symbols = new List<string>() { "0001HK", "0002HK", "0003HK" };<br />
DataTable TestPrice = new DataTable("TestPrice");<br />
DataColumn c = null;<br />
DataRow newRw = null;<br />
<br />
DataColumn[] PKs = new DataColumn[3];<br />
c = new DataColumn("Symbol", typeof(string));<br />
TestPrice.Columns.Add(c);<br />
PKs[0] = c;<br />
<br />
c = new DataColumn("Measure", typeof(string));<br />
TestPrice.Columns.Add(c);<br />
PKs[1] = c;<br />
<br />
c = new DataColumn("RecordDate", typeof(DateTime));<br />
TestPrice.Columns.Add(c);<br />
PKs[2] = c;<br />
<br />
TestPrice.Columns.Add("Value", typeof(double));<br />
TestPrice.PrimaryKey = PKs;<br />
<br />
foreach (string Symbol in Symbols)<br />
{<br />
foreach (string Measure in Measures)<br />
{<br />
for (int iter = 1; iter < 12; iter++)<br />
{<br />
newRw = TestPrice.NewRow();<br />
newRw["Symbol"] = Symbol;<br />
newRw["Measure"] = Measure;<br />
rnd = new Random((Symbol + Measure + iter).GetHashCode());<br />
newRw["Value"] = rnd.NextDouble();<br />
newRw["RecordDate"] = new DateTime(DateTime.Now.Year, iter, 1);<br />
TestPrice.Rows.Add(newRw);<br />
}<br />
}<br />
}<br />
#endregion<br />
<br />
var q = from rw in TestPrice.Select()<br />
group rw by new {Key1=rw["Symbol"], Key2=rw["Measure"]} into key<br />
select key;<br />
foreach (var k in q)<br />
{<br />
Console.WriteLine(k);<br />
}<br />
return;<br />
}<br />
REF: 101 LINQ Examples[^]
dev
|
|
|
|
|
Have a look at this neat article[^], especially the GroupData function. Once you dynamically build the data, you can use
Func<DataRow, String> groupingFunction = GroupData; as shown in the article.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Hi,
I am calling a .dll from C#. There is no problem loading the dll and call some functions from C#, but one function call gives
"System.AccessViolationExceptionMessage: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
There is no problem to call this function from c++.
I suppose something is wrong with the structures I use in C# but I'm not sure what and how to solve this issue.
Using Visual Studio 2008.
********************************** C++ **********************************
typedef enum _MAPI_APN_TYPE
{
MAPI_APN_PRIMARY = 0,
MAPI_APN_ACTIVATION,
}MAPI_APN_TYPE;
typedef struct _MAPI_APN_DATA
{
wchar_t wcApn[80];
wchar_t wcUsername[80];
wchar_t wcPassword[80];
wchar_t wcDialNumber[80];
}MAPI_APN_DATA, * LPMAPI_APN_DATA;
typedef struct _MAPI_CORE_PATH
{
wchar_t strPath [ 260 ];
}MAPI_CORE_PATH, *LPMAPI_CORE_PATH;
***** c++ function that works: *******
MAPI_APN_DATA data;
MAPI_CORE_PATH path;
memset( &path, 0, sizeof( MAPI_CORE_PATH ) );
result = M_API_GetApnData( &path, MAPI_APN_ACTIVATION, &data );
********************************** C# **********************************
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MAPI_APN_DATA
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string apn;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string username;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string password;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string dialNumber;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MAPI_CORE_PATH
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string strPath;
}
public enum MAPI_APN_TYPE
{
MAPI_APN_PRIMARY = 0,
MAPI_APN_ACTIVATION,
};
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate MAPI_RESULT M_API_GetApnData(ref MAPI_CORE_PATH path, MAPI_APN_TYPE apn_type, ref MAPI_APN_DATA data);
private M_API_GetApnData fnMGetApnData;
pFunction = MbmFramework.Native.GetProcAddress(pMClientDll, "M_API_GetApnData");
fnMGetApnData = (M_API_GetApnData)Marshal.GetDelegateForFunctionPointer(pFunction, typeof(M_API_GetApnData));
MAPI_APN_DATA data = new MAPI_APN_DATA();
MAPI_CORE_PATH path = new MAPI_CORE_PATH();
MAPI_RESULT apiRes = fnMGetApnData(ref path, MAPI_APN_TYPE.MAPI_APN_ACTIVATION, ref data);
Best regards
Olof
modified on Monday, July 4, 2011 4:54 AM
|
|
|
|
|
Does the exception occur inside the fnMGetApnData() function? If so you need to track exactly what is going on in there, and without seeing the code it is impossible for anyone here to make a guess.
The best things in life are not things.
|
|
|
|
|
Yes, fnMGetApnData() is the unmanaged call to the dll. I don't have the source code to this dll. I tried to debug this unmanaged call in the assembler code but have not enought assembler experience. The only thing I can see is that a assembler "call" is causing the exception.
|
|
|
|
|
marca292 wrote: I don't have the source code to this dll
It's unlikely that anyone here will be able to guess what's going on. Is there any way you can get hold of the people who created the dll?
The best things in life are not things.
|
|
|
|
|
I was just wondering if anyone could see something wrong with my C# struct declaration that could cause this error.
Maybe, I shall see if I can get hold of the people who created this dll.
|
|
|
|
|
Make sure wchar_t is what you think it is. I don't see anything obviously wrong with the structure definitions.
Alternatively, does the function rely on the path being set to zeros? You are doing that in C++ and not C#. You might need to assign "\0" to path.strPath if the C function expects it to be set to zero length to start with. (I'm not sure what the marshalling does with an unassigned string variable in a struct. You might need to assign a value to all the string properties; a constructor or method on the struct to do that might be a good idea.)
|
|
|
|
|
Try changing the CharSet to CharSet.Ansi.
|
|
|
|
|
I'm confused as to why you're using the UnmanagedFunctionPointerAttribute to get the dll function and then go through all that marshalling mess. Wasn't a simple DllImport enough?
|
|
|
|
|
please send me code to run the project in asp .net
thanks
|
|
|
|
|
Arvind Vishwakarma wrote: please send me code to run the project in asp .net
What sort of question is that? Please note:
- This is not the ASP.NET forum
- You have not given any details about what problem you are trying to solve
- Working projects are not free, you either have to buy them or build them yourself
The best things in life are not things.
|
|
|
|
|
|
hey! be more specific while asking question and please don't ask to send me code because no one will send you code whatever
Try
ASP.NET - Database Connection[^]
|
|
|
|
|
How about doing a search on the internet for this information?
You could check out msdn for tutorials / quickstarts.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Hi,
i'm not sure how to describe my self (not sure what is the name of this issue)
i can write to console like this
Console.WriteLine("The answer of {0} + {1} is {2}",2,2,2+2);
how exactly this topic (of {0}... and the arguments) is called ?
any way, i was wondering if i can write something like this.
Dictionary <string,int> dic = new ...
string [] arr = {"hello","world"};
foreach (var str in arr)
{
dic.Add({0},str, str.Length);
}
I know that it's not the correct syntax, but i hope i was understandable enough...
|
|
|
|
|
Uh, no, I have no idea what you want, but would String.Format help?
|
|
|
|
|
The method has to support Composite Formatting[^] to use that syntax.
You can build the string first, perhaps using StringBuilder, String.Format(), string operators, etc., before adding it to the dictionary.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
If you want to write a function that accepts variable number of arguments like WriteLine does, you have to uses the params modifier.
http://msdn.microsoft.com/en-us/library/w5zay9db(v=VS.100).aspx[^]
In the format string {#} where # is a number refer to the the argument at that position starting at index 0 with the first argument after the format string.
Philippe Mori
|
|
|
|
|
Your sample doesn't really make any sense.
Why don't you just do it this way:
for (int i = 0; i < arr.Length; i++)
{
dic.Add(arr[i], arr.length);
}
One of the Console.WriteLine method overloads acts just like string.Format . You pass a format string, followed by an array of objects. The number inside the curly braces indicates the index into the specified object array. Just like all other arrays, this one is 0 based, and you can't specify a value < 0 or > the number of elements in the array (minus 1). You can specify the same array index over and over again:
WriteLine("{0}{0}{0}", "x", "y");
which would result in "xxx" being written
or even out of order:
WriteLine("{2}{1}{0}", "x", "y", "z");
which would result in "zyx" being written.
You can have more objects to format, but your indexes in the format string can never exceed the number of objects in the array.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
String.Format() does the trick, Console.WriteLine() internally uses String.Format() .
|
|
|
|
|
I'm unable to get ms access afterupdate event like functionality in c# textbox.
What I have done so far is:
private void VocNoTextBox_KeyDown(object sender, KeyEventArgs e)<br />
{<br />
if (e.KeyData.Equals(Keys.Enter))<br />
MoveToSpecificVocNo();<br />
}<br />
and Leave event
<br />
private void VocNoTextBox_Leave(object sender, EventArgs e)<br />
{<br />
MoveToSpecificVocNo();<br />
}<br />
But the problem is If I press enter and press tab to move to next field. The event is called twice. One for Enter key, another for Leave.
Is there any solution?
Regards
Asif Rehman
|
|
|
|
|
One way would be using a flag to indicate it had been run already.
At the form level:
private bool func_called = false;
In KeyDown you set it to true after calling the function:
private void VocNoTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData.Equals(Keys.Enter))
{
MoveToSpecificVocNo();
func_called = true;
}
}
And in Leave you reset it (if this is appropriate for what it does):
private void VocNoTextBox_Leave(object sender, EventArgs e)
{
if ( !func_called )
{
MoveToSpecificVocNo();
}
func_called = false;
}
Jack of all trades ~ Master of none.
|
|
|
|