|
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!
|
|
|
|
|
Use two split container controls; drop one on the form and set its dock property to fill, then drop another one in the left hand panel of the first split container and set its dock property to fill also but set its orientation property to horizontal. The main container and the subordinate container will adjust to fill the window during use and in response to resizing the form. You can still adjust the size of the panels by moving the splitter bars up and down or left and right.
|
|
|
|
|
Hi, thanks for replying me.
I've already tried this way, but using 2 splitContainers and setting one with Dock = Fill, opening a child window of the MDI container this is not visible because it appears (hide) under the container.
the problem is that my application should have a left panel as described before, but the rest of the main window shoud not be tabbed (as VS), but free for child windows.
any other suggestions?
-- modified at 4:25 Monday 23rd October, 2006
|
|
|
|
|
Hello,
Oh, the issue is with the MDI parent. Here is a solution:
1. Get rid of the split containers altogether.
2. Add a panel to the MDI form
3. Dock the panel to the left side
4. Drop a splitter control (not the split container, just the splitter) to the right of the panel.
5. Put a panel inside the left docked panel.
6. Dock this new panel to the top.
7. Drop another control beneath the new panel.
8. Dock the splitter control to the top.
9. Drop another panel under the new splitter control.
10. Dock the new panel to the full extent.
This will give you two panels that will adjust in size on the left hand side, you can put whatever controls you want to inside those panels. This also leaves the MDI form clear to accept adding forms to it.
I tested this and it works fine for both the splitters and as an MDI parent. If you have any additional problems with this, I would be glad to send you a working copy of it; just email me an address and I will forward it along.
Scott Lysle
|
|
|
|
|
Could anyone explain to me how to format a long value as a date time value?.
This is because I am using Btrieve as a data base and the datetime fields are store as long types.
Any help is greatly apreciated.
Regards,
|
|
|
|
|
Oh, btrieve, I'm sorry. We, unfortunately, also use btrieve here. But our dates are stored as a string. Probably because it's just a date and not a datetime. Do you know if the long represents seconds or milliseconds? There's probably also a starting date like 1/1/1980 or 1/1/1900. If you had this information you could probably have a constant defined for the start date and just use the AddSeconds or AddMilliseconds methods to add the long value.
|
|
|
|
|
If the Ticks for Btrieve equals Ticks for the System.DateTime then you can use this:
DateTime theTime = new DateTime(_longValue);
Otherwise you'd have to find out what the startday is for Btrieve and if it counts in milliseconds or nanoseconds etc, then modify the returnvalue to equal the format for System.DateTime before using the above codesnippet.
-Larantz-
for those about to code, we salute you
|
|
|
|
|
I have arrise a problem in c#. that is i have two string variables like StartTime and Endtime. StartTime is 2100 ( i.e. 9 p.m) and 0600 ( i.e. 6 a.m). How i get the accual hour. i.e 9 hours.
xzv
|
|
|
|
|
Well, here's an example of what you could do. I guess if you get a negative number, you could always add 24 to it. Or you could use AddDays to change the day used by DateTime. By default, it will use the current date.
string strStart = "0600";
string strEnd = "2100";
DateTime dtStart = DateTime.ParseExact(strStart, "HHmm", null);
DateTime dtEnd = DateTime.ParseExact(strEnd, "HHmm", null);
Console.WriteLine(dtStart);
Console.WriteLine(dtEnd);
TimeSpan ts = dtEnd - dtStart;
Console.WriteLine(ts.Hours);
|
|
|
|
|
Hi everyone,
In a bit of a knot here chasing my tail. I have a webbrowser control embedded in a C# windows app which is calling a .CFM page to provide XML data as an output. I need a way to get this content into a text box in the C# application so as further processing can be carried out.
I am new to C# and would welcome any help that may be provided. The interface works and the webbrowser carries out the action required on the .cfm page it is just the farming of the form fiedl data that is required.
Thank you in advance.
Jarlath
|
|
|
|
|
hi everyone
does anyone have an idea about how i can develop a desktop application via C#. NET?? what differantiates it from web based application?
yasemin
|
|
|
|
|
Desktop apps use client-side Windows Forms technology (unless it's a console app). The target machine must have the .NET framework installed.
Web apps use ASP.NET to generate client-side HTML and javascript which renders in a browser. The target machine does not need to have the .NET framework installed.
|
|
|
|