|
hello Gurus,
i am very new to C#.
just to give you a little background of myself, i work as a teamlead for a sap abap team.
i wanted to create a very simple windows form to track the productivity of my team using c#
this is the pseudo code I wanted to implement:
1. input will be taken from a textbox (numeric in value)
2. if textbox input is found in excel worksheet, (where field code = textbox)
3. then, append the value to a datagridview and clear the textbox (for the next numeric input)
4. else, popup message "value not found in the excel worksheet".
my form contains:
1 textbox
1 datagridview
my worksheet looks like this:
code | description | field3 | field4
1 | some description | field3 | field4
The field "code" is my primary key.
hope someone replies.
many many thanks,
-Myth-
|
|
|
|
|
I'm not sure what you are asking us to do. But if you do not know how to code, I would suggest sticking to Excel and building your form there.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Do yourself a favour, and don't use a spreadsheet - use a "proper" database (SQL Server, SQLite, Access, MySQL, ... whatever) - don't try and force a spreadsheet to do a database function.
While it's possible, it's a bit "I've got a hammer now how do I screw that desk together?".
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Griff, while I find your intuition/insight always prescient, I think, in this case, more information about how Excel is used here (work-flow) would be valuable; I've posted a query to the OP. cheers, Bill
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
To respond to your query, I'd need to know:
1 Excel: who creates these Work/Books/Sheets; why are they used; who uses them; etc.
2 Why Excel rather than a database ?
3 What's the work-flow: how is data gathered from developers ?
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Hello Bill,
Thank you so much for your reply.
to answer your queries:
1 Excel: who creates these Work/Books/Sheets; why are they used; who uses them; etc.
-----> originally, what i have i mind is, to implement 2 functionalities in my windows form. 1 for creation, and the other one is display.
for the creation part, this is already done, -i have already figured out how to append entries to the excel worksheet (using text boxes and a button). for the display however, i don't know how to validate the incident number (code field) against the existing entries in my worksheet, hence this thread is created. (as described in my OP).
as for the the 'why are they used',
-----> right now, the current tracker that was handed over to my team doesn't allow simultaneous update. (which is kind of -for the lack of a better word: dumb).
for 'who uses them'
------> my team is small - just 11 people.
2 Why Excel rather than a database ?
----> i am thinking of using excel, because, the current tracker that i have is made of excel (using macros and some vbs i believe). so i was thinking, it will be easier to migrate the existing entries that my team have created. (plus the original developer of our tracker already resigned. :P ).
3 What's the work-flow: how is data gathered from developers ?
----> the data is gathered from developers via creation functionality (which, as mentioned, i already implemented -thanks to this forum. .
i am really new to C#. and one of the reasons why i wanted to create the simple tracker is for me to learn the language as well.
hope to hear from you soon.
-Myth-
|
|
|
|
|
Let my see if I really understand your comments: are you the only person who somehow monitors your team member's coding, and creates the data entries ?
I keep thinking there is some automated process being used here, and that you are accessing some data store ? Wrong ?
cheers, Bill
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
I'm currently doing console application. How do I display S.1.1.004 into the console?
CREATE from S.1.1.001 to S.1.1.002 on Monday, 7th of May, 2019 07:20:44
CREATE from S.1.1.002 to S.1.1.003 on Tuessday, 23rd of March, 2018 10:01:22
CREATE from S.1.1.003 to S.1.1.004 on Wednesday, 4th of February, 2019 5:42:45
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
namespace ReadFromFile
{
class Program
{
static void Main(string[] args)
{
TextReader st = new StreamReader("C://test.txt");
int NumOfLines = 3;
string[] ListLines = new string[NumOfLines];
for (int i = 0; i < NumOfLines; i++)
{
ListLines[i] = st.ReadLine();
}
Console.WriteLine(ListLines[2]);
Console.ReadLine();
st.Close();
}
}
}
|
|
|
|
|
Assuming that you want to show a specific part from the last line in the file, you can do it very easily.
There are two basic ways: use Substring, which extracts a specific portion from a string (good if your line format is static and never changes) or use a Regular Expression (good if the data moves around, changes position from line to line).
First, read all the lines:
string[] lines = File.ReadAllLines(@"C:\Text.txt");
You can identify the last line directly from that
string lastLine = lines[lines.Length - 1];
You can then extract the bit you want - I'll use substring:
string bitYouWant = lastLine.Substring(25, 9);
And print it:
Console.WriteLine(bitYouWant);
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks for the explanation. Why does the substring starts from 25 and end at 9 ? Is '9' the length?
|
|
|
|
|
Here is the documentation of the Substring method:
Substring(Int32, Int32)[^]
You could also use a regular expression to extract the value you are looking for:
Regex r = new Regex(
@"^CREATE from S\.\d\.\d\.\d{3} to (?<value>S\.\d\.\d\.\d{3}).*$"
);
string value = r.Match(lastLine).Groups["value"].Value;
while (!(success = Try()));
|
|
|
|
|
Does the while code needed?
|
|
|
|
|
No, the while loop is my signature
Sorry for that ambiguity.
while (!(success = Try()));
|
|
|
|
|
I think you forgot to add Console.ReadLine();
|
|
|
|
|
phil.o has given you the documentation, but if you look at your line text, the section you want starts at index 25 (starting form zero, remember) and is 9 characters long. So those are the numbers you feed into substring to specific exactly which chunk of text you want to extract.
A Regex will do fine, but they can be complicated and difficult to understand (and worse to modify), so it you can use a "fixed position" extraction for now, that's the best place to start.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks for the explanation. I have a better understanding of substring
|
|
|
|
|
You're welcome!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
string line3a = File.ReadAllLines( "xxx" )
.Skip( 2 )
.FirstOrDefault();
string line3b = File.ReadAllLines( "xxx" )
.SkipWhile( s => s.Contains( "S.1.1.004" ) == false )
.FirstOrDefault();
if ( line3a != null ) {
}
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
ReadAllLines reads the whole file into memory. In this case, it would be better to use ReadLines instead.
File.ReadAllLines Method (System.IO) | Microsoft Docs[^]
File.ReadLines Method (System.IO) | Microsoft Docs[^]
Quote: The ReadLines and ReadAllLines methods differ as follows: When you use ReadLines , you can start enumerating the collection of strings before the whole collection is returned; when you use ReadAllLines , you must wait for the whole array of strings be returned before you can access the array. Therefore, when you are working with very large files, ReadLines can be more efficient.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi All,
I was looking more for a snip in c#/WPF of making connection to AD Azure server for authentication.
The rest of the code i can do by my self.
The info that i find with google is not clear how to do it
Regards
Jan meeling
Thanks
Regards
Jan Meeling
modified 27-Aug-19 8:11am.
|
|
|
|
|
Here you can find some examples:
Azure Active Directory code samples (v1.0 endpoint)[^]
And your favorite search engine will give you plenty of other links.
enum HumanBool { Yes, No, Maybe, Perhaps, Probably, ProbablyNot, MostLikely, MostUnlikely, HellYes, HellNo, Wtf }
|
|
|
|
|
Maybe he/she/them/they doesn't have a favorite search enchine.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Or maybe his/her/their favorite is just us.
enum HumanBool { Yes, No, Maybe, Perhaps, Probably, ProbablyNot, MostLikely, MostUnlikely, HellYes, HellNo, Wtf }
|
|
|
|
|
Hi Phil,
Thanks for pointing to the right way.
On the search engine is lost of grape .
Regards
Jan Meeling
|
|
|
|
|
I need to win the lottery, but that isn't working for me either.
Perhaps if I bought a ticket, I'd stand a better chance or winning?
Likewise, if you put some effort into working out what to do, rather than just going "!give me the code" you could have a chance of completing your project as well.
We aren't a "code to order" service.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|