❔ I have a project and I need to implement a functionality to create a membership for users
I need help with using exporting & importing data in a text file in a my console application project
60 Replies
what have you tried and what problem are you currently having?
Let me show you
Here is my plan for the project
I'm trying to take user inputs save them in a variable and then pass this variable as a path to write it to a text file, then read the file and create a membership, ultimately it's just a practice project, is it possible?
I know we could write data to a text file and read/import data from a text file
Why do you have a StreamWriter is a validation method...?
as
Oh! This needs to be modified, because at the beginning I was thinking on only taking user input and validate, but the I thought this is boring.
I wanna practice using text file not taking user input 🤨
you should practice planning out your project before writing any code
list out all the data that you need, how it should be organized, and what actions you need to do with it
Well! I have done that. But not very precisely as you mentioned about the data.
I have planed the project on a piece of paper as a diagram.
could you share that?
Although it's not considered as completed yet
Do you think I need to use a softwire to draw a diagram flow?
it's probably easier than trying to do it on paper
i would comment that a part that says "apply logic" isn't useful to write down, you should be more specific about what the code needs to be doing
for example, this is a very rough outline of a feature i'm working on for one of my work projects
Ok! Yeah! I think using software is better and more efficient Teknik to see the flow of the project than using the typical way with pen and paper.
Ok! It looks a bit cryptic to me and not really understand some of these outlines. But it looks more organized and splited into multiple sections.
I basically sketched out what data I need and what has to be done with it
Which you should have a good idea of before writing any code
Otherwise you might get stuck with code you have to rewrite because you didn't plan ahead
Ok! Yeah! You're absolutely right. Planning the project and get a very clear view about the sections that needs to be implemented will save too much time.
So I could do that? .
yes
it's not exactly clear what you want to do, which is why i suggested planning it out more thoroughly
it's easier for us to help if you have a good plan
I mean the docs shows that you could write any string value to a text file, so instead of hardcoding the
"Hello World!!"
string, I could write the users data and store in a text file in the program.Sounds great. I'll plan the project, so you'd get a glimpse of what I'm trying to create. I'll go and plan it then. Thanks a lot so far 🤗
Just a quick question, let's say I took all these user inputs, should I be saving each data in each its property?
I mean those are variables too, right?
yes, if the data is related to each other (like different data about one user) you should group them in a class
Ok
They are already in a class
yes
But shouldn't I be using seters too to set value for each property?
it depends
do you want to change the data after instantiating the class?
Right now I'm using only the getters to get their values
Although, I haven't done the logic part e.g. while loop, other methods, lists and etc..
I had modify the last square to
user membership
so i don't think a flowchart is the correct type of diagram for this
Ok
a flowchart models one process from start to finish, you put a whole bunch of stuff in here
you probably want to look at a class diagram
or even just a plain list with bullet points like i showed above
Yeah! This will require making a lot of stuff and it will take some time to draw everything.
Exactly, I totally agree with you. Your method and the way you structure your project flow is much easier and faster bing done than using this type of software.
I wasted some time on this, but I learned something too at least when planing in future projects.
if you do want to do diagrams i recommend looking at the different types of diagrams available and understand how each one can help you plan your project
for example, a flowchart might be good to plan out the logic of a single method
planning your class definitions and relationships between them would be done with a class diagram
Yeah! That's right bro.
Ok! So how do I find this type of diagram to be able to use it for this type of project? Can you recommend me for one?
just did
You mean just like you did?
.
i mean i just gave you 2 examples of diagram types and when to use them
Ok! So I think I will keep the flowchart the way it is currently to see what I'm building, then I would need to plan the logic or the classes as a list with bullet points, right?
that's not what a flowchart should be used for but sure
this is the point where you should do some additional research
Aha! Ok! I get that. You're right.
I'm planing the logic on a simple file just like you did anyway
This just a the primary planing, I haven't done the whole yet. What do you think?
looks like a good start
Awesome
I thought your off line because of difference in timezones, other wise I was gonna ask you in the first place.
Should I try writing this code solo first even if do it wrongly?
always try it first
if you ask someone how to do it before you even try, you won't learn as much
That's a very good advice. Very wise said and done.
I should be validating the user input first, before adding any invalid data to a text file, right?
what do you think?
what would happen if you didn't?
These are good questions that makes me think more deeply when it comes to data
I mean although this is just a console application, but still I should validate, because what if the user inputs only one character instead of a name? What if the age is 2000? What if the email address is invalid? I think I need to practice these validations to get ready for applying them in GUI apps when working professionally, w d y think?
Plus, I should make sure that these data are separated by a delimiters, so the data don't get mixed other wise I won't be able to read them later.
correct
Awesome
There's something called regex where you pass a certain collection of characters inside parentheses and you use them for validation, but not sure exactly how?
I mean the format should be as long as input is not null or the following characters then store the value in a variable, otherwise I think an exception will be thrown.
https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex?view=net-7.0
https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.regularexpressionattribute?view=net-7.0
Regex Class (System.Text.RegularExpressions)
Represents an immutable regular expression.
RegularExpressionAttribute Class (System.ComponentModel.DataAnnotat...
Specifies that a data field value in ASP.NET Dynamic Data must match the specified regular expression.
I'm gonna review these attached links and learn how to apply the Regex to my project, thanks 😉
To be honest, didn't quite understand the content in those links, would be able to explain?
Do you know how to add validation to a property?
@IceGPTI've done it this way in my previous project
But without using a method though
<a:cat_no:768672517325717544>
well idk if you're doing a web project but you can google
No, man it's just a console application.
I don't think I could use this docs as validation for my project
ubk
Useful scripts | Basic and Advanced Day to day used scripts
DataAnnotation based validation in C# Console Application
Data annotation based validation in C# console application.
sure heres the 2nd link i found under google
you dont necessarily have to do it this way
Ok! Awesome bro. I'll definitely take a look at this link. Thanks a lot
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.