|
Okay, like I mentioned at the end of my last post, have a timestamp and that can help you with the synch.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Hi,
I am trying to find a quick way to add 1 dimensional array into multidimensional array. For example:
<br />
object[] oneDArray1 = new object[10];<br />
object[] oneDArray2 = new object[10];<br />
object[] oneDArray3 = new object[10];<br />
Then, I need to add this array into 2D Multidimensional array.
<br />
object[,] twoDArray = new object[3, 10];<br />
The reason I need to do this is because I have a DataSet and I need to convert this DataSet to Excel Application.
Currently, I do the following:
<br />
oRng.Value2 = oDataTable.Rows[iRowIdx].ItemArray<br />
This code work if the Range is within single row. Now, if I have 1000 rows, this is process is very slow. It takes about 20 seconds to loop through the range and set the rows.
Alternatively, I could set the value of the range at one go. For example I want to set the value from Row #1 Column #1 to Row #1000 Column #1000, I must do
<br />
object[,] 2DMultiDimensionalArray = new object[1000, 1000];<br />
oRng = oSheet.get_Range("A1", "ALL1000");<br />
oRng.Value2 = 2DMultiDimensionalArray;<br />
In order to set the excel value at one go, I MUST convert each DataRow.ItemArray into MultiDimensional array. I need to add Single Dimensional Array into MultiDimensional array (NOT jagged array because I have try it and it throw an error).
An unhandled exception of type 'System.Runtime.InteropServices.SafeArrayTypeMismatchException' occurred in mscorlib.dll
Additional information: Specified array was not of the expected type.
Any help is greatly appreciated!
Thanks
|
|
|
|
|
Do you want to export a DataTable to Excel? I am asking, because I would then suggest to use instead of arrays two loops. An outer-loop to do your rows and a inner-loop to do your columns.
Much faster than arrays.
Regards,
Elizma
|
|
|
|
|
Hi Elizma,
Yes, I am indeed exporting DataTable to Excel.
Doing loop for each row and each column will be quick if the number of columns aren't big. Here, I am talking about about 1000+ rows by 1000+ columns.
Currently, if I do
for (int iRow = 0; iRow < dt.Rows.Count; iRow++)
{
oRng = oSht.get_Range("A" + iRow.ToString(), strLastCol + iRow.ToString());
oRng.Value2 = (System.Array)dt.Rows[iRow].ItemArray;
}
This code is about 30x faster than nested loop. In my PC this loop takes about 20 seconds where as nested loop (to set each cell) takes about 10 minutes.
However, if you set directly to MultiDimensional Array, it takes less than 1 second (and probably few seconds to add the 1D array into Multidimensional array).
I am starting to think that it is impossible to add 1D array to Multidimensional array without nested loop
Any other idea to speed up this process? Thanks for any input/help.
Cheers
|
|
|
|
|
Hope this[^] article will give an idea about the arrays.
Regards,
Satips.
Don't walk in front of me, I may not follow;
Don't walk behind me, I may not lead;
Walk beside me, and just be my friend. - Albert Camus
|
|
|
|
|
Hi Satips,
Thanks for the link. But it doesn't answer my question
|
|
|
|
|
Satips do you intentionally just answer questions badly?
|
|
|
|
|
Hi,
I embedded windows media player 11 on a form, and I add a few files to the currentplaylist of it. like:
WMPLib.IWMPMedia m= wmp.mediaCollection.add(sFile);
wmp.currentPlaylist.appendItem(m);
I want this playlist "Repeat" forever. but the function "repeat/Ctlcontrols.repeat" is gone. How to do this????
I don't want to create my own timeline thread to check the duration by the way.
Also I could not use the StatusChange and PlayStateChange event, it is not recommended by MS.
thanks a lot in advance!!
Alan Shen
MCAD for .NET Version
^~^~^~^~^~^~^~^~^~^~^
Great idea is the beginging of success!
|
|
|
|
|
hello all;
i am working with an external electronic curcuit and i want to take the data that this circuit provides by serial port to the computer and by windows application open the port and read the data and finally to draw these data.
please any body hase an idea about how can i do what i am talking about using c# 2005 please help me.
Thank you all
ahmad al-omar
ahmad al-omar
|
|
|
|
|
It is very simple to open/read from a port in .NET.
Investigate (aka MSDN/Google) the System.IO.Ports namespace and in particular the System.IO.Ports.SerialPort class.
A small sample:
System.IO.Ports.SerialPort port = new System.IO.Ports.SerialPort("COM1"); //whatever com-port your device is hooked to
port.Open();
string oneLine = port.ReadLine();
Hope this gets you started.
-Phil
|
|
|
|
|
thank you
i made a button to open the port and other to read the data but when i click on the read button my PC stop working and i have to reset it
may be i wrote a wrong code and may be i choose wrong COM port
i will try it again
thank you
ahmad al-omar
|
|
|
|
|
[shameful plug]Take a look at my article on Terminal3[^], this has a simple graphing feature built into it as a demonstration. If you have any queries don't hesitate to ask.[/shameful plug]
|
|
|
|
|
thank you
but i dont know how to use your program when i choose terminal or graph no thing appears to me i dont know how to use it , can you help me in order to understand the operation.
thank you
ahmad al-omar
|
|
|
|
|
The code which displays stuff on the graph is in GraphWindow.cs. I intended this program as more of a reference than to actually use it. To see stuff in action do the following:
- File | New | Graph
- Click the SerialPort icon on the toolbar, this will add a port to the graph window (multiple ones are supported).
- Click the little drop-down arrow of the new button and select Properties.
- Edit the port settings to what you require (note you must change the Color as this defaults to White and will not display on the graph).
- Click the little drop-down arrow and select open, this will open the port and is ready to receive data.
To see data being plotted the sample program requires that data being read on the serial port has two double values seperated by a comma, it then splits these and uses them as the X and Y values of the graph. Note this was an example so there is no complex error checking or anything like that. One problem you might come across is the two values and the comma must be read in all at the same time. How I used this as a demo for my colleagues was to set up the com0com virtual serial port drivers and then I could have another window open in the terminal window and use the combo box to send the comma-seperated values as one string.
Hope that helps, by the way, if you're doing work with serial ports I strongly recommend installing these virtual ports, it makes it perfect for testing stuff because you don't need two hardware ports and a null modem cable, what you write to one port (COM10 on mine) is sent out on the other (COM11 on mine) and vice versa so you can get applications to talk to each other and you can debug things in Hyperterminal etc without having to hook up the hardware system.
|
|
|
|
|
I have an odd problem with remoting. I have an application that acts as a server for my remote object and also acts as a client for the same object (so it can work on it and react to changes to it). So in this case the object is in not just on the same machine, but even in the same process. Now this works fine most of the time, but on some machines, when the computer is connected to the internet it works, but when it's disconnected it doesn't work. I get an error "No connection could be made because the target machine actively refused it".
I added a sleep statement between the publishing of the object and the attempt by the server to connect to it and I could see using netstat.exe that the object is published and listening. Does anybody have any ideas as to what might be happening here?
Of course, it works just fine on my development box
|
|
|
|
|
Sounds like a dns problem of some sort.
Did you define the connectionstring to the hosting process as localhost or someother hostname? If the hostname cannot be resolved due to lost connection to your dns server, you might get the results you're seeing.
-Larantz
|
|
|
|
|
Thanks for the reply.
I should be connecting to the localhost. Here's how I have it set up:
BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();<br />
provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;<br />
IDictionary props = new Hashtable();<br />
props["port"] = mySettings.TCPPort; <br />
TcpChannel channel = new TcpChannel(props, null, provider);<br />
ChannelServices.RegisterChannel(channel, false);<br />
RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyMessenger), "MyRemoteService", WellKnownObjectMode.Singleton);<br />
<br />
messenger = (MyMessenger)Activator.GetObject(typeof(MyMessenger), "tcp://localhost:" + mySettings.TCPPort + "/MyRemoteService");
Am I doing this correctly?
|
|
|
|
|
Looks correct to me.
Then I'm not sure what's causing your problem.
-Larantz-
|
|
|
|
|
Hi.
Can direct me, from where should I start .Net 3?
I don't have any idea about it.
Best wishes
|
|
|
|
|
Downloading the framework!
After that write the famouse Hello World! program. And after that use your imagination
|
|
|
|
|
hahah!!!
Well said!!
by the way y is it always the hello world program!!!
I was born dumb!!
Programming made me laugh !!!
--sid--
|
|
|
|
|
yeah, I'm sure that Google doesn't have ANY links about the subject.
_____________________________________________
Flea Market! It's just like...it's just like...A MINI-MALL!
|
|
|
|
|
You're just getting bitter.... :P
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I'm bitter about several things today and posts like these is just like poking a bruise.
_____________________________________________
Flea Market! It's just like...it's just like...A MINI-MALL!
|
|
|
|
|
leckey wrote: I'm bitter about several things today
Would it have anything to do with those circular reports you posted about the other day?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|