Filip said:
I want a button that creates a .txt, lets me name it and lets me choose where to save it, but it has the data (words numbers whatever,) that i've typed in my edit box.
...
the editbox goes by thisform.edit1
The line of code you need in the button.click event is
Code:
STRTOFILE(Thisform.edit1.value, PUTFILE('','','*.txt'))
Edit: Important, I had these two parameters backwards, first parameter is what to save, i.e. the value of the editbox, second parameter is the file name.
Filip said:
please dont send me messages replace this replace this, if its not necesseary becasue i am a beginner so i dont really know that much
I fear I already did, but how could you know what to do, if you don't get told? I think you fear not understanding the instructions, if they are too brief, but also, when they are too verbose and full of things you don't know that.
Beginning with programming is overwhelming, nobody can protect you from that, sorry.
To get a bit less brief, let's go some steps back tto where you are: You have put an editbox onto a form, that ot the name "Edit1", which is normal, yes. And in the first place, this is okay and doesn't need change. I actually assume now, that you alread also put a button on the same form, because that does only differ in picking a button instead of editbox and drag that into the form area.
To get to the click event you have several ways, one very simple, intuitive way is double click on the button. You get a white empty code window and it will be the click event of the button. That's displayed on top of the empty code window:
You could then run the form and have your first sucess experience.
It's not the worst idea to write more verbose code and also add more to the form as Scott has suggested. There are some things that are not ideal with my short oneliner code. One thing is that you can close the "save as" dialog, in which case the file name will be empty and the STRTOFILE() call will fail. So it is better to do things in multiple lines of code and be ablte to react to all the cases that can be exöpectged to happen. Well, that's actually describing how to think in programming, you alwayss have to go through all the major cases that could happen and think about them.
I don't know if programming is for you, but I don't want to curb your enthusiasm. Maybe it actually sparked just today, that you want to learn programming. Before you continue in VFP specifically, know this isn't a programming language with a bright future, it is a discontinued progtramming language. Also, I don't know if putting an editbox on a form you got the impression and idea, that programming VFP is just visual, dragging objects on design areas. The intuitive way of getting to the click event of a button by just clicking on it is nice, but doesn't work as intuitive and simple foir everything. If you double click on the empty area of the form, you end up with an editor Window of the Load() event of the form. That allows you to write code that runs first, but it's not the natural event to program, you better program something in the Init() of a form, because at that stage of a form all controls on it actuall will also be there when this code runs, while the form is empty when the code in the Load() event is execute.
And that's where things already become unintuitive, not as you'd expect it to work, because of cause you already put all the objects on the form when programming/designign the form, so why is the form empty when it runs? I'll not explain this right now. I just mention this as you need to understand one important thing: Nobody can protect you from getting stumped, not only because we explaiun things with a base knowledge in mind that you don't have yet, but because things are actually not intuitive before you know a bit of everything. Unfortunately no programming language is something you can learn in some path that's builds up knowledge in simple logical steps like learning a natural language or something like driving a car or skiiing. And you very well know learning to drive on the actual streets has some safeties for you as a learner like a driving instructor able to intervent with his own brake.
If you fear to do something wrong then better stop now. What you want in this special case is already programmed. The Notepad editor does that, and one step better it's done in Notepad++, where a new text you start writing is saved, even if you never actually gave it a name. Notepad++ even saves when the computer crashes and will restore the state it ended in with the next start. Texts are stored in tabs and where you never gave a file name, the tab captions will be "new 1", "new 2", , etc.
Also, there is something built into VFP, you can write a text and get back to it by date with a system window that's named 'calendar' and has, well, mainly a calendar on the left form side and an editobox which you can resize in width. If you go to a specific date what you wrote into that is restored. It's based in the idea Scott also sketched, it's store in a table in a memo field. Just into an already existing system dbf of VFP, soo all you need to get a form saving whatever you enter into an editobx per day is
Code:
Activate Window 'calendar'
It's actually also mentioned in the help of VFP, it's not a secret or easter egg of VFP.
Now, as a last step I'll tell you the second best way but also a more generally working way to switch bewtween the visual form design and the code behind all the objects: Move the mouse within the designer window to the white area outside the form and right click there, this will give you a popup context mewnu with one item "Code...", where you switch to some method or event of some objects. Depends on what is selected on the form or what you last edited.
Many people actually dislike this way, because there is no single overview code window with everything. But believe me, it actually forces you to concentrate on one specific thing, one event or method. Right above the code editing "editbox" you can select objects of the form or, at the root and as topmost element, the form itself, And the box right from the object allows you to switch between the methods and events.
I personally think it forces you to focus and concentrate on one thing you're concerned with. When you program what a button click should do, you don't need to see what code executes when the form starts, if at all.
There is a way to get an overview of all, but it's only for that aspect, you couldn't necessarily run that overall code also changing it won't change the individual methods or events of the form or objects on the form . If you don't like this concpet at all, then you better go for seomthing else, like HTML, but even in such a different "genre" of programming that's all on one, you get teached separation, for example defining the design decisions in CSS files and code in JS files and HTML files only concerned with the base HTML strcutrue that only gets it's final look with CSS.
If you seek for something completely visual, I think you won't find anything like that outside of introductory concepts like Scratch is for kids to teach programming in a visual way or like Logo was in earlier days for programming how a turtle walks. You won't be able to create fully fledged applications with such concepts, though.
I also actually thank you for pointing out that using ChatGPT to get some code can't replace all programming skills, even though Scott said: "If I had written this myself it would have taken hours to days for me to work out, not that I'm a VFP/WinAPI genius, but that's part of the point.".
If you're a novice in programming, you will not know what to do with a piece of code. And just like a single prompt will not give you the code for a full application, you also won't learn hopw to program in one question to a forum. So get used to having more questions than you started with, after learning one step towards your goal. That's not a problem, that's normal. Not only, if you are a beginner.
Chriss