deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if (POSDGV.Rows[j].Cells[2].Value == null)

It really depends on how you're storing null values. Likely the check will fail because the cell value is actually DBNull.Value or simply an empty string:

if (POSDGV.Rows[j].Cells[2].Value == DBNull.Value || string.IsNullOrEmpty(POSDGV.Rows[j].Cells[2].Value.ToString()))
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do you think I have an obsession or a passion with tech and software?

Passion, yes. Borderline obsession too. Not that there's anything wrong with it as long as it doesn't take over your life; I have a similar passion when it comes to software development.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Another potential issue with hardware changes is you may need to reactivate Windows. Typically this only happens with significant changes like a motherboard replacement, but it's not unheard of for minor hardware changes or even non-hardware changes to trigger a reactivation notice.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What have you done so far?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do your own homework.

Thank you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

malloc() is a pre-defined function which is available in <alloc.h>.

stdlib.h. alloc.h is ancient and non-standardized. Unless you copied that information from a hideously outdated source, I'd recommend updating your knowledge of C. A lot of things have changed since Turbo C, including best practice.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Actually the printf() statement will work according to the stack mechanism i.e., the evaluation (execution) will starts from right side to left side...

Yet the compiler is free to actually evaluate the arguments in any order at all. Just because the values might be pushed from right to left doesn't mean the expressions used to produce a value will be evaluated in the same order.

Modifying a variable multiple times between sequence points is undefined behavior. All predictability is gone, even between runs of the program from the same compiler.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

please put a simple program which can be understood by first year people please.......

My sample program meets that requirement.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There are a number of reasons why a service won't start or remain started. Usually it's the result of an unhandled exception. Can you provide more detail as to what you're doing and what the result is?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I answered to his request, or should I say, solved his problem, right there...

I'd wager that's precicely why you got downvoted. Solving homework problems for people without any effort on their part is generally considered to be unhelpful because there's no practical learning involved.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Nice tutorial. I'll also add that there are usually two situations where forms communicate that affect your choice of how to do it:

  1. The forms are not modal and the lifetime of the child form is either long or independent of the code that creates it. In this case the event approach is suitable.

  2. The child form represents a modal dialog. In this case two way events are overengineered; a better approach uses public properties and is vastly simpler:

    using (var dlg = new ChildForm())
    {
        if (dlg.ShowDialog() == DialogResult.OK)
        {
            // Whatever other stuff you want to do...
    
            textBox1.Text = dlg.Name;
            textBox2.Text = dlg.EventType;
        }
    }
    

Your tutorial covers the first case quite well, but doesn't cover the second. I just wanted to point that out for readers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Works for me, once I fix the error of trying to define an array with a non-const size (my compiler doesn't support C99+).

Since I can't reproduce the stated problem, you'll need to follow debugging practices such as tracing through the code in a debugger and watching the size that's calculated. Presumably the issue is in StrLen, and that's where I'd start after confirming exactly where 6 originates in your main function.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A static data member belongs to the class rather than to an individual instance of the class. Likewise with a static member function. A reasonable way to think about them at a high level is to treat the class as acting like a namespace for those members:

class Foo
{
public:
    static int bar;
    static void baz();
};

...

int main()
{
    cout << Foo::bar << '\n';
    Foo::baz();
}

Comparable in many cases, but not identical is the namespace concept:

namespace Foo
{
    int bar;
    void baz();
}

int main()
{
    cout << Foo::bar << '\n';
    Foo::baz();
}

In both cases you can use the name of the class or namespace as a qualifier to access the member. With classes you can also access static members through an object:

int main()
{
    Foo obj;

    cout << obj.bar << '\n';
    obj.baz();
}

Under the hood, the Foo class can be imagined something like this:

int static_cls_Foo_public_bar;
void static_cls_Foo_public_baz();

class Foo {};

