Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2006, 03:25 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default How to do Mathematical expressions (seriously)

Hi,
  The bold line is compound interest and the text5.text is an amount of money and needs to be times by 1.06 ^ 15 meaning 6% interest over a period of 15 years, how can it be done seeing as the line I put doesn't work!

        If Text5.Text > 500000 Then
          Text2.Text = Text5.Text * 1.03 ^ 30
             Text3.Text = Text5.Text * 0.03 ^ 30
        End If

also it would be nice to know how to do:
more then
less then
more then or equal
less then or equal

during if..then statements

cheers to anyone who can help


------------------------------------------------
Apocolypse2005
Always ready and waiting to help!
__________________
Apocolypse2005, I'm a programmer - of sorts.
 
Old December 11th, 2006, 06:02 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There are financial functions made available by vb6, such as Rate, FV (future value), IPmt, PV (present value), SLN, and others. You might check any of these out.

And the more/less/or equal:
more than: >
less than: <
more or equal: >=
less or equal <=

If 1 > 2 then
' Do something
elseif 3 <= 2 then
' Do something else
else
' You'll always end up here..
end if

note that you will want to use paranethesis to denote the precedence in complex calculations.


Woody Z
http://www.learntoprogramnow.com
 
Old December 11th, 2006, 06:31 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You have to convert the Text value into a number before doing any math, that is:

Text2.Text = CDbl(Text5.Text) * (1.03 ^ 3)

(CDbl automatically converts the string into a number using the current locale settings for decimal points)

Marco
 
Old December 11th, 2006, 08:21 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by marcostraf
 You have to convert the Text value into a number before doing any math, that is:

Text2.Text = CDbl(Text5.Text) * (1.03 ^ 3)

(CDbl automatically converts the string into a number using the current locale settings for decimal points)

Marco
This isn't strictly true, since VB6 coerces datatypes. Doing math on a string in all but a few cases will automatically cast the string to the appropriate numeric data type. However, it is important to validate the value in the string is actually a number before attempting to use it as a number.

Woody Z
http://www.learntoprogramnow.com
 
Old December 15th, 2006, 02:12 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

"more then" means either "more at that time" ("If he pays me tomorrow, I'll have more then than I do now.") or is synonymous with "Alright then: More!" ("I'm hungry, so give me more then!").
"Th[u]a</u>n" (with an "a") is a word denoting comparison.

I only mention this to assist searches you might undertake. You won't find a match if you use "then" instead of "than."
 
Old December 15th, 2006, 03:35 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by BrianWren
 "more then" means either "more at that time" ("If he pays me tomorrow, I'll have more then than I do now.") or is synonymous with "Alright then: More!" ("I'm hungry, so give me more then!").
"Th[u]a</u>n" (with an "a") is a word denoting comparison.

I only mention this to assist searches you might undertake. You won't find a match if you use "then" instead of "than."
This is very true. I have been seeing a lot of this lately where someone uses "then" when they mean "than", and vice versa.

Of course, that means that we have to search for both in case the person who has posted a solution is making the same error.

Then I'd rather use then than than when I mean then, then others will know the then I used then means then and not the than I didn't use then. But I'll use than when I mean than, then the than is better than then. That reminds me of that old wordplay about using that that that that that referred to...

Woody Z
http://www.learntoprogramnow.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
plsql mathematical function RatanKumar SQL Language 1 May 29th, 2008 09:04 AM
Regular expressions on C# hideway C# 2 November 27th, 2006 05:08 PM
Regular Expressions The_Iceman ASP.NET 2.0 Basics 0 September 29th, 2006 05:06 AM
SQL Expressions shazia1 Crystal Reports 0 June 15th, 2006 05:20 AM
I need some help in regular expressions! marwaesmat Perl 2 March 7th, 2006 05:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.