how to get values from a notepad?
how to get values from a notepad?
(OP)
Hi everyone... Good day.... I have here a code in my program... may i ask if can get the value of commport from a notepad file? If so, Can you teach me how? Thanks and God bless....
DEFINE CLASS mySMS as Container
nTimeOut = 10
CommPort = 9
code,,,,
code.....
endefine
DEFINE CLASS mySMS as Container
nTimeOut = 10
CommPort = 9
code,,,,
code.....
endefine
RE: how to get values from a notepad?
lcText = FILETOSTR("c:\data\myfile.txt")
(substituting the actual filename and path, of course).
Once you have the contents of the file in lcText, you will need to pick out the value of your comm port. How you do that will depend on exactly what text is contained in the file. If you can post a (small) sample, we should be able to advise further.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
RE: how to get values from a notepad?
RE: how to get values from a notepad?
If the "notepad file" is actually containing the DEFINE CLASS, well, that's a VFP code file, a PRG with VFP code of a class and you create an object of that to use it. Let's assume the file is sms.prg
These lines directly after DEFINE CLASS are class properties:
CODE --> sms.prg
DEFINE CLASS mySMS as Container nTimeOut = 10 CommPort = 9
For example it's possible to use NEWOBJECT or CREATEOBJECT with this and get at the properties this way
CODE
The alternative with CREATEOBJECT needs a SET PROCEDURE to the PRG file first, just the same as we teached you to use when using a function that's defined in a PRG. So anytime you have a PRG you can't simply DO as it only contains definitions of classes or functions, but even if it just is code you can call directly, it's never wrong to SET PROCEDURE to such a prg file.
I just wonder if that's relevant, as you talked of a "notepad" and not a PRG. A "notepad" actually isn't really a sensible term.
Anyway, in the case the part you posted after your question was the "notepad", it's code you should use as code and not as text.
Chriss
RE: how to get values from a notepad?
the comport notepad file contains number "5"
DEFINE CLASS mySMS as Container
komport = FILETOSTR("C:\comport.txt")
nTimeOut = 10
CommPort = komport
ENDDEFINE
RE: how to get values from a notepad?
But the following should be OK:
CODE -->
Alternatively, you could do it like this:
CODE -->
DEFINE CLASS mySMS as Container komport = FILETOSTR("C:\comport.txt") nTimeOut = 10 CommPort = this.komport ENDDEFINE
Give it a try.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
RE: how to get values from a notepad?
If you really have a comport.txt file containing only a 5, this still is a string read in by FILETOSTR(), as the name of the function tells, it reads a file to a string variable. There are much better ways to store configuration values, for example as you use VFP a DBF. Sure, a DBF with a numeric field storing a 5 would be much larger than the single byte txt file, but it's obviously not the end of what configuration values can be in data.
Another very old school way is the INI format, it's easy to maintain, as it's just a text file, too, and therefore still in use in many cases, though today many configurations are stored into XML files, still also text, but not very maintenance friendly for just using an editor. But there are also many new tools that format XML for easier handling.
I'd consider moving away from the single number in a text file, to anything else, but for the moment you'd need VAL(FILETOSTR("comport.txt")) as your comport number.
Chriss
RE: how to get values from a notepad?
Sorry I didn't spot that earlier.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
RE: how to get values from a notepad?