bar and baz are actually closer to global objects that are internally checked for correct visibility and access by the compiler. The objects themselves are not baked into an instance, but still tied closely to the class.

When would you use a static member? Well, whenever you need an object or function that applies to all instances or to the class as a whole. One good example is reference counting. If you're counting the number of instances, then each instance having an …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You've encountered a common beginner issue. Allow me to point it out more clearly:

// This is a pointer to a string literal. You can't modify it.
char *text = "GOOOD TEXT ALL TIME VERY POOR ";

// This is an uninitialized pointer, you can't read from or write to
// it until it points to a valid block of memory that you own.
char *copy_text;

// This is undefined behavior because you're trying to write
// to an uninitialized pointer. If you're lucky, the program
// will crash fantastically so that the error is obvious, but
// there's no guarantee of that.
StrCpy( copy_text, text );

Now let's fix it:

char *text = "GOOOD TEXT ALL TIME VERY POOR ";
char copy_text[50];
StrCpy( copy_text, text );

In the above correction, copy_text is an array. This means you own the memory, and it's large enough to hold all of the characters in text.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The laziness here is impressive. Most drive-by cross posters will at least have the courtesy to copy their other posts verbatim rather than linking to them. Did you read the answer to the question on that other forum? It provides a valuable hint for research.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My recommendation would be to use the string class:

string names[] = {"monitor", "cpu", "mouse", "joystick", "system"};

The problem with your code is that the "strings" aren't string literals, so they're treated as identifiers that don't exist. Further, the type of your array is char, which means each element of the array can hold one character and no more.

To hold multiple characters, the type of the array needs to be a char* that points to a string literal or dynamic memory, an array of char (ie. a 2D array), or an array of std::string as in my example above. The latter provides the most flexibility by far, and that's why it's recommended.

dennis.ritchie commented: thank you it worked perfectly +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You'll receive better help if you explain how the code isn't working.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm not aware of any standard controls that will do this for you. You'd essentially need to combine a textbox and some form of list control, where a button or the Enter key on the textbox fires a back-end search. It should go without saying that you'd be writing the search logic.

You can wrap the whole thing up in a user control, but the initial build is more than just dropping a control and setting a few properties.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
public static class Globals
{
    public static readonly string Foo = "DAFOO";
}

...

Console.WriteLine(Globals.Foo);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

On a side note, it's harder to read posts and titles in all caps.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What exactly are you trying to accomplish? "Lookup search control" is too vague.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

An array is a collection of items. To access individual items you need to specify which index in the collection you want (ranging from 0 to N-1):

