deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You may want to do some research on the OpenXML file format, it's not as simple as raw text. For something like this I'd look for a library that extracts Word files and then place the (hopefully) formatted text in my control.

Aspose.Words is a good library for this that I use professionally, but it's not free.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What is the general way of changing the user account under which the application is running?

The general way is to restart the application under elevated privileges:

Private Sub ElevateMe()
    Dim proc As new ProcessStartInfo()

    proc.UseShellExecute = True
    proc.WorkingDirectory = Environment.CurrentDirectory
    proc.FileName = Application.ExecutablePath
    proc.Verb = "runas"

    Try
        Process.Start(proc)
    Catch
        Exit Sub
    End Try

    Application.Exit() ' Kill the old process
End Sub

Permissions are done on a per process basis, so while you can demand admin rights at a higher granularity, it would require the application to originally be started as an admin in the first place.

I don't want the Program to restart as by doing so I will not able to save some of text, images, audio etc

Why not? Save the current state of the program and then reload it when the new process starts.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're probably one of the most unpopular posters DW has ever had.

I can think of a few that would vie for that title, but they gave up fairly quickly long before voting was introduced.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Little do they know that we geeks don't let mere holidays keep us from Daniweb. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i whant full prodram

No. Please read our rules.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your question is too vague.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@Deceptikon: Out of interest, what's the performance difference between Regex and the LINQ statements I create?

That's something I'd profile if it worried me, which it doesn't in this case. My guess is that that LINQ would win out most of the time, but with such a simple pattern and when the string is longer, the expression building logic of LINQ could overwhelm the setup of a regex parse.

The methods of solving the problem are different enough to make a comparison difficult though. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please help me ........

With what? All you did was post a homework assignment verbatim.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're opening your file in "a+" mode. This doesn't mean there's a read position and a write position. The file position is initially at the beginning of the file for reading, but the instant you do a write, the position is set to the end of the file. Subsequent reads without an intervening seek or rewind will still happen at the end, which accomplishes nothing after your first record is added.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What have you tried for yourself?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What you're asking is nonsensical. You want var1 and FUNC to have file scope, yet still be visible in other files. Why?

My guess is that you're confusing how static is overloaded and want semantics that are actually already there with extern functions and variables. It might help to explain exactly what you want to accomplish here, rather than how you think it should be done.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Done :)

The result set must include delimiters, not remove them. ;) Try this little one-liner:

var parts = Regex.Split("abc,123.xyz;praise;end,file,clear", @"([\.,;])");
ddanbe commented: Nice! +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It was more like, "Normally Daniweb users are able to help their users so why can't you help out like them"and so on... It wasn't like, "SO is #### so join Daniweb!"

I can't see how that could go wrong, given the pissy tendencies of many SO regulars. :rolleyes:

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I wasn't implying my way is best practice, just some anecdote on how I work. Maybe I'm just a control freak. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you have VS you can also connect to a database via the Data menu.

Maybe I just have an old school mentality, but I've never handled database connections or data through the Visual Studio UI. I've always done it from straight code.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

strcpy(ptr->name, s);

strcpy(ptr->name, s.c_str());

However, be very careful that the length of s doesn't exceed the bounds of ptr->name. The ideal (aside from using std::string for name in the first place) is to make name a pointer and allocate memory appropriately:

node *ptr = new node;

ptr->name = new char[s.size() + 1];
strcpy(ptr->name, s.c_Str());

Also don't forget to release your memory. This can all be handled in your node definition through constructors and destructors:

struct node {
    char *name;
    int price;
    node *next;

    node(const std::string& name, int price, node *next = 0)
    {
        this.name = new char[name.size() + 1];
        strcpy(this.name, name.c_str());

        this.price = price;
        this.next = next;
    }

    ~node()
    {
        delete[] name;
    }
};

Then the code becomes as simple as:

