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!

field is numeric and data contain string

Status
Not open for further replies.

mnaushadali

Programmer
Apr 14, 2014
8
SA
Dears

I have a DBF file that file have field is numeric and data contain string (Character). How to Handle for variable.

Regards
Naushad
 
Perhaps I did not fully understand.

Have you done a DISP STRU on the table to make absolutely certain that the field is NUMERIC - instead of merely being a Character field containing Number CHARACTERS (such as the characters "123456")?

If the field is actually Character and you need your application to work with the Numbers that are represented, then you can use the VAL() function to convert the characters to numbers.

Good Luck,
JRB-Bldr
 
Like jrbbldr, I am confused.

A numeric field cannot ever contain a string, so your question confuses us.

Are you sure, as jrbbldr has noted, that you don't have a character field that contains characters that LOOK like numbers but in fact are strings?

Either DISPLAY STRUCTURE or use TYPE() to verify what type of fields that you have.

You could also cut and paste some code that shows us what you are trying to do and shows us where your problem lies.

mmerlinn


Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond
 
This file is Visual FoxPro File, I have checked by Display Structure on the command prompt and Field type is Numeric.

Regards
Naushad
 
Hi Naushad,

Welcome to the forum. As you have seen, there are plenty of people here who are anxious to help you. But you will have to give us some more information. You say that the field is numeric and that it contains a string. That doesn't make sense. It can either be numeric or character data, but not both at the same time.

Also, it's not clear exactly what you are asking. What exactly is the problem?

It would be better if you could post some code that shows how you created the file.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I am trying to give command MyBranch=transform(numericfield) and other is nLength = 10
nDP=2 , MyBranch=Alltrim(Str(numericfield,nLength, nDP)and got Result Zero.

Regards
Naushad
 
Dear Naushad,

Please have a look at TRANSFORM() function in the helpfile

e.g.
nField = 123456.78
?Transform(nField, "999,999.99")
returns character string "123,456.78" depending on settings of SET POINT and SET SEPARATOR

nField = 6175551212
?Transform(nField, "@R (999) 999-999")
returns character string "(617) 555-1212"

hth

MarK
 
What is the numericfield itself in the case you get an unexpected result from either TRANSFORM() and/or STR()?
NULL is a value to consider, eg.

Also you always will get 0, if at EOF() of the DBF. GO TOP or to the record you need.

Bye, Olaf.
 
The Result Should be Alphabet because of Data stored in Alphabet. like "MY BRANCH
 
I'll try to put my questions more direct:

? numericfield
What does that display?

? SET("NULLDISPLAY")
What does that display?

? ISNULL(numericfield)
What does that display?

BROWSE
What is displayed in the browse window?

Bye, Olaf.
 
>The Result Should be Alphabet because of Data stored in Alphabet. like "MY BRANCH"
What are you talking about?

You showed code using a variable named MyBranch earlier. Variable are names, right, that's valid for all variables, no matter what type.
? MyBranch will show the value of MyBranch, not the variable name. Why do you expect to see "MY BRANCH" as a result? Of what? What is your real problem?

Bye, Olaf.
 
The Result details is below as i got.

? deprtid
Result Display = 0

? SET("NULLDISPLAY")
Result Display = .NULL.

? ISNULL(deprtid)
Result Display = .F.

BROWSE FIELD deprtid
Result Display = MABDAH LAB

Note : When I PUT Cursor Point in field DEprtid then Result Show = 0 then go Down on next Record then Show MABDAH LAB
 
A variable is not a field.

So you have a variable with the same name as a field, then the field value get's displayed, if you display MyBranch.
You don't browse a variable, you browse data.

Your field is named numericfield, isn't it?

Here's a short demo of what might happen:
Code:
Create Cursor curData (numericfield N(10,2) DEFAULT 0.0, MyBranch C(10) DEFAULT "MABDAH LAB")
Append Blank
MyBranch = numericfield
? MyBranch, m.MyBranch


MyBranch will display the field value, m.MyBranch will display the variable value.

If you BROWSE, as I asked you, without FIELDS clause, you'll see the numericfield contains the 0.0, it doesn't contain the string, that's in the MyBranch field.

You have a field and a variable with the same name. What happens, if you address the name? You get the field value, not the variable value.

Bye, Olaf.
 

Below as I have given example from this hints not possible to solve ?

After Brows When I PUT Cursor Point in the field Deprtid then Result Show = 0 after that wehn go Down on next Record then Up Record Show MABDAH LAB.

? deprtid
Result Display = 0

? SET("NULLDISPLAY")
Result Display = .NULL.

? ISNULL(deprtid)
Result Display = .F.

BROWSE FIELD deprtid
Result Display = MABDAH LAB
 
I asked you for BROWSE (browsing the whole table) not BROWSE FIELD.
Try BROWSE NOCAP NORMAL, but don't BROWSE a FIELD, this'll not show you a variable, you don't browse variables.

I also already showed what's causing the effect you see.

Bye, Olaf.
 
If something solved your problem, great. Otherwise I think nobody can really help you.

You can try some standard solutions, eg delete foxuser.dbf. It's storing info about the last time you browsed a table, eg switched columns, calculated fields, etc. BROWSE NORMAL will not look into foxuser BROWSE LAST will. Double clicking a workare in the datasession window causes BROWSE LAST, not BROWSE NORMAL. NOCAP will just show you the real field names, not field captions. That may also be a reason to confuse columns with something they are not. So BROWSE NORMAL NOCAP will give you the core browse view on a table as it is in physical order of fields, field names as they are.

If you work a lot with BROWSE in your applications, you better start using grids, because BRWOSE has some bugs.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top