?
Solved

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

Posted on 2011-02-24
9
Medium Priority
?
450 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 1004 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 1004 total points
ID: 34976555
Yes, decimals would be retained. Val(7.55) = 7.55
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
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 664 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 1004 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 664 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 332 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
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…
Suggested Courses

765 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