void apple::insert(string s, int a)
{
    head = new node(s, a, head);
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The problem is when I login, it would only read one record.

That's exactly what you tell it to do. Technically, your file reading loop in login is pointless because the first iteration returns from the function in all cases.

I suspect you intended to return 0 only if the loop exits normally:

while(fscanf(fp,"%s\n%s %s\n%s\n", obj.employeeID, obj.employeeFN, obj.employeeLN, obj.employeePW) == 4){
  if(strcmpi(obj.employeeID,loginEmployeeID)==0 && strcmpi(obj.employeePW,loginEmployeePW)==0){
     return 1;
  }
  else if(strcmpi("admin",loginEmployeeID)==0 && strcmpi("admin",loginEmployeePW)==0){
     return 2;
  }
}

fclose(fp);

return 0;

Take a look at the loop condition as well; I fixed a bug for you. feof should not be used to control the loop. Due to timing of events, it introduces an off-by-one error where the last line may be processed twice.

Pia_1 commented: It works perfectly..thank you so much! +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My books show - and > but neither of them seem to apply. The books don't seem to show both together.

Strange books. -> is a single token, and should at the very least be mentioned in the precedence table for operators.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's an easy one, TabPage doesn't have an Activated event. :) The Click event is fired when the mouse clicks on the control.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The reference is System.ComponentModel, MarshalByValueComponent is a class in the namespace.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is that a big square hole in your wall?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd recommend against that, actually. It makes managing the connection harder. Also, many database servers will support connection pooling to eliminate the performance cost of creating, opening, and closing a connection for each transaction.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm going to guess that mode_t is already defined as something like unsigned int, or maybe as an intrinsic type in your compiler. In that case, your define would end up being expanded as unsigned int int, which is an illegal type name.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please post the contents of my_global.h.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Over the years I've been leaning more toward #2 because it's easier to manage. When all of the controls are directly inside your TabControl, they must have unique names regardless of whether they're on separate pages.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The percentage is a string, which makes things a bit more difficult as you have to convert that to something you can use in a mathematical expression. Let's say InsurancePercent is of the form "###%". The process would be some variant of this:

var percent = Convert.ToDouble(patient.InsurancePercentage.TrimEnd('%'));
var insuredAmount = patient.AmountDue * (percent / 100);

Console.WriteLine("Insured Amount: " + insuredAmount);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes, there are many grid controls, but only a couple of standard .NET ones. The standard controls also vary in name and features depending on whether you're using something like Windows Forms, WPF, or Web Forms.

Third party controls are numerous. They could be free, but the best ones tend not to be free.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i do always study but always forget..i feel sumties like stupid !!

You remember what you use often, and references are there for what you don't use often. Don't feel bad, there isn't a programmer in the world who can remember everything, and it gets harder to remember as you learn more.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If it's going back to the start of the sequence, either you're not querying the newest ID or you're overriding what the database returns. It's hard to say without seeing both your database schema and all of the code.

Would it be possible to pare down the code into a very small console mode program that exhibits the problem?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can set the delimiter for getline().

Indeed, but only one delimiter. If the line doesn't end with '.', input will span multiple lines. A full solution would use getline from the file to read a whole line, then getline with '.' as the delimiter from a stringstream of that line:

string line;

while (getline(in, line)) {
    // Display the line header

    stringstream ss(line);
    string line_part;

    while (getline(ss, line_part, '.')) {
        // Display the line part
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So pass by reference basically boxes, or stores a pointer to the data type provided in the heap.

No. Passing by reference doesn't box a value type. Let's also differentiate between passing by reference and passing an object reference:

void foo(object obj);     // Passing an object reference
void foo(ref object obj); // Passing by reference

When passing an object reference, the reference to an object is passed by value. When a value type is passed by reference, compiler magic allows the called method to access the original entity.

This address in the heap is passed to the method.

Not necessarily. Deep under the hood you may ultimately have a pointer (another object holding an address), but it's equally likely that the compiler is smart enough to simply bind another symbol in the symbol table to the same address and avoid any kind of indirection.

However, if a pointer is used, you introduce the overhead of fetching the object at that address. This can overwhelm any savings you might get from the performance of minimizing copying in the method call.

Given this, it would be more efficient in all situations to pass by reference rather than copy the whole value in a pass by value operation.

Would it? Try writing a test where you call a method with a value parameter in a long loop and profile it. Then do the same for a long loop that calls a method with a ref …

Ketsuekiame commented: +1 This kind of micro-management is very rarely required. +11
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A DataTable is the back end container for data, it corresponds roughly to a database table. A DataGrid or DataGridView is a UI control for displaying tabular data. It may or may not bind to a DataTable.

I'm not sure what controls those applications use, they may be custom grid controls. But it's safe to say that they use something like a DataGridView.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can Any body do it????

Yes. But nobody will do it for you. Please read our rules.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This smells like spam bait, but we'll see. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't understand the question. What are you trying to do now?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My C/C++ classes swore by passing by reference as a good coding practice, and I have passed even primitive values by reference for a while now.

Even in C++ it's a tradeoff. The size of a reference versus the size of the object being passed relative to the cost of an extra level of indirection (even when it's hidden from you). Generally, in both C++ and C#, you can feel confident passing scalar types by value. Scalar types are things like char, int, double, decimal.

In C# you'll usually be passing by reference except in the odd cases where you're using a value type such as DateTime.

Even then, my recommendation is not to worry about it for performance reasons unless you have profiling results that show a slowdown, you've done everything you can at a higher level, and micromanaging how you pass parameters is the next step.

Instead, focus on functionality. If you want to update the object being passed either by reseating the reference or creating a reference from a value type so that it can be modified from another function, consider using either a ref or out parameter. Otherwise, use the default passing semantics for the type.

The trick is to do what you need to do when you need to do it and not before. Otherwise you'll end up with over-engineered code that's harder to maintain and may even be counterproductive in terms of performance.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

<M/> - It is just the first letter of my first name within tags...

Is it meta? Does it mean you have no value? ;)

