Ask Experts Questions for FREE Help!
Ask    ||    Answer
 
Advanced  
 

Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
Free Answers in 3 Easy Steps

Register Now
3 Steps

At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.

Home > Computers & Technology > Programming > Compiled Languages > Visual Basic   »   Something about Visual Basic.

 
Thread Tools Search this Thread Display Modes
Question
 
 
#1  
Old Sep 28, 2009, 05:55 AM
peter1988
New Member
peter1988 is offline
 
Join Date: Oct 2008
Posts: 5
peter1988 See this member's comment history on his/her Profile page.
Something about Visual Basic.

may anyone tell me how to do this calculation,the code into Visual Basic?
(Question)
if the user inputs 15 and 3, the first number is a multiple of the second. If the user inputs 2 and 4, the first number is not a multiple of the second.

Reply With Quote
 
     

Answers
 
 
Old Sep 28, 2009, 11:21 AM   #2  
Ultra Member
Perito is offline
 
Perito's Avatar
 
Join Date: Feb 2009
Location: USA
Posts: 2,865
Perito See this member's comment history on his/her Profile page.Perito See this member's comment history on his/her Profile page.
I'm not sure I understand the question.

Is this the question? how can I determine if the second number is an integral multiple of the first? If that is the question, this is how to do it (This is a VB6 program)

Dim FirstValue As Double
Dim SecondValue As Double

FirstValue = 15
SecondValue = 3

If (CInt(FirstValue / SecondValue) * SecondValue = FirstValue) Then
Call MsgBox("The second value is an integral multiple of the first", vbInformation)
Else
Call MsgBox("The second value is NOT an integral multiple of the first", vbInformation)
End If


You can also do it this way (using the "\" operator, the integral division operator).

If ((FirstValue \ SecondValue) * SecondValue = FirstValue) Then
Call MsgBox("The second value is an integral multiple of the first", vbInformation)
Else
Call MsgBox("The second value is NOT an integral multiple of the first", vbInformation)
End If


The key is the "CInt" or the integer division operator "\". Other languages have other functions to do the same thing (Trunc, Fix, IFIX, etc. VB has the FIX operator.) Basically, you throw away the fractional part (or the remainder). If you then multiply by the divisor, you should get back the original number. If you don't, it's not an integral multiple.

Note that VB is somewhat more forgiving than some other languages. In some languages. Round-off errors can make the IF statement fail incorrectly. In these cases, you would have to do something like this:

Dim TestValue as double
TestValue = ((FirestValue \ SecondValue) * SecondValue) - FirstValue

if ABS(TestValue) < 0.0000001 then
' The second value is an integral divisor
else
' The second value is NOT an integral divisor
end if
  Reply With Quote
 
     

Your Answer
Email me when someone replies to my answer
Join Login





Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

 
Similar Sponsors


Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page

Similar Threads
visual basic
(1 replies)
visual basic
(1 replies)
Visual Basic
(1 replies)
Visual basic dot net
(1 replies)
Visual basic
(1 replies)

Search this Thread

Advanced Search

Bookmarks

Sponsors



Copyright ©2003 - 2009, Ask Me Help Desk.
All times are GMT -8. The time now is 07:01 PM.