|
Thank you, Stefan. Here is a little twist. The elements of the control array are dynamically instantiated at run time. Is it possible to randomize elements from the control array?
|
|
|
|
|
I'm sorry, but I don't understand your question. Could you rephrase it and/or explain in greater detail what you want to do.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi,
I want to control the show/hide to another program. I use Process to start the program and make the initial window status Minimized. then I use Process to get the program main window handle and use windows API showwindow to hide the program i just started.
Everything looks fine but one thing. some of the control's visible property (or event, like viisble changed) in the started program are not correct. for example, the button is visible in the GUI, you can click and execute something, but you always get false when you check (get) the visible value . but I can use windows Api like iswindowvisible to get the right visible value.
I can use API to set/get the right value, but the related event fired are not correct!!
BTW, the program I started is created by C# (VS 2005).
Does anyone have some idea about this.
Thanks a lot in advance.
Alan Shen
MCAD for .NET Version
^~^~^~^~^~^~^~^~^~^~^
Great idea is the beginging of success!
|
|
|
|
|
Hi folks
Is there any way of manipulating mp3 files such as:
1) extracting a part of a file (the actual data) and saving it somewhere
or
2) concatenating say two files to produce a third file and saving that file?
Kind regards
Ross
|
|
|
|
|
Well, if you aren't looking to do it in code - or want an easier way - check out Audacity - it is open source and does this - you just need the LAME MP3 encoder for it.
If you needed to do it in code and were not doing a commercial release, I think you could paste their code into your app to do this.
David
|
|
|
|
|
Hi,
I have an array (which may change in length each time) of numbers (employeeid) and I want to create a random generator function to return one these numbers.
The only parameters I will be receiving are the array of numbers and the array length.
I'm new to C# so any sample code would be appreciated.
Thanks.
|
|
|
|
|
public int GetRandomInt(int[] array, int length)
{
return array[new Random.Next(0, length)];
}
|
|
|
|
|
Thanks for your reply.
I'm getting the follwoing error..
Error 2 'System.Random.Next()' is a 'method' but is used like a 'type'
All I require is just one number returned from the array.
Does return array not return a list of arrays or does the Next method refine it to one number?
Pardon my ignorance.
|
|
|
|
|
Belfast Child wrote: Does return array not return a list of arrays or does the Next method refine it to one number?
array is your variable that was passed to the method. Using the square brackets is indexing the array to retrieve one of the members of the array. Since it is an array of int, you will return an int, which is what the method signature specified.
|
|
|
|
|
Cheers Guys.
Figured it out.
Here's a test on a click button for anyone else interested
public int GetRandomInt(int[] array, int length) <br />
{<br />
Random ranNum = new Random();<br />
return array[ranNum.Next(0, length)]; <br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
int [] intArray;<br />
intArray = new int[3] {123, 321, 666};<br />
int randumNum = GetRandomInt(intArray, 3);<br />
randomLabel.Text = (randumNum.ToString());<br />
}
|
|
|
|
|
You should use ranNum.Next(length) instead of ranNum.Next(0, length) as it produces random numbers within the same range and is almost 2 times faster.
Also I would suggest to retrieve the array length dynamically instead of using a fix value. Either do it when you call the GetRandomInt method or even remove the length parameter and do it inside the method.
int randumNum = GetRandomInt(intArray, intArray.Length);
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Belfast Child wrote: Error 2 'System.Random.Next()' is a 'method' but is used like a 'type'
Random r = new Random();
r.Next(...)
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
You have to put parantheses on the constructor, i.e. use "new Random()" instead of just "new Random".
It's better to create the Random object once, and use that throughout the program, than to create a new one for every random number. When you create a new object, it will be seeded from the system clock, so if you create them too closely in time, the randomness will be poor. Also it's a waste of resources to create more than one Random object.
---
b { font-weight: normal; }
|
|
|
|
|
hi
i want to copy large file and show progressbar to show operation.
what is your suggest for this subject ?
please give me an example for progressbar and copy file.
thanks
|
|
|
|
|
|
hi ..
Bekjong don't said me how to use Stream.BeginRead() and Stream.Beginwrite and show percantage of operation in progressbar .
and please give me an example how to use these methods.
thanks
|
|
|
|
|
Realistically, this is going to slow down your copy operation, by quite a bit. He's saying you can read how big a file is, then read and write it a bit at a time, giving you access to a progress bar in your own code.
The better answer IMO is, you can't do it. Why give a progress bar at the cost of doubling the time the operation takes ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
Could any one help me understand this?.
I am reading an array of bytes and one of the fields is a long for the amount and I get this big number: 800000000 when it should be 80000.
Do I still have to do format the value to something else?
Regards,
|
|
|
|
|
It sounds like this could be a byte-ordering issue. See http://en.wikipedia.org/wiki/Endianness[^] for more information.
Of course, I could be completely wrong here. If you could provide a snippet of the code that was giving you problems, perhaps we could troubleshoot it.
|
|
|
|
|
I am trying to learn how to connect with a USB scale. This scale requires no special drivers and uses the HID POS class. I have a copy of all the available reports. Also, when I hook up the scale, I hear the nifty sound meaning the PC found the device. So, if I want to write a C# app to display the weight and to say "zero the scale" and so on, how do I get started? I've done serial stuff forever, but not USB and need to do it now.
Please point out some helpful places to look. I have started combing through this website and SurgeForce and Microsoft, so maybe I'll get lucky. It's just that we have never written USB pc apps from scratch before and we're sort of lost. Ideas?
Thanks.
Kenny O'Dell
Prinicpal R&D Software Eng
Mettler-Toledo Inc.
Worthington, OH
|
|
|
|
|
Hi,
Since it's a USB HID device, things are already much easier -- not that they were hard in the first place. The method of communicating with a HID device (redundant) in windows is this:
(Note: this is just a brief summary from my mind, detailed instructions can be found from this page, http://www.lvr.com/hidpage.htm[^])
1. Get the HID GUID for the system w/ the win api function HidD_GetHidGuid
2. Call the SetupDiGetClassDevs function which returns an array of active HID devices
3. Now, loop through each device and match against a product and vendor id of the device you want, using the SetupDiGetDeviceInterfaceDetail function
(this should be unique to each device and can be found via msinfo32.exe)
4. Now get the handle to the device with the CreateFile function an the device pathname from the previous step
5. Get the capabilities for the device, ie input/output report length (HID terminology)
6. SO now, you finally have the device and you can start communications with it
7. You can write to the USB HID when it has a handle to the HID
interface and knows the number of bytes it allows you to write. To write data, the
application copies the data to send to a buffer and calls win api function WriteFile . The
buffer size should equal the size reported in the OutputReportByteLength
property of the HIDP_CAPS structure returned by HidP_GetCaps . This
size equals the report size in bytes plus one byte for the Report ID, which is
the first byte in the buffer. (this is all obtained from step 5)
8. To read input from the device you use WriteFile's compliment, ReadFile a win api function.
... and that's about it! Just as long as you know the API of your device so you can make sense out of it's input you'll be fine. There's lots of work already done for .net HID interaction, all of which can be found from the HID page linked above.
/\ |_ E X E GG
|
|
|
|
|
Thanks for the reply. I'll dig into this and see how it goes. Normally, you can get some sort of a SDK from the mfg of the product, except WE ARE the one the make the device! Sort of embarrassing, but we're catching up. PC apps in .NET talking USB is a long way from deeply embedded assembly and C code. So, again thanks for the tips.
Kenny O'Dell
Prinicpal R&D Software Eng
Mettler-Toledo Inc.
Worthington, OH
|
|
|
|
|
//The problem is that bytes written to a FoxPro General Field are not being read back in correctly.
//This code will write 10 bytes to a general field and then read them back in. When the data is read back it will be incorrect.
//Part 1 of 2. Write a byte[] with values 0..9 to a foxpro 'General Field'
OleDbConnection oleDbConnection = new OleDbConnection(@"Provider=VFPOLEDB.1;Data Source=c:\blobTest\");
oleDbConnection.Open();
byte[] adtByte = new byte[10];
for(Int16 i = 0; i < 10; i++)//load the array with values 0,1,2,3,4,5,6,7,8,9
adtByte[i] = (byte)i;
OleDbCommand command = oleDbConnection.CreateCommand();
command.CommandText = "DELETE FROM image"; //clean up past attempts
command.ExecuteNonQuery();
command.CommandText = "INSERT INTO image (image_len, image_val) VALUES (?, ?)";
//foxpro table 'image' has two fields. image_len of type interger and image_val of type general.
OleDbParameter p1 = new OleDbParameter("?", OleDbType.Integer);
p1.Value = adtByte.Length;
command.Parameters.Add(p1);
OleDbParameter p2 = new OleDbParameter("?", OleDbType.Binary);
p2.Value = adtByte; //write the byte array as type binary - I think this is my problem????
command.Parameters.Add(p2);
command.ExecuteNonQuery();
command.Dispose();
//At this point we should have one row in the table and the values should be;
// image_len = 10
// image_value = 0123456789
//--------------------------------------------------------------
//Part 2 of 2. Read the row just created back into a pair of variables.
OleDbCommand oleDbCommand = new OleDbCommand("Select * from image", oleDbConnection);
OleDbDataReader oleDbReader = oleDbCommand.ExecuteReader();
while (oleDbReader.Read())
{
object objFieldImage = oleDbReader["image_val"];
byte[] inBytes = (byte[])objFieldImage;
object objFieldLen = oleDbReader["image_len"];
int iLen = Convert.ToInt32(objFieldLen);
//At this point image_len is 10 as expected.
//but inBytes has doubled in size and the value is all wrong.
}
thanks
|
|
|
|
|
Hi everyone.
I have to develop an MDI app and in the main window I want to put a sizable panel on the left (like Solution Explorer in VS).
So I created a SplitContainer (in which there is an other splitContainer) and set it vertical and "Dock = Left".
My problem is that while internal panels are sizable, the container itself isn't sizable (so it has the right border fixed) and it stands fixed in a portion of my main window.
How can i make the splitcontainer sizable? otherwise: is there a workaround (such as other controls instead of splitContainer)?
thanks!
|
|
|
|