for (int i = 0; i < months30.Length; i++)
{
    if (months30[i] == month) // Now you can test against the entered month
    {
        Console.WriteLine("{0} has 30 days", month);
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's interesting because a single post can seem to gather both, causing you to wonder if you deserved either.

Indeed, it's a moving scale.

Did you pick your name because of the transformer culture I never bothered to learn until I watched the movies?

Not really, it was fairly random but no doubt I was thinking of the decepticons at the time. I added a misspelling to differentiate myself a bit.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The first error that I immediately noticed is you're not initializing your variables to 0. This means that they'll have some random value, and incrementing that value (on top of being undefined behavior) will accomplish nothing meaningful.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Help whom? The original poster is 3 years gone.

The original poster isn't the only person a thread might help, that's why we don't close threads after they reach a certain age.

It could be helpful for u if u had brain.

Malicious personal attacks will not be tolerated, please keep our rules in mind.

cuz you dont own this community........

Nor do you. It's generally frowned upon when a new member tries to play net nannie. I'd suggest that if you feel any rules are broken, simply report the offending post and let those of us who were selected by the owner of this community to enforce those rules handle it. Taking matters into your own hands is a good way to find yourself in the wrong and subject to moderator action.

kplcjl commented: Thanks, for how you handled both of us because we were both wrong in how we reacted. I later felt an idiot for reacting to a post. +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Notification of what, exactly? Does the presence of records in the database trigger a notification or something else?

All of the pieces are straightforward, so break it down a bit:

  1. Connect to SQL and get data then print it out.
  2. Send a test email.
  3. Combine those by sending a "real" email with the data you got from SQL.
  4. Write a simple service that does nothing.
  5. Add a log to the service that writes a line when it polls.
  6. Combine everything by adding the "real" email notification when the service polls.

This kind of application can be written in less than an hour, especially if you use existing templates like this one.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I just found it as an interesting a little confusing BUT NORMAL behaviour.

Yes, it's normal. I can also see it being confusing because there are three issues involved:

  1. The console shell will likely be in a state that echoes any input.
  2. Standard input functions use whatever the shell state is. There's no standard way to take raw input or input with no echo to the exclusion of the shell state.
  3. Due to the way the shell works, input is line oriented and requires a newline to sent data from the shell to the running program.

The result is that if you print a newline, then take input that requires a newline to send to the program, that newline will be echoed and you'll have two adjacent newlines (ie. a blank line in the output).

Such is the way when your input source and output destination are one in the same.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The closest you can get would be a static class in C# with those variables as members. Place that class in a shared assembly (if your project uses more than one assembly) and you're good to go.

GagaCode commented: thaks +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your code performs precisely zero length, existence, or success checks, so it's absolutely vulnerable to malicious use. It's also brittle in the face of legitimate use. Let's add a few checks to make it better:

#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[]) {
    char *first, *second;

    first = malloc(888);
    second = malloc(22);

    if (first != NULL && argc > 1) {
        first[0] = '\0';
        strncat(first, argv[1], 887);
    }

    if (second != NULL && argv > 2) {
        second[0] = '\0';
        strncat(second, argv[2], 21);
    }

    free(first);
    free(second);

    return(0);
}

Of course, in practice the arguments may be required and/or related to each other, in which case the tests would be different. Right now they're entirely independent.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Things look pretty grim this season.

All I need is one good one to be happy. ;)

All my favorite anime series are coming to an end (Strike the Blood, Golden Time, Magi S2, Log Horizon, Silver Spoon S2, Tokyo Ravens. Oh my...)

Fall season will find us with more Log Horizon though. I'm not sure how it will work out because this last season ended close to where the novel has left off. With any luck there won't be much filler or the filler will be decent.

Baby Steps -- Recommended by our resident anime expert decepti-kun so would be definitely giving it a shot :P

I'm hoping and praying that it's well animated and true to the manga. Baby Steps is one of my favorite manga, and there's plenty for several seasons of anime.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The answer they're probably looking for is null, but the question is ambiguous because it greatly depends on what type is being used, where it's defined, and whether the compiler will even let you compile without assigning a default value explicitly. For example, int isn't a nullable type by default, so how could the "undefined" value be null?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I can't set it in the designer too, because that code can/will be regenerated.

If the class is obsolete, why would you be changing it such that the generated code is updated? Last I checked, generated code was only updated when you changed the form from the designer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It seems like there's some confusion with the overloading of the & operator. In the context of a type, it means "reference to", not "address of".

More details

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Only open the form if the login is correct:

