A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Expression Builder: Convert STRING to INTEGER for Calculation???



 
 
Thread Tools Display Modes
  #1  
Old June 16th, 2005, 08:24 PM
cpr
external usenet poster
 
Posts: n/a
Default Expression Builder: Convert STRING to INTEGER for Calculation???

Thank you for your help!

I have three fields within a form: (1) an integer (currency), (2) an inputed
text from a combo box (the text is a payment frequency option: 'annually',
'biannually', 'quarterly', 'monthly'), and (3) an integer in which I wish to
display the result of a calculation taking the the currency integer in (1)
and dividing it by an integer in (2).

EXAMPLE: (1) has a user-inputed integer value of $12,000; (2) has a
user-inputed text value of 'quarterly'. I want (3) to calculate and display
the integer currency $3,000, which is (1) divided by the integer value '4'
(which is derived from the string value 'quarterly').

HOW DO I DO THIS? Can I convert a string value into an assigned integer
value for use in a calculation???

Please help! Thanks for your time!

Sincerely,
Clinton
  #2  
Old June 16th, 2005, 08:40 PM
Nick via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

One way to go about it is to use a Variant variable type:

Dim varTimePeriod as Variant

varTimePeriod = YourStringVariable

You can then use varTimePeriod as you would an integer value, which should
work, I played with it a bit. You can also put an error test in there, like:

If Not IsNumeric(varTimePeriod) Then
MsgBox "Please enter a numeric value."
Exit Sub
Else
End if


HTH,
Nick

--
Message posted via http://www.accessmonster.com
  #3  
Old June 17th, 2005, 05:14 AM
Dirk Goldgar
external usenet poster
 
Posts: n/a
Default

"cpr" wrote in message

Thank you for your help!

I have three fields within a form: (1) an integer (currency), (2) an
inputed text from a combo box (the text is a payment frequency
option: 'annually', 'biannually', 'quarterly', 'monthly'), and (3) an
integer in which I wish to display the result of a calculation taking
the the currency integer in (1) and dividing it by an integer in (2).

EXAMPLE: (1) has a user-inputed integer value of $12,000; (2) has a
user-inputed text value of 'quarterly'. I want (3) to calculate and
display the integer currency $3,000, which is (1) divided by the
integer value '4' (which is derived from the string value
'quarterly').

HOW DO I DO THIS? Can I convert a string value into an assigned
integer value for use in a calculation???

Please help! Thanks for your time!

Sincerely,
Clinton


Since you say the payment frequency comes from a combo box, the easiest
thing would be to use a hidden column of the combo box to hold the
divisor that goes with the text. Let your combo box get its data from a
table like this:

Table PaymentFrequencies
Field: PymtFreq (Text, primary key)
Field: PymtFreqDivisor (Number/Integer)

Fill the table with these rows:

annually, 1
biannually, 2
quarterly, 4
monthly, 12

Then set your combo box's properties to these:

Row Source: SELECT PymtFreq, PymtFreqDivisor
FROM PaymentFrequencies
ORDER BY PymtFreqDivisor;
Bound Column: 1
Column Count: 2
Column Widths: 1.5", 0"

Now you can set the Control Source property of the third text box to
something like this:

=[BaseAmount] / CInt([PaymentFrequency].[Column](1)

That's assuming "BaseAmount" is the name of your first text box, and
"PaymentFrequency" is the name of the combo box. Make the appropriate
name changes.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
print query in landscape dimwit General Discussion 15 May 25th, 2005 11:41 PM
expression builder erased my expression Stefano General Discussion 1 December 6th, 2004 10:17 PM
Concatenate a string to a integer Dave New Users 1 June 14th, 2004 01:01 AM
Convert grouped records into a string mmattson Running & Setting Up Queries 1 May 26th, 2004 07:04 PM
Reading a text string charachter by charachter....convert string to number ChuckM Worksheet Functions 2 December 30th, 2003 06:37 PM


All times are GMT +1. The time now is 03:48 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.