Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error storing text box data into a variable

Status
Not open for further replies.

HAINC

IS-IT--Management
Mar 10, 2011
8
US
Yes I am new to Visual fox pro. I'm using VFP 7 I am trying to convert an old clipper program.

I am having trouble with my form: Basically I have 2 buttons, first a text box for the user to enter a upc and the seccond is a command box with the following code:

store RIGHT('0000000000000'+LTRIM(RTRIM(STR(text1))),13) to xtemp
sEEK xtemp
thisform.Refresh


When I run my form I enter my upc in text1 box click on command button that runs the code above and I get an error that says Variable text1 not found.

I thought when you entered data into a text box it was stored as a variable named the name of the text box.
 
I thought when you entered data into a text box it was stored as a variable named the name of the text box.

No, that's not right. The value that you enter is stored in a property of the textbox object. The property is named Value.

So, if the textbox is named Text1, then you access the value by reference to THISFORM.Text1.Value.

Also, the value is normally stored as a string, not a number (unless you had initialised the textbox with a numeric value). So, normally, you don't need to use STR() to convert it.

You can also simplify your code a bit further: (i) combine LTRIM() and RTRIM() into a single function, ALLTRIM(); and (ii) use PADL() to get those leading zeros. So, instead of this

store RIGHT('0000000000000'+LTRIM(RTRIM(STR(text1))),13) to xtemp

you could do this:

store PADL(ALLTRIM(Thisforml.text1.Value),13,"0") to xtemp

Mike






__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
store PADL(ALLTRIM(Thisforml.text1.Value),13,"0") to xtemp

Almost. Mike already pointed out the textbox value might also be num,eric, if initialised as a numeric value, then Alltrim would fail, as it only works for string types.

I suggest you set the Textbox Format: R, Inputmask: 9999999999999 and MaxLength=13 should be sufficient. If you use a barcode scanner to enter UPC codes, leading zeros are also entered and don't need to be added.

Bye, Olaf.

 
Also: In the When() event empty the textbox value, in the Valid() event check the upc code for validity.

You may use preamble or postamble code in barcode scanner programming, eg a preamble of a function key or any other hotkey could be used to set focus to the textbox, if you react to this hotkey in the form keypress event or ON KEY hotkey _screen.activeform.txtUPC.setfocus() or somthing similar.

With SET CONFIRM OFF the full barcode will trigger the valid event, with SET CONFIRM ON you will need an ENTER to get into the textbox valid, either the user needs to scan and ENTER or you program a postamble code in your barcode scanner to send ENTER.

I rather prefer barcode scanners to not do anything else but send the barcode digits, no final ENTER. a Preamble hotkey can help, especially if it's a function key having no effect whatsoever in other applications working with the same barcode scanners, unless they do program special handling. The function key itself does not enter anything into a textbox, at least.

Bye, Olaf.
 
I will add that you might want to consider moving away from the OLD FP syntax.

Instead of:
Code:
store PADL(ALLTRIM(Thisforml.text1.Value),13,"0") to xtemp
you could use:
Code:
xtemp = PADL(ALLTRIM(Thisforml.text1.Value),13,"0")

Good Luck,
JRB-Bldr
 
I'll mildly disagree about the "oldness" of STORE. Both approaches are still perfectly valid. In fact, STORE allows you to populate multiple variables in a single command which direct assignment does not.

I'm in favor of casting off the old but only where there's a clear benefit and I don't see one in this example.
 
Well, an advantage of '=' vs 'store' is it's universal syntax. If you program in many languages it's better to use common syntax. Also if at any time somebody needs to replace you as a developer, the more usual the syntax is you use in your source code, the easier to gripe the meaning of the code for someone else.

That said, there's something else you can do with store: STORE value to (cNameExpression), while you can't do (cNameexpression) = value, you will need to do makrosubstitution &lcVariableContainingName = value, which is taking longer than name expression, but for the single assignments you do, even if you use multiple (cNameExpressions), that's not giving much of an advantage, it'll not make the code any more portable to other languages, than with macro substitution.

I also do avoid BETWEEN() in SQL, as there is the SQL BETWEEN clause, LIKE(), as there is the LIKE clause and some more. You can really avoid some of the VFP functions and commands in favour of more common syntax, having a few things less to explain to somebody new to Foxpro. And in my developer live there have been 4 collegues coming and going, and it wasn't a turbo in letting them understand my source code faster, but it was a few things less to explain.

Bye, Olaf.


 
Thank you all very much for your help.

I am having another problem with my form/program When I click on the button that does the seek I get a popup that says table has no index or order set.

The form opens my table but does not open the index. I have tried the following:

In the main.prg just before do the form I open the table and index

On the form itself on the init procedure i use master index master.cdx

I'm just not sure where or how i'm supposed to open the cdx. I thought that a table has a cdx the cdx was opened as soon as the table was opened.

 
That's an entirely new question and deserves an entirely new thread.

But don't confuse opening an index with setting an order. A structural CDX is indeed opened when a DBF is opened, but a CDX can contain many indexes (most do), and an index order needs to be set with SET ORDER.

There's also a much larger discussion this opens about using data environments and more important PRIVATE data environments, but again it's a subject for a new thread.
 
Sorry Dan that should be a new post. Thank you for your quick response. I did have the index and set order confused.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top