if (username == textBox1.Text && password == passwordtextbox.Text)
{
    MessageBox.Show("You are now successfully logged in.");
    Form2 frm = new Form2();
    frm.Show();
    frm.mypass = password;
    frm.myid = username; 
}
else
{
    MessageBox.Show("Username or Password seems invalid, please use email to recover password/username");
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why would you want its address? That's meaningless to the caller of the method. Anyway, you can get the address on the caller's side using the updated code from my previous post:

cout << "Reference of last element in stack: " << &P.top() << endl;
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That makes much more sense, a realistic example is far more helpful than a broken example. You simply need to remove the address-of operator and returning a reference will work in this case because the array has the same lifetime as the stack object:

int& Stack::top()
{
    return container[size-1];
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I know it can be solved if function is defined as "int* example()"

The error will go away, but the underlying problem will remain. You're referring to an object that no longer exists. This is the dangling pointer or dangling reference problem.

If int a is global constant, how to do it then?

The real question is what do you want that function to accomplish? Because right now it's completely nonsensical.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

&a evaluates to a pointer to int rather than int, therefore a reference to int is an incompatible type. Further, returning a reference to a non-static local variable is an extremely bad idea because the local variable is destroyed after the function returns; the reference will refer to a non-existent object.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Done.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

From the end of the string walk backward until you find a non-blank character, then overwrite the last blank you saw with '\0'. Easy peasy, and here's a working example of an rtrim function to get you rolling.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

input output stream. Concerning the header, iostream is where your cin and cout objects are declared. In general, the iostreams library is C++'s character streaming I/O support mechanism.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i want the code for this program using arrays

Then write it. Also, please read our rules concerning homework questions without proof of effort. We won't do these problems for you, but we'll help if you get stuck doing it yourself.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Of course, since you still have the assignment and saying it's stupid won't accomplish much, a reasonable approach would be to compress your range with a loop and table lookup:

int lookup[] = {21, 41, 61, 81};
int discount = 0;

for (int i = 0; i < sizeof lookup / sizeof *lookup; i++)
{
    if (qty < lookup[i])
    {
        break;
    }

    discount += 5;
}

switch (discount)
{
case 0:
    // Blah
    break;
case 5:
    // Blah
    break;
case 10:
    // Blah
    break;
case 15:
    // Blah
    break;
case 20:
    // Blah
    break;
}

But if you're already finding the discount with the lookup, I'd question whether a switch is even needed. It might be able to be rolled up into little more than a final price calculation and output statement.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Two years ago I'd say no way in hell. These days I'd say that appropriately designed tablets can kill the netbook market, though not the laptop market due to simple scalability limits. My current tablet (ASUS T-100TA) is a perfectly suitable netbook as well as a nice tablet.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You get to do the math! :-)

For massive bonus points, incorporate chronological adjustments in your math (eg. leap years, leap seconds). Date and time calculations are shockingly complex when you look for higher correctness across the board. Most libraries even put a lower bound on supported dates to avoid changes in the standard calendar.

Even given its relatively limited scope I found that time.h was the second or third most time consuming part of the standard library to implement correctly.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I know that malloc will allocate 1 block of given size and calloc will allocate n block of given size.

They allocate exactly the same single block of memory. The only difference is how that block is calculated. With malloc it's calculated by the caller and with calloc it's calculated internally. In fact, you can implement calloc in terms of malloc:

void *calloc(size_t n, size_t size)
{
    size_t blk_size = n * size;
    void *mem = malloc(blk_size);

    if (mem != NULL)
    {
        memset(mem, 0, blk_size);
    }

    return mem;
}

Does calloc initilizes all BLOCKS or all BYTES to 0 ?

There's only one block, and all bytes are initialized to 0. That's why calloc should be used judiciously with non-trivial or non-integral types due to the potential of borking up memory you're not supposed to access or that doesn't represent all bytes zero as a zero value for the type.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It largely depends on your compiler and switches. C++11 (the latest standard) added this feature, and some compilers prior to that offered it as an extension.

Your book is old, by the way, and also written by an author who's routinely mocked for making grievous beginner mistakes. You might consider getting a different one.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Usually you specify what exception type(s) it may throw.

Noting of course that exception specifications have been deprecated because they're stupid. Support for exceptions themselves is still standardized and unlikely to change significantly in the forseeable future.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What kind of "help" are you looking for? Daniweb requires proof of effort for homework questions, and I don't see any such proof. Please give it an honest try, and feel free to ask for help (that doesn't constitute doing your work for you) if you get stuck.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I hope that once in a while you visit non-English pages, don't you ?

Only with translation unless it's a language I can reasonably read. ;)