Solved

Val(FldData(1)) vs FldData(1)

Posted on 2011-02-24
9
442 Views
Last Modified: 2012-05-11
when reading from a text file, what will the difference between the 2 formats above?

FldData(1) would point to 1st column in the csv file.
!ColName = Val(FldData(1))
or
!ColName = FldData(1)
thanks
0
Comment
Question by:anushahanna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 12

Accepted Solution

by:
geowrian earned 251 total points
ID: 34976521
The Val() function returns the numbers in the passed argument. See:
http://www.techonthenet.com/access/functions/numeric/val.php

Basically, if you have a number in the 1st column of the CSV file, it won't make a difference. If you have text in it, it will return the numbers int the text.
0
 
LVL 6

Author Comment

by:anushahanna
ID: 34976550
is it valid for decimal numbers also (example: 7.55)
0
 
LVL 12

Assisted Solution

by:geowrian
geowrian earned 251 total points
ID: 34976555
Yes, decimals would be retained. Val(7.55) = 7.55
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Author Comment

by:anushahanna
ID: 34976618
if col one is 7.55,
Val(FldData(1)) is same as FldData(1)? (val does not make difference in this example)

val is really useful only if reading from text columns that have numerical values?
0
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 166 total points
ID: 34976900
There are some nuances with Val() that you should be aware, which is why I'm pasting the Help file info on Val().
= = = = =
Returns the numbers contained in a string as a numeric value of appropriate type.

Syntax

Val(string)

The required string argument is any valid string expression.

Remarks

The Val function stops reading the string at the first character it can't recognize as part of a number. Symbols and characters that are often considered parts of numeric values, such as dollar signs and commas, are not recognized. However, the function recognizes the radix prefixes &O (for octal) and &H (for hexadecimal). Blanks, tabs, and linefeed characters are stripped from the argument.

The following returns the value 1615198:

Val("    1615 198th Street N.E.")

In the code below, Val returns the decimal value -1 for the hexadecimal value shown:

Val("&HFFFF")

Note   The Val function recognizes only the period (.) as a valid decimal separator. When different decimal separators are used, as in international applications, use CDbl instead to convert a string to a number.

Val Function Example
This example uses the Val function to return the numbers contained in a string.

Dim MyValue
MyValue = Val("2457")    ' Returns 2457.
MyValue = Val(" 2 45 7")    ' Returns 2457.
MyValue = Val("24 and 57")    ' Returns 24.

= = = =
0
 
LVL 12

Assisted Solution

by:geowrian
geowrian earned 251 total points
ID: 34976901
That is correct if you are storing the result as a string. If you were assigning the value to a numeric object (i.e. an Integer variable or numeric column), then Val() would be required since it returns a number.

For instance, assume FldData(1) stores "7.55":
FldData(1) returns "7.55" (note the quotes to indicate it is a string - the quotes themselves are not stored)
Val(FldData(1)) returns 7.55 (a number)

One thing to note is that Val() always returns a number. For instance Val("Test") returns 0 since there is nothing numeric.
0
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 166 total points
ID: 34976912
One other issue with Val() ... it will *not* return leading zeros in a String:

Val("001234")
returns 1234

mx
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 83 total points
ID: 34976949
the Val function
*Returns the numbers contained in a string as a numeric value of appropriate type.
*Symbols and characters that are often considered parts of numeric values, such as dollar signs and commas, are not recognized. However, the function recognizes the radix prefixes &O (for octal) and &H (for hexadecimal). Blanks, tabs, and linefeed characters are stripped from the argument.


* recognizes only the period (.) as a valid decimal separator.
val(123.45) returns 123.45

* stops converting at the first character that cannot be interpreted as a numeric digit, numeric modifier, numeric punctuation, or white space.

Val(" 2315 208th Street S.E.")  returns  2315208
val( "1 3 78 9")  returns 13789
val("25 and 27") returns 25



0
 
LVL 6

Author Comment

by:anushahanna
ID: 34985687
very helpful - many thanks for the examples!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question