|
In C++, this would be exteremely easy (I can think of a couple of methods off the top of my head).
Yet... Is there a way in Pure C# to do this?
Just to clarify: I am talking about taking a void* (returned from a function like CoCreateInstance) and accessing a function without going through C# Com Interop. I read somewhere that someone did this by accessing the vtable of the interface pointer though he or she failed to mention how he or she did this.
Thank you in advance.
|
|
|
|
|
List<string[]> salesPeriod = new List<string[]>();<br />
string[] totalPeriodNo = new string[3];<br />
<br />
<br />
totalPeriodNo[0] = "AA";<br />
totalPeriodNo[1] = "0.01";<br />
totalPeriodNo[2] = "0.02";<br />
totalPeriodNo[3] = "0.03";<br />
salesPeriod.Add(totalPeriodNo);<br />
<br />
<br />
totalPeriodNo[0] = "BB";<br />
totalPeriodNo[1] = "0.06";<br />
totalPeriodNo[2] = "0.07";<br />
totalPeriodNo[3] = "0.08";<br />
salesPeriod.Add(totalPeriodNo);<br />
How can I go about editing BB for period 3 from 0.08 to 1.33 ?
|
|
|
|
|
Okay, a List has random-access support so just edit it the same way you would an array.
salesPeriod[1][3] = "1.33";
Hope that helps.
|
|
|
|
|
As you have added the same array to the list twice, you have a list with two reference to the same array. Therefore there is three ways of changing the period:
totalPeriodNo[3] = "1.33";
salesPeriod[0][3] = "1.33";
salesPeriod[1][3] = "1.33";
Either of these will change the item in the array. As the list is just two references to the same array, the change will be visible in both items of the list.
If you want two separate items in the list, you have to create a new array object before populating it with the BB data.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Maybe it was just a typo in your sample, but:-
string[] totalPeriodNo = new string[3];
declares a string array with 3 elements. These elements are indexed as 0, 1 and 2
so, your line:-
totalPeriodNo[3] = "0.03";
will throw an exception.
|
|
|
|
|
/method to convert decimal stored in "nDecimal"
//to two's complement representation, stored in array "bitstring"
private void decimal_to_twoc( )
{
int nDecimal = Convert.ToInt32(decimal_input.Text);
//string numBits = Convert.ToString(decimal_output.Text);
int carry = 1;
int flag = 0;
if (flag==0)
{
for (int i = 0; i < 8; i++)
bitstring[i] = bitstring[i] + 2;
bitstring[nDecimal] = carry;
carry = 0;
if (bitstring[nDecimal] > 1)
{
bitstring[nDecimal] = 0;
carry = 1;
It is givingme a wrong conversion from decimal to two's complement and I can figure out the reason. Any help please?
|
|
|
|
|
What are you trying to do ? Where is bitstring defined ? Obviously, it's not reset in this function, so whatever value it had, 2 is added to every element. I don't see how you remotely are interacting with the decimal, except as an index into an array. So, if your array has 8 elements, as it seems, a number > 8 will just crash it, right ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
This is where I started from, thanks.
.............................................................
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TwosComplement
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
for (int i = 0; i < 8; i++)
{ bitstring[i] = 0;}
twoc_output.Text = "enter an integer";
decimal_output.Text = "enter a length 8 bitstring";
}
private int[] bitstring = new int[8];
private int nDecimal;
//strings for reading the bitstring in and out
private string instring, outstring;
private string nextbit;
//helper function for flipping bits in the bitstring
private int negate(int x)
{
if (x == 1) return 0;
return 1;
}
//method to convert decimal stored in "nDecimal"
//to two's complement representation, stored in array "bitstring"
private void decimal_to_twoc( )
{
int nDecimal = Convert.ToInt32(decimal_input.Text);
string numBits = Convert.ToString(decimal_output.Text);
int carry = 1;
int flag = 0;
if (flag==0)
{
for (int i = 0; i < 8; i++)
bitstring[i] = bitstring[i] + 2;
bitstring[nDecimal] = carry;
carry = 0;
if (bitstring[nDecimal] > 1)
{
bitstring[nDecimal] = 0;
carry = 1;
}
}
}
|
|
|
|
|
OK, so your first issue is that the code, when it works, will only work once. Because you only reset the array once. Or is it meant to be cumulative ?
Angelinna wrote: private int negate(int x)
{
if (x == 1) return 0;
return 1;
}
Not sure that you call this, but is it really worth writing a function for ? How about just writing this:
return 1 - x;
and 1-x is something you can just code inline instead of making a call, surely ?
I'd have expected you'd need to use the & operator to work out what bits are set in the original number, what you're doing here seems to me to be doomed to fail.
bitstring[nDecimal] = carry;
This will just crash if nDecimal > 7 and won't ever do anything useful.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Ya , not really sure of what am doing. Would like the code to work for both positive and negative integers and should take care of any "out of range" errors.......
Otherwise would appreciate tips or web where I may read more on this.
Thanks.
|
|
|
|
|
|
Christian Graus wrote: reads to me like a two's complement is the same as !x + 1.
Signed numbers are stored as two's complement, so the easiest way to get it is to cast a signed number to an unsigned number:
int negAnswer = -42;<br />
uint twosComplement = (uint)negAnswer;
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi, I have two forms that both open windows, I need to get the response from a checkbox on Form2 and use it with Form1, Form2 is not a dialogue and needs to open all the time. Any ideas? Thanks.
|
|
|
|
|
Delegates.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
As Christian said - use delegates. Simple example I've given before here[^].
Edited link!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
modified on Friday, August 22, 2008 3:23 AM
|
|
|
|
|
The link "Here" leads nowhere ?
|
|
|
|
|
Edited the link - thanks for pointing it out.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Create 1 form & 1 userform a couple of buttons etc,etc , put the userform inside the form and check this out ok?!
I think you can read the code bellow.
/////////////////////////////////////////////
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
userControl11.MyTextEvent += new UserControl1.MyDelegate(userControl11_TextEvent);
userControl11.visibility_ev += new UserControl1.MyDelegate2(userControl11_visibility);
}
protected void userControl11_TextEvent(string textToSet)
{
textBox1.Text = textToSet;
}
protected void userControl11_visibility(bool visibility_b)
{
textBox1.Visible = visibility_b;
}
}
///////////////////////////////////
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public delegate void MyDelegate(string textToSet);
public event MyDelegate MyTextEvent;
private void button1_Click(object sender, EventArgs e)
{
if (MyTextEvent != null) //Checks if anyone has registered the event.
MyTextEvent("This is a sample text");
}
public delegate void MyDelegate2(bool visibility_dl);
public event MyDelegate2 visibility_ev;
private void button2_Click(object sender, EventArgs e)
{
if (button2.Text == "Hide")
{ visibility_ev(false); button2.Text = "Show"; }
else
{ visibility_ev(true); button2.Text = "Hide"; }
}
}
//////////////////////////////////////////
nelsonpaixao@yahoo.com.br
|
|
|
|
|
no need for delegates, if form 1 called form 2 and you have problems passing values from form 2 to form 1 just make accessor methods from form 2 that after form 2 is closed, you can get the values from form 2.. you can also make use of again accessor methods if you want to pass values from form 1 to form 2 that before showing form2, set first the values then show form 2
|
|
|
|
|
don´t use 2 forms, use 1 form and load userforms inside, like what i showed you before.
I would use many form, for exemple, if i wanted to create a chat application (to load private chat windows).
But ... you are the boss i don´t know what you are trying to achieve.
Good Luck
nelsonpaixao@yahoo.com.br
|
|
|
|
|
Hi there,
I would like find one or two open source projects that use test-driven development in good practices.
I will use them to understand how unit testing works in real world.
(The language can be Java or C#, does not matter so much.)
Any suggestion would be appreciated,
Regards,
sarp
|
|
|
|
|
NUnit, look at the tests for itself!
|
|
|
|
|
I want to see how test driven developed project goes and learn something from their experience via understand their code(open-source).
|
|
|
|
|
Hi all.
I've two picture box overlapping.In it I load .png file (with trasparent border).
But i can't see only the first PictureBox.
I've read a lot on internet but i haven't find a solution.
How can i enable the trasparency?
Thanks.
|
|
|
|
|
Try using a Panel instead to load the png file in. Set it's BackColor to to Color.Transparent . This should do it.
|
|
|
|