deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are we slowly turning ourselves in robots?

You've asked this question with the implied assumption that the result is bad, which hasn't been convincingly argued. What's inherently wrong with being partially "robotic"? Until we have a basepoint for discussing the ramifications intelligently, we need to move away from irrational fears.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My bad, it should have been if (parts.Length != 2). If code you find online is broken, don't be afraid to troubleshoot it yourself. We're all fallible, after all. ;)

i don't know where can I put this code on my form. sorry im newbie on this.

You'd pull the ID directly from the database, then call AutoIncrement to get a new ID for new records is what I was thinking. Or maintain the most recent ID in your code and update it as necessary for new records For example:

private string _connectionString = "<your connection string>";
private string _lastId = "AN-00000000"; // Default first ID if there are no records

/// <summary>
/// Retrieves the most recent ID from the database.
/// </summary>
private void Form1_Load(object sender, EventArgs e)
{
    using (var connection = new SqlConnection(_connectionString))
    {
        connection.Open();

        using (var cmd = new SqlCommand(connection))
        {
            cmd.SelectCommand = 
                "select top 1 piId" + 
                "from tblpair_individual_membership" +
                "order by piId desc";

            var id = cmd.ExecuteScalar();

            if (id != null)
            {
                _lastId = Convert.ToString(id);
            }
        }
    }
}

