×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

how to get values from a notepad?
2

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

RE: how to get values from a notepad?

Can we assume that your "notepad file" is just an ordinary text file? If so, it is easy to read the contents into a VFP variable:

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?

(OP)
Got it Mike!!!! Thank you so much.... God bless,...

RE: how to get values from a notepad?

Problem solved, I see.

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

LOCAL loSMS
loSMS = NEWOBJECT('mySMS','\some\path\to\sms.prg')
* Now, after that class is instanciated as loSMS, the properties can be read out:
? loSMS.CommPort
? loSMS.nTimeOut 


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?

(OP)
Thank you Chris and Mike... I might have reacted to soon.... Mike is this correct.. it returned "varaiable not found" please help..
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?

Yes, Mandy, I can see that that won't work. That's because komport is not a variable; it is a property of the class.

But the following should be OK:

CODE -->

DEFINE CLASS mySMS as Container

nTimeOut = 10
CommPort = FILETOSTR("C:\comport.txt")

ENDDEFINE 


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 CommPort needs to be a numeric value, just reading in the file won't work.

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?

Chris is right. Any value that you read in with FILETOSTR() will be stored as a string - as the name of the function indicates. If your CommPort property expects a number (which it almost certainly does), you need to use the VAL() function to convert it.

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?

(OP)
Thanks Mike and Chriss… its working now… while taking note of all your tips… God bless…

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close