Solved

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

Posted on 2011-02-24
9
403 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
Comment Utility
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
Comment Utility
is it valid for decimal numbers also (example: 7.55)
0
 
LVL 12

Assisted Solution

by:geowrian
geowrian earned 251 total points
Comment Utility
Yes, decimals would be retained. Val(7.55) = 7.55
0
 
LVL 6

Author Comment

by:anushahanna
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Access MVP)
DatabaseMX (Joe Anderson - Access MVP) earned 166 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
very helpful - many thanks for the examples!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 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

11 Experts available now in Live!

Get 1:1 Help Now