nmaillet 97 Posting Whiz in Training

Oh, why not:

int i;
clock_t ticks;

ticks = clock();
for(i = 0; i < 100000000; i++);
ticks = clock() - ticks;

printf("Number of ticks:   %ld\n", ticks);
printf("Clocks per second: %ld\n", CLOCKS_PER_SEC);
printf("Time ellapsed:     %ld ms\n", ticks * 1000 / CLOCKS_PER_SEC));
getchar();

Note, I did this with a C++ compiler, but it should work with a C compiler (don't have a C compiler to test it with). Also note that the order of operations in the last printf statement are very important. Reversing the 1000 and CLOCKS_PER_SEC would give me a result of 0ms instead of 235ms (in my case, where there were ticks=235 and CLOCK_PER_SEC=1000), since this is integer arithmetic.

nmaillet 97 Posting Whiz in Training

You could use the clock() function in the time.h header. The 0 value has nothing to do with real world time (it can be based on the time the program started, but is implementation specific). It gives you the number of clock cycles (ticks) that have ellapsed, so you have to divide by CLOCKS_PER_SEC to get it in seconds.

Basically, get the return value at the beginning of your program and at the end, and use the difference to show execution time.

nmaillet 97 Posting Whiz in Training

Ah, ok. So you would use something similar to what I put above.

for(...)
{
    ...
    double d = all_prices[i1][i2] == string.Empty ? 0.0 : double.Parse(all_prices[i1][i2]);
    ...
}

The ? and : operators are just shorthand for:

for(...)
{
    ...
    double d;
    if(all_prices[i1][i2] == string.Empty)
        d = 0.0;
    else
        d = double.Parse(all_prices[i1][i2]);
    ...
}

You could use either one, it doesn't really matter. Also, string.Empty is equivalent to "", it doesn't really matter which one you use. Without your source code I can't really make any specific recommendations, but you should be able to use this as a starting point.

nmaillet 97 Posting Whiz in Training

What exactly do you mean? Something like this?

string.IsNullOrEmpty(all_prices[0][0]) ? 0 : int.Parse(all_prices[0][0]);

That example just returns 0 if it's null or empty, otherwise it parses the string (you could use float/double/decimal instead), but I'm not sure if that's what you're trying to do... If it is, could I ask why numeric values are being stored as strings?

nmaillet 97 Posting Whiz in Training

Create a for-loop, that iterates through each character, and ensure their ASCII (assuming you are not working with international representations) value is numeric, a hyphen or a decimal. At the same time, make sure you're checking for a hyphen at the beginning only, and only one decimal.

You could also use a regular expression library, but it's trivial enough that I wouldn't bother.

nmaillet 97 Posting Whiz in Training

Can you show your code, an example of the output, and what you would expect it to look like? In most cases, not using special characters like &amp; is breaking the XML standard (or at the very least creating issues for parses).

nmaillet 97 Posting Whiz in Training

Take a look at this article. It's in C#, but shouldn't be much of an issue to convert.

nmaillet 97 Posting Whiz in Training

Actually, it is as of C11.

Oh cool, I haven't followed the new C/C++ standards for a couple years. Nice to see them updating the standards, but, as you said, we'll see about the adoption. Thanks for the info.

nmaillet 97 Posting Whiz in Training

What have you tried? Do you have any source code? What results are you getting?

nmaillet 97 Posting Whiz in Training

Another project developped internally perhaps? I've never heard of a .NET library with that name, and Google didn't turn up anything... Maybe somebody else here has. Good luck.

nmaillet 97 Posting Whiz in Training

Assuming you're using WinForms, you could try handling the GotFocus and LostFocus events. Detecting whether a new program has been opened could cause issues, especially during startup, since you can't be sure your program is opened last, and Windows could be starting up a bunch of programs.

nmaillet 97 Posting Whiz in Training

Ok, that may be the root of the problem, but you'll have to check the sheet where the data gets dumped to (after the query is run). What you want to see is data headers, in the first column, then all the data below that. The error message you are getting is usually caused by a header being an empty cell. Make sure that each header has something in it (I don't know if that query outputs headers for you, check that).

nmaillet 97 Posting Whiz in Training

