English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am creating a monthly payment calculator using Visual Basic 6 and I need a variable to represent the equation used to find the monthly interest. How do I declare my variable so that I can substitute it into the full equation for the payments.
I know that if I were using BASIC I would go
interest=(txtinterest.text * .01)/12)
and then substitute the variable interest into the whole equation, but this doesn't seem to work.
please help me...

2007-04-10 10:53:31 · 5 answers · asked by Anonymous in Computers & Internet Programming & Design

5 answers

You would create a function which will accept data and return a computed value. A function is a subroutine which returns a value and may be located in a form, module or class.

If you create a function in a module it will be available to the entire program (global) and it is easier to reuse a module in another program.

THe code:

Public function myInterest( value as Double) as Double
dim x as double

x = (value * .01)/12
return x
ENd Function

to use your function

interest = myInterest( "your number goes here")


I do recommend that you not use values directly from a text box as in (txtInterest.text * .01)/12

rather you should first validate the text entry then copy the data into a variable of the proper type by performing data type conversion. Validation can be done in the validating and validated events.

dim myData as double

myData = Val(txtInterest.text) ' convert a string into a double

interest = myInterest(myData)

2007-04-10 15:01:24 · answer #1 · answered by MarkG 7 · 0 0

DIM myVariable as float

(or int or whatever)
Do yourself a favor and learn a real language like C# or Java.

(DIM - comes from "dimension" which has no meaning anymore... it's a relic from the old days, and a completely unsuitable term for declaring a variable.)

In SQL, you say "declare"... I declare, that makes a lot more sense.

And no, you would use the "text" property of anything... you want a number, not a string. Visual Basic lets you be lazy and it will automatically convert that string to a number, but that allows the user to type something like "eighteen percent" which can not be converted to a number, causing your program to crash because of user input, which is a very bad thing. Weak typing is a very bad thing actually, and VB is the single biggest source of bad code in the world, mostly for that reason.

2007-04-10 11:02:34 · answer #2 · answered by polly_peptide 5 · 0 0

Here is how to create and open a text file for writing. This example only write a single line but you would loop through an array of data or read values from a module into a string for saving. Private Sub Command1_Click() 'add reference to Microsoft Scripting Runtime [Project > References] Dim f As File Dim fso As FileSystemObject Dim ts As TextStream Dim myFileName As String Dim strData As String ' myFileName = "C:\myTestFile.txt" ' Set fso = New FileSystemObject 'Create the file fso.CreateTextFile (myFileName) ' Set f = fso.GetFile(myFileName) 'Open for writting Set ts = f.OpenAsTextStream(ForWriting, TristateFalse) ' strData = "Hello World" ' ts.WriteLine (strData) ' ts.Close 'close file and do some housekeeping Set f = Nothing Set fso = Nothing End Sub

2016-04-01 07:45:58 · answer #3 · answered by Anonymous · 0 0

example of variable declaration:

Dim interest As Integer
Dim name As String
Dim flag As Boolean
Dim variable1 As Byte
Dim variable2 As Currency
Dim variable3 As Double
so on....

i dont think there's a float type in vb6

good luck

2007-04-10 13:08:59 · answer #4 · answered by farina m 4 · 0 0

i dont think u have to declare var. in vb. its just a nice way to show them

2007-04-10 11:15:55 · answer #5 · answered by MoooMoo 2 · 0 0

fedest.com, questions and answers