|
I found this code for a word count, but I want to loop pages and search the header, body, and footer.
using System;
using Microsoft.Office.Interop.Word;
class Program
{
static void Main()
{
// Open a doc file.
Application application = new Application();
Document document = application.Documents.Open("C:\\word.doc");
// Loop through all words in the document.
int count = document.Words.Count;
for (int i = 1; i <= count; i++)
{
// Write the word.
string text = document.Words[i].Text;
Console.WriteLine("Word {0} = {1}", i, text);
}
// Close word.
application.Quit();
}
}
|
|
|
|
|
|
Hi I'm new to programming and I'm still confused most of the times to figure out the logic behind those problems that I'm working with. I feel like I'm so stupid. I wonder how other programmers come up to those kinds of solutions. Please give me some tips on how to improve my programming skills.
|
|
|
|
|
Everyone here was once a "beginner;" don't feel alone
Suggestions:
1. decide on an initial language to learn: I recommend C# used in the context of the .NET framework.
2. get a good book on the language you've chosen to learn, and get a programming environment (IDE) set up where you can start experimenting with the language. I recommend using the free editions of Visual Studio for your IDE. For a book: how about Charles Petzold's ".NET Book Zero," which is free: [^].
3. Start studying, start experimenting, download the code samples (if available) in the book you are using, run them, and experiment with them.
4. very important: learn how to debug ... to set break-points, to observe the value of variables, and the "state" of "objects."
5. get so busy learning, experimenting, and analyzing the results of your experiments, that you never have time to think about whether or not you are a "beginner," or, if you "understand programming."
cheers, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
It's not too bad, once you get your head around the process.
Start by breaking the task into smaller chunks - for example, it your have to get two values from the user, add them together and print the result (and yes, I know it's trivial) then you would brak it into three bits:
1) Get values
2) Add
3) Print Then look at the first one "Get values" and break that into smaller bits:
1) Get values
1.1) Get a value
1.2) Store it somewhere
1.3) Get a value
1.4) Store it somewhere else
2) Add
3) Print And you start to see that 1.1 and 1.3 are the same job - so they can be done with the same code. You then continue this until each of the tasks you have is pretty simple - and then implement them!
There is a technical term for this - reductionism - and it's a process we use all the time in real life without really realising it: "Make tea" for example reduces to "boil water", "brew tea", "add milk and sugar", "combine" - and each of those breaks down into simpler actions we take without thinking.
Another way to get started is to do the job manually, and think about the processes you are involved in to do it. This can give you a good idea of the overview, and you can then start reductionism to separate out the simpler tasks.
It's a skill - and like all skills it only comes with practice - so try it. You'll get it wrong (we all did, and we all do) so be prepared to throw it away and start again, but you'll get better as you go along.
Good luck!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
These days, the main emphasis seems to be on the "newer" analysis and design tools: state diagrams; sequence diagrams; activity diagrams; etc.
I don't think any of these tools is a substitute for a plain "old" flowchart and / or decision tree when it comes to a particular piece of non-trivial logic.
A simple flowchart can help one to better understand a particular process (and how to program it).
If you're not familiar with flowcharts or decision trees (or some of the other "older" tools), you should take the time to learn about them if you are serious about programming. Even the "old" stuff can be useful in a particular situation.
|
|
|
|
|
Hi Gary,
I find your mention of "decision trees" very interesting; I have always wondered why they seem to have been "left-behind" in the last years.
I've been implementing my own decision-tree control in C#/.NET and intent to publish it here when it's "ripe."
An intellectual problem I see in implementing useful decision trees is to figure out a way to analyze the possibly numerous criteria so that you select-out the variables whose state-change has the maximum predictive power for the outcomes.
Imagine an air-fare discount decision-tree with some thirty possible variables, each having #n possible states: analysis of the possible decision matrix might lead to concluding that the most "powerful" predictive variable was the flyer's "age."
How to create an interface that assists "mere mortals" to write efficient decision-tables that are "pruned" so that the minimal effective set of rules/actions are used. That's the interesting problem, to me.
cheers, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
the problem is only a problem as loong as u dont have the solution yet;)
"Divide and conquer". Break Down the problem so much Down that u only solve 1 problem at the time.
If u have to do that solution many times, look for "loops".
But i think that every programmer has his weak points.
But u will get stronger and stronger to see what to do.
Using a editor will give u some sort of feedback, to what u are missing.
And mistacks will be made , i dont think i ever 1 shottet a solution. Allways something Little thing that i overlook.
I my self find web programming slow, so slow that i have to only do 2-3 linie before i debug. Mayby because of ininspirence but havnt find a editor for it. It just Work or it dosnt.
And it is easy just to look and twist a few linies to see the result, than to look at 15 linie, and no where to start.
So just keep learning.
It is mostly just matematik and logik.
And speeking of logic, i still get - less than and greater than (<>)the wrong way.
Best regards
jan
|
|
|
|
|
Hello,I understand Shell Sort definition but I can not understand
this C# code:
public void shellSort()
{
int inner, outer;
long temp;
int h = 1;
while(h <= nElems/3)
h = h*3 + 1;
while(h>0)
{
for(outer=h; outer<nElems; outer++)
{
temp = theArray[outer];
inner = outer;
while(inner > h-1 && theArray[inner-h] >= temp)
{
theArray[inner] = theArray[inner-h];
inner -= h;
}
theArray[inner] = temp;
}
h = (h-1) / 3;
}
}
please help me thx!
modified 2-Oct-15 4:39am.
|
|
|
|
|
The best way for you to help yourself understand this code is to create the initial Array and the required 'nElem variable, put a break-point at the start of the code, and then run the program, single-stepping (using F11 in Visual Studio) through the code, and observing what happens with each step. Hover the mouse over the variables and inspect their current values.
As you study what is happening in the code, take breaks, and go back and read about how the Shell sort "works." Then observe/study the running code again.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
The answer hasn't changed since you posted exactly the same message[^] yesterday.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Message Removed
modified 2-Oct-15 4:40am.
|
|
|
|
|
I have a table in a database containing a number of records. The records have an ID number i.e. H1, H2, H3. Each record also contains a field called C1 which contains a value.
There can be multiple records with the same ID.
I want to read all the values of fields C1 for records with the ID H1 into an array. I don't know exactly how many records there are with the ID H1.
I don't want to do this in SQL.
Does anyone know how I would create a collection holding the values?
|
|
|
|
|
Read the data from the Db using a trivial SELECT:
SELECT C1 FROM MyTable WHERE ID='H1'
You can read the values using a DataReader, or a DataAdapter - whichever you are comfortable with.
For a reader, it's really simple:
List<MyTypeOfData> collection = new List<MyTypeOfData>();
while (myReader.Read())
{
collection.Add((MyTypeOfData) myReader["C1"]);
}
For an adapter, just use the table data in a Linq query:
var collection = myDataTable.AsEnumerable().Select(row => (MyTypeOfData) row["C1"]);
[edit]forgot the brackets... [/edit]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thanks for the reply OriginalGriff.
What i want to do is add together all the values for each occurence of C1 and then to write this to a field.
Can I do this with what you have suggested?
|
|
|
|
|
To add them together (assuming they are numeric), you don't even need a collection:
SELECT SUM(C1) FROM MyTable WHERE ID = 'H1'
Will return the total for you - and you can use ExecuteScalar to fetch the value directly without a reader or adapter.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I want to do this through C# though
|
|
|
|
|
The just add the collection items together!
Use a foreach loop, or even a Linq method:
var sum = collection.Sum(item => item);
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Linq Method Would probably be the best as I have to write it out to a field.
I'll put together some code and see what you think?
|
|
|
|
|
Sounds good!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Im trying to do something like this:
var complexQuery = from e in orgContext.CreateQuery("Eval")
join c in orgContext.CreateQuery("Contract")
on e["contractid"] equals c["contractnameid"]
I want to do a Count of the complexQuery and whatever the count is I want to add this to a variable so I can write this out to a field.
|
|
|
|
|
Um...you do realize that a Collection has a Count method?[^]
So to get all the elements in your total sequence:
var complexQuery = from e in orgContext.CreateQuery("Eval")
join c in orgContext.CreateQuery("Contract")
on e["contractid"] equals c["contractnameid"];
int count = complexQuery.Count();
If you are trying to get the count of elements with matching ids (i.e. a collection of counts) then just Group the linq query and select the count of each group.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thanks for your help Ill try this.
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
It sounds to me like you're looking at having a Dictionary of Dictionaries like this:
private Dictionary<string, Dictionary<string, ClassRepresentingOtherItems>> dictionary = new Dictionary<string, Dictionary<string, ClassRepresentingOtherItems>>();
public void Add(string id, string fieldValue, ClassRepresentingOtherItems items)
{
if (!dictionary.ContainsKey(id))
{
Dictionary<string, ClassRepresentingOtherItems> childDictionary = new Dictionary<string, ClassRepresentingOtherItems>();
dictionary.Add(id, childDictionary);
}
dictionary[id].Values.Add(fieldValue, items);
} This allows you to associate many fields with the same ID.
|
|
|
|