VB Help should be simple for someone that knows

Associate
Joined
22 May 2004
Posts
1,792
Location
N.Ireland
Hi guys am doing an assigment for tech and am trying to do this
Code:
Public Class Simple

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        'Declare local Variable
        Dim dblInterest, dblInvested, dblYears As Double
        Dim dblInterestEarned, dblTotal As Double

        'Input Values from User
        dblInterest = Val(Me.txtInterest.Text)
        dblInvested = Val(Me.txtAmount.Text)
        dblYears = Val(Me.txtYears.Text)

        'Perform Calculations based upon input Values
        dblInterestEarned = dblInvested * dblInterest * dblYears / 100
        dblTotal = dblInterestEarned + dblInvested

        'Output results to Form
        Me.txtInterestEarned = Cstr(dblInterestEarned)
        Me.txtAmountEarned = Cstr(dblTotal)

    End Sub
End Class

But the program is showing up an error Error Value of type 'String' cannot be converted to 'System.Windows.Forms.TextBox'.

Anyone know why the calulation wont go to the text boxes? Help please Please please LOL :)

Gareth
 
Looks like you're trying to assign the string directly to the variable that represents the control, rather than to the Text property of the control. Try this:
Code:
Me.txtInterestEarned[B].Text[/B] = Cstr(dblInterestEarned)
Me.txtAmountEarned[B].Text[/B] = Cstr(dblTotal)
 
What line is the error coming from?

It is, however, probably due to you trying to assign the value to the textbox rather than the text property. So it should be textbox.text.

Possibly...


Edit: Beaten : (
 
Hi guys one more stupid question. Have worked out simple interest but am now tring to work out compound interest

IT is

A = P*(1+R/100)^T

where P is the principil (Amount invested
R is the Annual rate of interest
T is the total period of investment in years
A is the amount that the principal becomes after T years

How would I get basic to do this?
 
Thanks dude. Ill read that and sort it out. If I up this as a zip file can someone check why when it should go from Splash Screen-Password screen(Password is 12345) to the maian menu.. Different screens keep popping up.

If I zip it and upload it can anyone check to see why?

Its uploaded to here http://rapidshare.com/files/113513220/BmcBank.zip.html

Gareth
 
Last edited:
Just had a quick look at it and the reason the form keep popping up is that the timer remains running on the splash screen form and when the tick event fires it shows the password form.

You should be aware that even though you hide the form the actual form object still exists in memory and will keep running as normal, such as the timer event firing.

To be honest this is one of the nasty things about VB. In VB.NET 2005 they introduced the 'My' namespace.

This is what allows you to simply do things like frmPassword.Show() when you haven't explicitly created a variable to hold a frmPassword object.
The actual forms in your application are held as variables in the My.Forms namespace.
When you call frmPassword.Show() it's actually doing My.Forms.frmPassword.Show() and using the variable it's created there.

If you're reasonably new to VB.NET (which I suspect you are) you lose sight of the fact that it's actually an object on which you're calling the .Show() method and can get unwanted behaviour such as you're seeing here.
 
The simplest solution is to just disable the time the first time the event fires by putting a ExitTimer.Enabled = False in the tick event handler.

I would have a look at how your application fits together though.
Currently you have 5 forms that are simply hidden and shown as appropriate.
These 5 forms will reside in memory for the length of your application - it would be better if you had one form that is the master and then you can let that form create and destroy the other forms as needed.

Have you done any VB6 before this by the way?
Your code strikes me as something that might have been done by someone that knows VB6.
 
Nah this is the first VB I have done. I am working off tecaher notes and some java knowledge. So pretty Lost at times. Thanks for all your imput... I take it you work with programming?
 
Just had a quick scan through your code and judging from the way it is organised you might also want to consider invoking your main application forms as modal rather than modeless i.e. calling ShowDialog() rather than Show() and Hide().

...though I prefer C# :)
Same here :)
 
Last edited:
Back
Top Bottom