Oh the fun of reading way too much into things.

<M/> commented: lol +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The downside is that using namespace will make the entire namespace visible, even if you don't want all of the names to be visible. There's risk of naming clashes. Prefixing std:: is more verbose, but also imposes no risk of name clashes.

For namespace std, it's really just a matter of knowing what names are there and avoiding creating new names that match. But that's not as easy as it sounds, so the general best practice is to limit how many names you expose from a namespace.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Hey, I have an idea! How about you do your own homework instead of asking other people to help you cheat?

nahi commented: tebeda +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd recommend against using ADODB. ADO.NET (the OleDb variants, specifically) should be your go-to for database connections in .NET and is the replacement for ADODB. Following the previous link you'll find that the documentation provides sufficient examples to come up with something workable. You can also find appropriate connection strings here.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Post your code and the examples that aren't working the way you think they should.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Start by making sure that your driver is working the way you want using a standard sorting library. Here's one that uses qsort in C-style since you're into C-style strings:

#include <cstdlib>  // std::qsort is here
#include <cstring>
#include <iostream>

using namespace std;

namespace {
    const int COUNTRY_MAX = 5;
    const int COUNTRY_NAME_MAX = 255;

    int compare(const void *a, const void *b)
    {
        return strcmp((const char*)a, (const char*)b);
    }
}

int main()
{
    char countries[COUNTRY_MAX][COUNTRY_NAME_MAX] = {0};

    cout << "Enter " << COUNTRY_MAX << " countries.\n";

    for (int i = 0; i < COUNTRY_MAX; i++) {
        cout << i + 1 << ": ";
        cin.getline(countries[i], COUNTRY_MAX);
    }

    qsort(countries, COUNTRY_MAX, COUNTRY_NAME_MAX, compare);

    for (int i = 0; i < COUNTRY_MAX; i++) {
        cout << countries[i] << '\n';
    }
}

If this is sufficient, you're done! Otherwise, you might be asked to write your own sorting function, which is relatively straightforward and also a good learning exercise.

Keep in mind that C-style strings are arrays and do not support direct assignment. You'd need to use something like strcpy (still thinking in C mode) to copy the content of the arrays.

On a side note, 20 is too small for country names. IIRC the longest official country name pushes 70 characters, and unofficial names push 200. The ideal would be to use std::string and let each object size itself properly so you don't need to worry about such things. An added benefit is that std::string supports copying with the …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please post your question in English.

Hinata_Dev commented: ok :) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Using ADO.NET to connect with an Access database is straightforward. Can you post your most recent code that doesn't work? Start by doing just the bare minimum in a console mode program so that all of the unnecessary fluff doesn't get in the way.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Break your program down into pieces. First I'd write a test console program that implements an LSB method for monkeying with bytes and ensure that it works the way I want. Then I'd write a GUI program to load an image and enumerate it's bytes, then save it. Finally, I'd work on merging the two.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Without a third party control, you'd need to make it yourself using expandable panels (think hiding the panel with the click of a button) and a FlowLayoutPanel.

Example 1
Example 2

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If that prank were real, and I strongly doubt it was, asking about his daughter as a first priority was totally evidence of good character.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but seriosly, the drinking age should be increased... (my opinion)

Age doesn't equate to maturity, unfortunately.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What content? You always free buffer (also note that it's a local pointer and not accessible outside of the function) and never populate text. The function certainly reads a file, but it doesn't do much more than that.