Solved

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

Posted on 2011-02-24
9
427 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
  • 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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 - Access MVP)
DatabaseMX (Joe Anderson - Access MVP) 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 - Access MVP)
DatabaseMX (Joe Anderson - Access MVP) 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

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
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

773 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