Solved

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

Posted on 2011-02-24
9
414 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
 
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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 119

Assisted Solution

by:Rey Obrero
Rey Obrero 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
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 developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now