My big mouth may have gotten me in a little bit of trouble. I told my friend I would make a little program for him and only now that I’ve started do I realize how extremely rusty I am in VB.
The program is very simple and shouldn’t take more than a couple of hours once I get back into the groove of things (it’s basically a specialized calculator.)
If anyone is willing to help please post here and we can get in touch through email or AIM or possibly over the phone.
I have VB installed and I still use it from time to time (VB 5.0). Email me if you need any help with it. Always glad to help a fellow Doper out. I don’t have AIM, but I do have MSN and Yahoo! messegers.
Thanks guys. Right from the start I’ve had problems. What I’m trying to make is a simple mortgage rate calculator.
The code I started out with is laughably bad to you guys, but it makes sense to a guy who hasn’t programmed since around 1997.
I’m trying to work with a combo box.
Private Sub Command1_Click()
If Combo1.Text = "30MI" Then GoTo a
If Combo1.Text = "30CORE" Then GoTo b
If Combo1.Text = "HQC" Then GoTo c Else GoTo d
a = MsgBox("30MI", vbOKOnly, "stuff")
b = MsgBox("30core", vbOKCancel, "stuff")
c = MsgBox("HQC", vbYesNo, "stuff")
d = MsgBox("Please select a valid loan program", vbOKOnly, "Error")
End Sub
Private Sub Form_Load()
Combo1.AddItem "30MI PP"
Combo1.AddItem "30CORE"
Combo1.AddItem "HQC"
End Sub
I’ve got VB6 at home, and do a fair amount of VB6 coding at work. My email’s in my profile, I’ll try to help you out if I can. Unfortunately, I will probably be a bit hard-to-reach for the next few days.
At first blush, it looks ok. What happens when you actually run it? I can stare at a bit of code all day and not see a problem with it. Then I run it, get an error or some weird output and immediately know what the problem is.
The only thing I see this far is the discrepancy between “30MI” and “30MI PP” but that’s not it.
Ok, first of all… goto is bad. Stay away from it if you can.
I’d do something like this:
Select Case Combo1.text
Case "30MI"
MsgBox("30MI", vbOKOnly, "stuff")
Case "30CORE"
MsgBox("30core", vbOKCancel, "stuff")
Case "HQC"
MsgBox("HQC", vbYesNo, "stuff")
Case Else
MsgBox("Please select a valid loan program", vbOKOnly, "Error")
If you’d prefer to use Goto, the statemets should look like this:
The first thing I would do, personally, is to change the structure of the code. Maybe separate functions named 30MI, 30CORE, HQC, and OOPS (makes it easier to edit later when the inevitable changes need to be made and you’ve long forgotten what you coded.)
Also, instead of the IF…THEN statements, a SELECT…CASE statement is much cleaner.
Something like this, maybe:
Private Sub Command1_Click()
Select Case Combo1.Text
Case = "30MI"
'call function 30MI
30MI
Case = "30CORE"
'call function 30CORE
30CORE
Case = "HQC"
'call function HQC
HQC
Case Else
'display error message
OOPS
End Select
Your functions would display the dialogs you’ve already specified as well as do any math routines you may need to set up.
Thanks a ton guys. This would all be much easier if my books and CDs weren’t all 2,000 miles away but it’s slowly coming back to me.
Jweb, your code looks like a giant step in the right direction but it’s still returning an unspecified syntax error. It looks like it has a problem with the MsgBox lines.
Yeah, my books are all at work too, don’t worry about it.
My guess is that you’re getting MsgBox syntax errors because you’re displaying the MsgBox with two button choices, ie: MsgBox(“text”, vbOkCancel, “text”)
The MsgBox function is trying to retun which button was pressed, Ok or Cancel. So try something like this:
Case "30CORE"
if vbOk = MsgBox("30core", vbOKCancel, "stuff") then
'do something
else
'do something else
end if
I don’t think you have to do this if your MsgBox is set for vbOkOnly though.
And I second SoulFrost’s idea of separating the functions.
VB is a bit strange about the use of parentheses when passing parameters to functions. There are different syntax rules depending on whether you are passing one parameter or multiple parameters.
For one parameter you can do one of the following:
MsgBox(“Test”)
Call MsgBox(“Test”)
MsgBox “Test”
For multiple parameters the first form is not allowed - leaving one of the following:
Is this just a one-shot thing to load the program with initial data or something that will need to be done all the time? It could be overkill if you only have to do it once - but it sounds like something that will happen all the time?
It should be fairly straightforward to either get data from an Access database using VB or to link to a running instance of Access to get the data.
The main problem is that I’m not really sure how you will be using this data. It almost looks like these are calculations that you need to perform in order to calculate the mortgage? If so then it seems like you need something that can convert the data into VB code - you could probably write an Access macro to do some of the work.
I’m probably way off track though since I don’t really know what you are trying to do. Can you explain it a bit better?