AllExperts > Experts 
Search      

Visual Basic

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Visual Basic Answers
Question Library

Ask a question about Visual Basic
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Frank G. Dahncke
Expertise
I can answer most questions realating to real-world application programming in Visual Basic .NET (including SQL-Server 7.0 and up). I NO LONGER ANSWER VB6 QUESTIONS. My speciality is GUI/frontend work and API calls. I do not know about Internet, games or graphics programming, just the bread-and-butter stuff. I answer questions in German as well.

Experience
Experience: I have been programming BASIC applications professionally for 22 years now (2007), having done most any application type from multimedia CBT to telephone directories to database frontends. Organizations: RA-MICRO Software GmbH
 
   

You are here:  Experts > Computing/Technology > Basic > Visual Basic > problem in vb project

Topic: Visual Basic



Expert: Frank G. Dahncke
Date: 7/21/2008
Subject: problem in vb project

Question
i want to do some accounting calculations.
Private Sub TxtAmount_Change()
TxtPassed_payment.Text = TxtAmount.Text
TxtPresent_amount.Text = TxtAmount.Text
End Sub

Private Sub TxtPresent_amount_Change()
TxtBalance.Text = TxtAllotment.Text - TxtAmount.Text
End Sub

Answer
Your problem is that you try to calculate with variables that can only contain text (so-called "string variables"). To be able to calulate, convert text to numbers frist. A function that can help you do that is called Val. After the calculation, the resulting number must be converted to text string again, so you can assign it to a text variable. So, you Sub should look like this:

Private Sub TxtPresent_amount_Change()
TxtBalance.Text =CStr(Val(TxtAllotment.Text) - Val(TxtAmount.Text))
End Sub

If the string inside your .Text variables are not numbers, Val will calculate with a zero instead, so be sure that TxtAllotment.Text and TxtAmount.Text only contain digits, or you will get wrong results.

Yours,

Frank

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.