/// <summary>
/// Adds a new client to the database
/// <summary>
private void buttonNewClient_Click(object sender, EventArgs e)
{
    var newId = AutoIncrement(_lastId);

    using (var connection = new SqlConnection(_connectionString))
    {
        connection.Open();

        using (var cmd = new SqlCommand(connection))
        {
            cmd.InsertCommand = "insert into tblpair_individual_membership (piId) values (@piId)";
            cmd.Parameters.Add("@piId", SqlDbType.VarChar).Value = newId;

            if (cmd.ExecuteNonQuery() == 1)
            {
                // Only update the last ID on a successful insert
                _lastId = newId;
            }
        }
    } …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And that represents a valid path, how?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yup. You need to split the string to extract the number part, convert it to int, add to it, then paste the string back together:

private static string AutoIncrement(string id)
{
    var parts = id.Split('-');

    if (parts != 2)
    {
        // Expected format "XX-dddddddd"
        throw new ArgumentException("Invalid id format");
    }

    int seq;

    if (!int.TryParse(parts[1], out seq))
    {
        throw new ArgumentException("Sequence number must be numeric");
    }

    // Validate the first part if you want

    // Put it all back together into a new ID
    parts[1] = (seq + 1).ToString("00000000");

    return string.Join("-", parts);
}

The conversion to int is the important part because the + operator for string performs concatenation rather than integer addition.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Did you change the to this?

string picLoc = null;
string picLoc1 = null;
string picloc2 = null;
string picloc3 = null;

Because that's not any better. If you're opening files, those strings need to have the path to the file. The framework has no idea what file you're trying to open if you don't. For example:

string picLoc = Path.Combine(rootFolder, "myimage.tif");
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well, unless you're changing those values, it's pretty obvious why you're getting an empty path exception. Blank strings are not valid paths.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How are you generating picloc, picloc1, picloc2, and picloc3?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Now, I have a question to create a auto number like this "AN-0000-0000", it is possible to query this on C#?.

That looks fairly custom. What does each part represent and how does it change as new values are generated?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please post your code. The exception is clear about what the issue is, so you need to look into why the path you're trying to save is interpreted as being empty. Most likely it's getting cleared somewhere.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is a hard 5 digit sequence required? If all you need is something that's larger than the previous ID and smaller than the next, you can use the custom date time formatting to get a high enough resolution that practically guarantees uniqueness:

' Timestamp down to the millisecond
Id = DateTime.Now.ToString("yyMMddHHmmssFFF")
Begginnerdev commented: Can be shorthanded by calling Now() +9
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm going to go out on a limb and guess that what you want is to clear the screen when redrawing the menu. This will keep the menu in the same physical location for each iteration of the loop.

Since you're calling it "DOS" I can only assume you're using Windows, and as much as I abhore system as a security hole, the easiest way to clear the screen is:

int menu()
{
    int choose;

    system("CLS");

    do {
    ...

Don't forget to include <stdlib.h>, that's where system is declared.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And? What have you tried? Please note that our rules disallow posting homework questions with no proof of effort as if you wanted us do write it for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

OpenConCls.ToString() will give you a default object representation because you didn't override ToString. This won't be a string that represents a valid integer, so Convert.ToInt32 fails.

By auto number I assume you mean the result of the query, which would be done like this, if I recall correctly:

 string pcount = OpenConCls.reader[0].ToString();
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can I get an example regarding how to declare it and then initialize it to NULL

Sure, once you answer my question. I can't tell you how to use some random class that I'm not familiar with, but given either the class itself or sufficient documentation I'll be happy to help out.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

counted_ptr isn't a standard class, which means you're trying to use a third party class. Where did you get it? How you use it greatly depends on how it was written to be used.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I wish you the best of luck, but strongly suspect that it won't end well one way or another.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

On the surface it seems enticing, but the concept of immortality (or extreme longevity in this case) is usually more about fear of death than anything. If you really think about it, living so long would be more of a curse than a blessing. I suspect most people who took such a pill would end up suiciding long before reaching the age limit.

Reverend Jim commented: I couldn't agree more. +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It sounds almost like you're working with a client-server setup. The client takes ticket requests and sends them to the server, then the server responds by creating a ticket and returning the result?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I do know PHP, but the content and structure of the shared data is largely irrelevant in this case. What you want to look at are IPC (interprocess communication) techniques. It could be as simple as dropping a serialized file from one process that the other reads or as much as direct communication between two processes using sockets or pipes.

Which option is best very much depends on what these programs do, where they run, and how the data will be used.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

All modern compilers will require the int return type unless (in some cases) you tell the compiler you are building legacy (old) code. The old K&R compilers would allow void return type for main(), but no longer (by default).

You're thinking about implicit int, I suspect. This is no longer supported as of C99:

main()
{
    return 0;
}

The int return type is still there, it's just implied. One problem with this feature is that people would assume that no return type meant no return statement was required, which isn't the case.

Support of void as a return type from main is completely a compiler extension and always has been. Even K&R C specified main as returning int.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I have mix up pointers and by reference.

"By reference" in C is "by pointer". That's how you simulate pass by reference because there's not an actual reference type available. Pointers are close enough though, and colliquially we simply say that you're passing by reference instead of passing by simulated reference using a pointer. ;)

Can you help me to understand why void main() wouldn't work?

The only two signatures of main that the C standard specifies as universally correct are:

int main(void)
int main(int argc, char *argv[]);

Equivalent parts like char **argv and different names for the parameters are acceptable as well.

Returning void from main is only supported by a subset of compilers, and if the compiler you're using doesn't support it, using void main invokes undefined behavior. Undefined behavior is among the worst possible results for a program because it removes all predictability.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The actual error is that you're adding an unnecessary level of indirection in the tokenise call. tokens is already an array of pointers, there's no need for the address-of operator.

However, that said you still have issues in the program. Most notable is the next line tries to print tokens as a single string when it's really an array of strings. You need to loop over the array and print each string individually. Further, tokenise should return the number of tokens so that you know when to stop the loop.

Compare and contrast, I fixed other minor issues like including string.h and not using void main:

#include <stdio.h>
#include <string.h>

#define MAX_NUM_TOKENS  100

int tokenise(char inputLine[], char * tokens[]);

int main(void)
{
    char inputLine[] = "Testing program Testing program";
    char *tokens[MAX_NUM_TOKENS];
    int n = tokenise(inputLine, tokens);
    int i;

    for (i = 0; i < n; i++) {
        printf("token: %s\n", tokens[i]);
    }

    return 0;
}

int tokenise(char inputLine[], char * tokens[])
{
    int i = 0;
    char *pch;

    pch = strtok(inputLine, " ");

    while (pch != NULL)
    {
        tokens[i] = pch;
        i++;
        pch = strtok(NULL, " ");
    }

    return i;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You have a number of options, but it depends what these programs are and do. Can you elaborate a little bit?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so is it correct to say that IN can not be necessarily used as a replacement from Exists, or reverse ?

in can be used as a replacement for exists in terms of functionality (may ways to do the same thing, of course). But if the result set of the subquery is large, exists will be quite a bit faster since it's essentially taking a count that stops when a single match is found. in will typically be faster when the result set is small.

returns all records form Customers table. Why ?

Because the subquery isn't keyed on the specific customer. You can think of these simple queries as an imperative foreach (not a perfect equivalence, but helps to visualize):

a = empty recordset

foreach customer in customers
    b = empty resultset

    foreach product in products
        if product["prodCategory"] = 'Consumer electronics'
            b = b + product

    if b <> empty
        a = a + customer

Notice that the inner loop doesn't look at the current customer record at all to determine its result set, so unless the table is empty, b will always contain at least one record, and the exists test will always evaluate to true. Therefore you'll always select every customer in the customers table.

Now consider the same equivalence using the customer ID:

a = empty recordset

foreach customer in customers
    b = empty resultset

    foreach product in products
        if product["prodCategory"] = 'Consumer electronics' AND product["cus_id"] = customer["cus_id"]
            b …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

let's put it in simple words, the subquery in this code will return on a boolean value TRUE, ok ?

It will select a matching record. exists evaluates to a boolean based on the presence of any matches. But the rest of your explanation is reasonable, though not strictly correct (which is okay since you're putting it into simple words). I think the issue here may be less about exists in particular and more about relational logic in general.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

exists looks for the first match in the subquery. If it returns true for any of the matches in the outer query, the where clause succeeds and that record will be selected.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How about a different example? Let's say you have customers that have the option to enrole in a feedback survey. You want to get all of those customers to send survey emails. You could use exists to retrieve that list and exclude customers that didn't enrole.

select c.ID, c.Name, c.Email
from Customers c
where exists (select * 
              from SurveyEnrolement se
              where se.CustomerID = c.ID);

Not that this is either the only way or the best way, I just think it may be a more clear example of exists.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's not a form, sorry. Your only option is to print it, fill it out, then scan it back in.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is the PDF form enabled? If they're just lines then you can't do anything, but if they're actual data fields in a form, you should be able to click into and type into them. Whether they're fields or not depends on how the designer of the PDF built it, you don't have any control.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You don't. That's why it's called Adobe Reader. To edit PDF files you need something like Acrobat or LiveCycle, but note that those options aren't free like Reader.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

give me a link for read more about that magic numbers?

Magic numbers are just that, magic. They're selected completely at the discretion of the programmer, so there's really nothing to document in general about magic numbers beyond. A good library should hide any use of magic numbers from you anyway.

What I've been saying is that you need a very specific case to study, but this case is not a good one because merely using the magic numbers is a bad practice.

Instead, I think you'd be better off studying bit twiddling in general, rather than continuing with this specific usage. Try googling for "bit manipulation exercises".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i need to understand them because seems to be used in very situations.

In this case you don't. Someone gave you bad advice.

please give more information about these type of calculations.

First you need to figure out what those magic numbers represent. It's harder because they're intended to be opaque and not worked with directly here. Once you find out what each of the constants you want to work with represent, it's simple enough to figure out what the bit operations do for you using the corresponding truth tables.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but why these number and not other?

Magic numbers for bit twiddling are typically chosen to be unique bit patterns. For example, in the case of flags that are intended to be OR'd together you'd typically want to choose numbers where a single bit is set:

0x01 = 0000 0001
0x02 = 0000 0010
0x04 = 0000 0100
0x08 = 0000 1000
0x10 = 0001 0000
0x20 = 0010 0000

That way when they're OR'd together, you get a bit pattern that can easily be tested with AND.

The problem with your question is that you shouldn't be using magic numbers at all. Rather, you should be OR'ing together the manifest constants for those flags, even if it's more verbose. The constants are there because the magic numbers could change, and then code that uses the magic numbers would break.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And also, as Agilemind pointed out (which you said you misunderstood for some weird reason)

I understand Agilemind perfectly. My difficulty was in phrasing my response. Did I make that unclear?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So prostate emaninations and treatment for various disorders of same (enlargement, cancer, etc) apply equally to both sexes?

Right now you've got cervical cancer screenings at no cost, for example, but prostate cancer is statistically more pervasive and fatal by orders of magnitude yet screenings aren't covered at all last I checked. Where's the logic there?

I have no problem with things like covered screenings, but isn't it more rational to focus on high risk conditions in general rather than saying what amounts to "women get a free pass, men gotta pay"?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You need to get the console text attributes before changing them, then reset them after you're done (either before or after setting the cursor position).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Insurance is based on the fact that the majority of insured persons won't use the majority of services they are insured for - they subsidize the unlucky few who do need to use them, otherwise insurance premiums we be no different than paying out of pocket.

I'd be okay with that, if the services subsidized were something I could potentially use if unlucky enough to need them. Try grepping the legislation for instances of "women" and "men". Then cross reference the preferential treatment in each instance. Maternity coverage is merely the most obvious and easily defended of sexisms in the legislation.

Last I checked, there were well over 100 benefits unique to women (that men are required to subsidize, recall). Conversely, male-specific benefits was 0. This is hardly fair, and I question half the population being forced to pay for things they couldn't possibly use (ever!).

And frankly, pregnancy almost always involves two participants one of which may be an unmarried older man. Why shouldn't he contribute to subsidizing the health care costs of the unmarried pregnant woman?

Almost always? More like always, unless science has invented artificial sperm. I'd like to respond to the logic here, but I'm having trouble properly putting it into words. Sorry.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Allow me to ask the obvious question, why would you want to recursively read a file?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but i still want to know if it can be done

Yup, it can be done. How depends somewhat on how you're deploying the setup.exe, but typically for standalone installers you can either use the default user interface, tweak the default user interface, or define your own completely.

For example, in Visual Studio's Setup & Deployment project (.vdproj), if you right click on the project and choose User Interface from the View menu, you can fiddle with the install wizard views. You can also use custom actions to get a little more flexibility.

With something like WiX, you get much more control over the UI, but at the cost of a steep learning curve for the declarative XML language. I actually prefer WiX if any kind of customization beyond UI banners is needed, otherwise the standard Setup & Deployment project is easier to build and maintain.

InnoSetup is also popular because it has an expressive scripting language. I haven't done much UI customization from InnoSetup though, so I'm not qualified to provide details on your question.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i ment to put c i just changed it to counter so you guys knew what it was

That's a hint that it should be counter in the first place rather than c.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's an issue with your code editor. If you can set the character set to something like Unicode, you should be good to go.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The good news is you can do it. The bad news is you have little choice but to use a platform dependent method to set the console into a wide character mode. For example:

#include <iostream>
#include <fcntl.h>
#include <io.h>

using namespace std;

int main()
{
    _setmode(_fileno(stdout), _O_U16TEXT);

    wcout << L"glória vitória\n";
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It sounds more like the issue is with creating a Windows Service. It's pretty straightforward as far as setting things up, though there are a huge number of variations depending on what you want to do and how you want to do it.

The MSDN tutorial is a good start.

The problem here is that you're asking for things that involve too much code to comfortably put in a post.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I have implemented OpenPOP methodology however it is developed in windows forms and I thought of some windows service to achieve this.

OpenPOP doesn't depend on Windows Forms, last I recall. There may be a Windows Forms test or utility, or something, but you should be able to ignroe it. You can use it in a class library or a Windows Service with no issues at all. Of this I'm sure, because I've done it before.

I used OpenPOP in a service before I moved to my own POP3 management library. And the only reason I moved to my own was to facilitate easier support of IMAP, OWA, and MAPI.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't recall of the top of my head what the polling interval is for sending those emails. Now that we know you're watching this thread, give it 24 hours and let us know if you still don't get an email.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is the thread in your watched articles list?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Hop into your edit profile page and make sure that "automatically watch articles I post in" is checked. If it is, look for that thread in your watched articles page. I'd wager that you're simply not watching the article, so you won't get new post notifications.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Imperative, procedural, declarative, functional, object-oriented...there are many programming paradigms. C++ is largely imperative (inherited from C), supports OOP, and has been introducing functional aspects lately.

Try looking at Wikipedia for "programming paradigm".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How would I detect the use of Shift key?

Please read my post again. Not only did I describe exactly what you're asking, I linked to documentation on the KeyEventArgs class so that you can get full details.