|
Thanks for all your help,
This is the runtime exception I am getting "AccessViolationException".
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
My code does compile. I just trimmed it down since it will be too long.
As far as I know about backgroundWorker, in DoWork event args.Result stores the result of long running process.
And this result is available in RunCompleted event as args.Result.
In my case the array allResponses is not modifying at all after the work is done. I have to modify that array in all three long running processes.
I am using VS2008. My upload is working perfectly fine without progressBars and threads.
I think there is some locking issue.
Thanks,
|
|
|
|
|
Hello there i need to build a receipt number the values that am receiveing is this
RecieptCode LastRecieptNumber RecieptDisplayDigits
Rcp2008- 248 8
now the main prob is in receipdisplayDigits
i know in python if i write z*8 it will be zzzzzzzz
i want the same thing in C# but if i did it i will not be able to add the last reciept number/
how could this be done?
i have another method but am sure there would be a better one my method is to add the lastreceiptnumber
with 10^(receipt display digt) then i remove the 1 and write the receipt code it will look like this
the example above
10^8 = 100000000
100000000 + 249 (since it should be new receipt) = 100000249
Convert it to string and remove the 1 = 00000249
Then i add the receipt code
Is there better way taking into concideration the performance
Best Regards
|
|
|
|
|
The reciept will be Rcp2008-00000249
please note that the receipt code is Rcp2008-
receiptLat number is 248
diplay digits is 8
|
|
|
|
|
If I understood correctly, you can do like this:
string receiptCode = "Rcp2008";
int lastReceiptNumber = 248;
int receiptDisplayDigits = 8;
string receiptString = lastReceiptNumber.ToString().PadLeft(receiptDisplayDigits, '0');
string fullReceiptCode = string.Format("{0}-{1}", receiptCode, receiptString);
EDIT: expanded taking into account your second post.
|
|
|
|
|
it worked fine but i did not understand the last line of code could you explain it please??
|
|
|
|
|
string receiptString = lastReceiptNumber.ToString().PadLeft(receiptDisplayDigits, '0');
This line converts lastReceiptNumber to string, then adds as many 0 at its left as it's needed to have a string receiptDisplayDigits characters long.
You cas also do as musefan suggested and use receiptString = lastReceiptNumber.ToString("D" + receiptDisplayDigits); instead.
After this line, receiptString will be 00000249 .
string fullReceiptCode = string.Format("{0}-{1}", receiptCode, receiptString);
This line will concatenate the string created in the first line with receiptCode , using a template to define the string format.
You can also use a direct string concatenation (string fullReceiptCode = receiptCode + "-" + receiptString; ).
After this line, fullReceiptCode will be Rcp2008-00000249 .
|
|
|
|
|
Ahh ok ok man thanks alot i knew this but i forgot it because its been a while since i used {0} {1}...
|
|
|
|
|
It did not work the thing you wrote about padding left since when i convert to int
the 0000000000 will turn into 0
but thanks you gave me an answer about the padding thing
|
|
|
|
|
That's right, the padding is related to strings, if you convert back the string to int, you will lose al format you have applied to it.
|
|
|
|
|
I really like the logic you have used in getting a value with 8 digits, it's great to see people thinking along those lines rather than expecting things to be done with a simple 'out the box' line of code (and thus never really learning how things are actually acheived).
But in instances like this one-liners are the way to go, so hope this helps...
int newNumber = lastReceiptNumber + 1;
string displayNumber = newNumber.ToString("D" + receiptDisplayDigits);
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Thanks man i really appreciate it, we ask question so we could learn how to solve them other wise we are not programers we are just people who ask questions
|
|
|
|
|
Exactly, and questions like yours will always be welcome in The Code Project forums
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Man it worked great but could you explain what is the use with "D" i did not know what did it do.
|
|
|
|
|
some data types (such as int) have the option to overload the ToString method and provide a string containing format information. 'D' followed by a number ensures that the string contains as many preceding zeros as dictated by the number. have a look here[^] for more information
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I am using Relection to get Methods from an Assembly.
I want to display the local Variable names in a method.
I have a test method called Test.
public void Test()
{
string myString = string.Empty;
int myInt = 0;
}
So I am using the following code:
MethodInfo[] methodInfo = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
List<MethodInfo> methods= new List<MethodInfo>(methodInfo);
foreach (MethodInfo method in methods)
{
MethodBody methodBody = method.GetMethodBody();
IList<LocalVariableInfo> localVariables = methodBody.LocalVariables;
}
My problem is, even if I loop through the localVariables collection, I am not able to get the name of the variables of Test Method.
Kindly let me know how do I get the variable names.
Thanks in Advance.
|
|
|
|
|
Hi,
AFAIK local variables are not available in the meta data, except for the method's parameters.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Correct. Reflection only exposes the interface, not the implimentation.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Agreed, I know that,
but I could see the variable names in the method in ildasm so I thought there might be a way to get those. I know ildasm is DISASSEMBLER but took a chance.
Thanks for reply,
Aniruddha
|
|
|
|
|
Hi,
forget Reflector, it won't tell you about locals. You need either the source files or, maybe, the PDB file.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Anir1982 wrote: Kindly let me know how do I get the variable names.
You can't and that is the end of it. It would require that reflection exposes the implimentation of the method rather than the interface.
What use would it be if you could in the long run? You cannot [or should not] be able to change the state of internal variables. Local variables only have scope within the life of a single call to the method. How or when would you be able to constructively use the instance or local variables of a class or method?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
How Can I Select any Row In DataGridVeiw
|
|
|
|
|
example :
dataGridView1.Rows[3].Selected = true;
|
|
|
|
|
Thanks But How Can I MOve The ScrollBar To That Row
|
|
|
|
|
dataGridView1.FirstDisplayedScrollingRowIndex = 3; // set the index of row here..
|
|
|
|
|
I Am Greatfull.
Thanks Again
|
|
|
|