Access provides a file based database. This is quite different than an Oracle or SQL Server database. The latter have several processes which work as a middle-man between the client and the physical file(s). This would allow (I certainly should be possible, albeit I've never attempted it) the processes to see the updates to specific table, and notify connected clients (assuming the connections actually remain open). An Access database, on the other hand, has several processes (client applications) making changes directly to the file, and no real method of pushing a notification to any of the other processes.

As an aside, I've heard that you shouldn't use SQL Server Compact (another file based database) databases on network drives (if that's how you're currently doing it), as the file locking can be flakey, which could cause some concurrency issues. I don't know if Access has some method of overcoming this, but you should look into that.

So, you have a few options (non very ideal), other than moving to another database platform:

  • Write a custom server application as a wrapper for the database, that is able to manage the connections and push out notifications.
  • Poll the database for changes.
  • Have each client application connect to each other (or a central location, if possible) to push updates to each other. I wouldn't really recommend this though.

Unless anybody has some ideas, that's all I can think of. Good luck.

nmaillet 97 Posting Whiz in Training

Yes, but it's not built in to the language or standard libraries. You'll need to use a third-party library to create and manage threads. For Windows, you can use the WinAPI; here is the Process and Thread Reference.

nmaillet 97 Posting Whiz in Training

There are some capitalization errors. C# is case sensitive. If you have any more problems, please post the error you're getting and any relevant information.

nmaillet 97 Posting Whiz in Training

Take a look at this. Basically, you'll want to use Double.toLongBits(f) or Double.toRawLongBits(f) (the difference between the two pertains to NaN values; see the documentation). These will give you a long integer, which you should be able to use Long.toHexString() to get the actual IEEE 754 value.

nmaillet 97 Posting Whiz in Training

You can give CG Textures a try. Their textures are free to use, with a few restrictions (see the license/FAQ).

As for "free" professional game engines, there are a few:

  • Unity: Free for the basic license, and $1500 for the Pro version. From what I here, it is one of the easiest to use.
  • UDK: Royalty based license, if you end up selling your game. This is built on the Unreal Engine 3 (used by many developers). It does lack some features from the full UE3 (such as native code, source code, etc.), but is quite full featured. It's interface could use some updating (and they seem to be getting there with UE4 demos, which should eventually make its way to the UDK). There are quite a few tutorials around for it.
  • CryENGINE 3 SDK: Similar license to the UDK. There isn't as much community support (yet) as Unity or UDK, from what I hear.

There's more out there, but these 3 stick out to me the most.

joycedaniels commented: Indeed But I think CG textures basically has textures for Maya and Max softwares. It won't be having like normal pics. Textures like skin or pebbles. +0
nmaillet 97 Posting Whiz in Training

Nope, it causes a "return" from the current method. It isn't quite a return, as no value is returned, and no variable will be assigned a return value. The exception will propogate through the call stack until it is caught in a try-catch block. In other words, the calling method will stop executing, and its calling method will stop executing and so on, until it is caught.

nmaillet 97 Posting Whiz in Training

Try this tutorial. W3Schools generally has some decent information for web development.

nmaillet 97 Posting Whiz in Training

It shouldn't be anything wrong with the code. Check the cells where the pivot table is getting its data from. At least the first row shouldn't contain any empty cells. See this article.

nmaillet 97 Posting Whiz in Training

Well, you can either call g.setColor(), followed by g.fillRect() to redraw the background. Or you can simply use g.clearRect() to redraw the background colour.

nmaillet 97 Posting Whiz in Training

You're using a char array (ie. a string), which the switch statement cannot work with. I tested it with switch(Pl.Level[0]), and it compiles. On the same note, Pl.Level='1'; would change the address of the pointer, not the first value in the array.

nmaillet 97 Posting Whiz in Training

It's certainly possible, but image recognition is difficult. Although I have done a little research on the subject, I don't have any experience implementing. Are you using that type of image? Or is that just an example? I'm curious to know if you will be using real world images, or simple black and white (no greyscale) images. It would be much easier with a black and white image, as simple edge detection becomes incredibly difficult when colours or shades of grey are introduced (compressed image formats could introduce other shades).

Ok, so I don't know any algorithms off the top of my head, but this might work for you (again, not experienced in this field, so take it with heaping grains of salt):

  1. Create a cone with radius x.
  2. Count the number of pixels contained within the cone.
  3. Rotate x/2 degress around the origin.
  4. Repeat until the entire circle has been covered.
  5. Select the cone(s) with the largest number of pixels (take care not to select two adjacent cones).
  6. This will give us a range of degrees (or radians), now decrease x by more than a factor of two, and repeat (within the selected cone(s)) until you get an accurate enough answer.
  7. Do the math.

Note that this wouldn't work well if the lines get close enough together, but selections could be broken up after the first pass. Hopefully that's of some use to you. Good luck.

nmaillet 97 Posting Whiz in Training

If sock is null, it would throw an InvalidOperationException. If there's no curly braces, it only executes the following statement.

nmaillet 97 Posting Whiz in Training

Not sure what you're asking; could you elaborate?

nmaillet 97 Posting Whiz in Training

i wish he gonna help you

I don't think he was asking a question...

This is a Simple one Line code for inserting current System date in to a text box:

What is the point of this? Not that I don't understand the code, or its purpose, but why post it? It's pretty trivial.

nmaillet 97 Posting Whiz in Training

You need to explain this better. Are you trying to calculate the coordinates where a line intersects a circle? And what inputs are you given (slope, y-intersect, etc.), or are trying to extract a line from a raw image?

nmaillet 97 Posting Whiz in Training

Could you just use a line like: runningcount[city]++;? Quick test:

Dictionary<object, int> runningcount = new Dictionary<object, int>();
object city = new object();
runningcount.Add(city, 3);
Console.WriteLine(runningcount[city]);
runningcount[city]++;
Console.WriteLine(runningcount[city]);
Console.ReadKey(true);

This program outputs:

3
4

The indexer property can also be set, which allows you to change the value. Unless there is something I am not understanding about your question?

nmaillet 97 Posting Whiz in Training

Do a google search for java io and java encryption. Should be pretty straight forward. Once you have done some research and tried coding, feel free to ask some specific questions if you get stuck. Good luck.

nmaillet 97 Posting Whiz in Training

++t is an increment operator, it is essentially equivalent to t+=1. Although it does not matter in this situation, note that there is a difference between ++t and t++ (just Google it if you're not sure about it).

As for the string[t], strings (in C) are an array of characters ending in 0 (not the character 0, which has a ASCII value of 32 I think, but the actual value 0, sometimes known as the null character) to indicate the end of the string. This is done since C strings do not implicitly have a length value like C# or Java. Now in C, Boolean values are simply integers where 0 indicates false, and any other value indicates true (generally speaking, I don't think this is actually stated in the standard). So the for loop iterates through each character until it reaches a character which evaluates to false. In this case it is the null character (ie. the end of the string).

nmaillet 97 Posting Whiz in Training

What do you mean exactly? You can use the == operator for most reference types (except when a class overloads the operator). To be sure you can use Object.ReferenceEquals() to compare two reference types.

nmaillet 97 Posting Whiz in Training

Do you mean you want to call multiple methods with a signle method call? That is not the intention of method overloading. It is mainly a convenience. It would be equivalent to something like this:

        static int AreaII(int n1, int n2)
        {
            Console.WriteLine("Inside Area(int n1, int n2)");
            int area;
            area = (n1 * n2) / 2;
            return area;
        }
        static double AreaDI(double n1, int n2)
        {
            Console.WriteLine("Inside Area(double n1, int n2)");
            double area;
            area = (n1 * n2) / 2;
            return area;
        }
        static double AreaID(int n1, double n2)
        {
            Console.WriteLine("Inside Area(int n1, double n2)");
            double area;
            area = (n1 * n2) / 2;
            return area;
        }
        static double AreaDD(double n1, double n2)
        {
            Console.WriteLine("Inside Area(double n1, double n2)");
            double area;
            area = (n1 * n2) / 2;
            return area;
        }

Here you would explicitly call the method you want. With method overloading, the compiler does that for you; it implicitly calls one of the methods.

Hope this clears things up a bit.

nmaillet 97 Posting Whiz in Training

Well, the line:

Form2 form2 = new Form2();

is not calling the constructor you define above. It is calling the default constructor. You would have to change it to something like this:

Form2 form2 = new Form2(class1);

Also, in the Form2 constructor, you are assigning label1.Text to class1.Name, I think you want the opposite. I.e.:

label1.Text = class1.Name;
nmaillet 97 Posting Whiz in Training

The main purpose for method overloading is doing essentially the same thing with different types. Each method must have a unique "signature". The signature is made up of the number, order and type of the parameters (the return value doesn't matter).

In your sample program, you could call another one of the methods by casting one or both of the variables to an int:

area = Area((int)h, b);

The compiler will try to match the given parameters (based on their types) with the best method (closest signature to your input). It generally has to match exactly, but will perform implicit casts if necessary. In your program, the compiler sees that both input parameters are doubles, so it calls Area(double,double). If you took out that method, it would not call any of the other ones, since you cannot implicitly cast an int to a double.

nakor77 commented: simple and clear explanation +4
nmaillet 97 Posting Whiz in Training

I will start by saying that I'm not an experienced game developper, I've learned little bits and pieces when I find the time. In either case, you could take a look at these (you'll never get a definitive answer on which is best, its all subjective):

  • Unity: I have heard some good thing about Unity, although I haven't had the chance to try it out extensively yet. It does support C# scripting, but not VB.NET). It's free, except when you won't to go with the Pro version which is around $1500 I think.
  • UDK: The UDK is powered by the Unreal Engine 3. It lacks some features of the full UE3, like native code (you can use UnrealScript). It's free at first, but when you go to sell your game, you pay a license fee (around $100) plus a percentage of sales after $50,000.
  • CryENGINE 3: It is comparable, in terms of cost, to the UDK with some slight differences. I have heard some complaints about it, but could be worth a try.

I think the best advice I could give, is try out some different engines, see what other people have done, and pick the one you like the best. Unless you're planning on making a very high-end game, then it shouldn't matter too much which one you pick.

nmaillet 97 Posting Whiz in Training

What software are you using to convert text to speech (because if you made it all by yourself you should be able to answer that question)? Also, I don't think this is the right place to ask about speakers...

nmaillet 97 Posting Whiz in Training

When you look at the exported CSV file in Notepad it's fine? So what program are you using to open the file, that gives the "replaced" characters? Are you using a C# program to parse it, or something like Excel?

nmaillet 97 Posting Whiz in Training

Couple of questions:

  • Are you using a fixed bit count? For instance, what would you do with the number 6? If we say it's 110, the reverse is 011 = 3. If we said it's the 4-bit number: 0110. Then the reverse is 0110 = 6, which is quite different.
  • I assume you have, but have you considered signed values? Or are you assuming everything is unsigned?
nmaillet 97 Posting Whiz in Training

The return value doesn't have to be stored. It is up to the programmer to determine what to do with a return value, or whether to not use it all together. In this case, the programmer decided to use an delegate to print the result and didn't need it for anything else in the Main method.

Hope that helps.

maurices5000 commented: Thanks! +0
nmaillet 97 Posting Whiz in Training

You would add something like either of the following statements:

mybtn.Click += new EventHandler(mybtn_Click);
//--or--
mybtn.Click += mybtn_Click;
nmaillet 97 Posting Whiz in Training

First, I'm a Windows developer, not a mobile developer. So your mileage may vary.

Use the Storyboard.Target attached property instead. Is the image you are referencing going to change? Or the index you are referencing within the list? You can reference lists in XAML (they must be exposed as a property, not a field) in the bindings path with something like this:

<DoubleAnimationUsingKeyFrames Storyboard.Target="{Binding MyListProperty[0], ElementName=myWindow}" ...>

If the image is going to change, you'll have to use an ObservableCollection<> or something that correctly implements the INotifyCollectionChanged interface. If the index you will be referencing will be changing, I would instead recommend updating a custom DependencyProperty when necessary.

nmaillet 97 Posting Whiz in Training

Well I can't vouch for HAP, I do agree with __avd. In any case, by default the dot operator (.) matches any character except the line feed character (\n). You can change the default behaviour by doing something like this:

Regex regex = new Regex(@"<p>\s(.)\s</p>", RegexOptions.SingleLine);
Match m = regex.Match(htmlstring);

Just note, that there are a lot of things that can go wrong when doing this. The other option is to use * after the subexpression to capture each as a group. If you want to capture multiple paragraphs, wrap the whole thing in round braces () and add the * to capture multiple groups.

F**ks sake, I am really starting to hate this new text editor. Writing this one short post was painful.

nmaillet 97 Posting Whiz in Training

This is dependent on many things, such as: What is the structure of your CSV file? What is the structure of your database? Is it all going into one table, or broken up amongst many table? Are there primary/foreign key constraints that you need to worry about?

Maybe you should start by posting the code you have tried, a small example of the input, explain how it's supposed to go in the database and explaining what went wrong.

nmaillet 97 Posting Whiz in Training

Put it in a loop, read each line and split each line up with the string.Split() method or the Regex class. Post some code and ask some specific questions, otherwise you probably won't get much help here.

nmaillet 97 Posting Whiz in Training

Try taking out the AttachDbFilename part, so it would go from:

con.ConnectionString ="DataSource=.\SQLEXPRESS; AttachDbFilename =C:\MyWorkers.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";

to something like this:

con.ConnectionString ="DataSource=.\SQLEXPRESS; Integrated Security=True;Connect Timeout=30;User Instance=True";

The database file is already attached to the instance of SQLEXPRESS. This may be causing some undesireable results.

I'm not going to download and look through all of your code. If you post some code (ie. where you created the SqlConnection class, and how you're using it) I'll take a look, but atleast try my above suggestion first.

nmaillet 97 Posting Whiz in Training

Oh, quick follow-up question... Are you going to be playing a song from your app? Another app? Or just any sound from the computer?

nmaillet 97 Posting Whiz in Training

It's getting late, so I don't have time to look too extensively tonight (I'll try and remember to look into it a bit tomorrow), but you may want to start in the Audio/Video section of the Windows API, found here. In particular, look at the Core Audio APIs. I don't do much with audio, in terms of programming, so I'm not the best on the subject matter, but I believe output audio can be directed to whatever device, then each device has a number of audio channels (they may share channels for all I know though). In either case, I think you'll have to monitor several channels and devices, which is why I believe you'll have to start with the Core Audio APIs. I don't believe the .NET Framework directly supports what you want to do, so you'll probably have to use some native libraries via COM interop.

Good luck.

nmaillet 97 Posting Whiz in Training

Oh ok, I got you. Generally when you are using a database, settings or custom file during development, you are not concerned with the changes that occur during runtime. Switch it back to "Copy always". Reason being, if you make changes to the source file (the one directly in your project folder) the copy your application is using will get overriden. So, you'll want your application to work off of the original copy instead. You could do this using preprocessor directives, like this:

#ifdef DEBUG
    string filename = "c:\\...\\mydb.sdf";
#else
    string filename = "mydb.sdf";
#endif

What this does, is uses the db file from a different location, only during the Debug run. So you can statically set the absolute path, or the relative path to use (I believe it's DEBUG all in caps, but it could be Debug).

As for MDI, I want to be sure you understand what MDI is. When you are using MDI, the MDI parent displays nothing (expect a MenuBar) usually. It then contains several child windows. The child windows, cannot move outside the bounds of the parent window (well it can, but it gets clipped). This is how Office 2003 worked, in the sense that you could have multiple windows opened within a parent windows (although a button in the taskbar did appear for each opened document). If you were not using MDI, it would be like opening a settings window, or an open file dialog.

In either case, you just need to …

nmaillet 97 Posting Whiz in Training

This allows each button to be associated with one event handler, which is how this should be handled. This is why I asked the question, but let me rephrase it: what is going to be different about each different button press?

If only one button is creating the new dialog, then maybe you put the first piece of code in the wrong location... or something else is going on. Each event handler (essentially the new method we created) can be associated with several events (the Click event of each button).

nmaillet 97 Posting Whiz in Training

Add this to skatamatic's sample code:

btn.Click += btn_Click;

Then you'll need to create a new method to handle the Click event:

private void btn_Click(object sender, EventArgs args)
{
    MyDialogForm form = new MyDialogForm();
    form.ShowDialog(this);
}

Now, there's a couple ways you can handle associating the dialog box with a class. So, is the dialog box going to be different depending on the button selected, or the same basic layout/options?