I'm going to be needing some Visual Basic help

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.

Thanks very much!

I’d be willing to help, although I don’t get the time to do as much straight programming as I’d like to. My e-mail address is in my profile.

CJ

Thanks Siege. Do you have AIM?

I’m afraid not, but I do have a working telephone, and some experience talking people through things.

I’m probably as rusty as you are with VB, but I’m willing to give it a go. You using .NET or VB6?

If you post snippets here, remember the “code” vBulletin function.

-David
email: soulfrost@innocent.com
AIM: soulfrost

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:



a:
     MsgBox("30MI", vbOKOnly, "stuff")
b: 
     MsgBox("30core", vbOKCancel, "stuff")


Oh, and one more thing…

on my first code block, you need to add a


 End Select

at the end of the select statement.

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.

-David

Hmmm… not only did I post late, but I put equal signs where equal signs ought not go…

Bad Dave!

-David

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.

Thanks again everyone :).

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:

Call MsgBox(“30core”, vbOKCancel, “stuff”)
MsgBox “30core”, vbOKCancel, “stuff”

My personal preference is to always use the “Call” form so things look consistent whether or not you are interested in the return value:

Call MsgBox(“30core”, vbOKCancel, “stuff”)
If (MsgBox(“30core”, vbOKCancel, “stuff”) = vbOk) Then

I’m a developer by trade and I use VB most of the time at work so I’ll keep an eye on the thread and help when I can. =)

I have 3 full pages of variables like this:

That I need to program into this calculator.

My friend is telling me to input them all into an Access database and link to it from VB. Does this sound like a smart idea? If so, how hard is it?

I took and aced an Access class a couple years ago so I’ll be fine with that side of it.

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.

Are you asking if these variables are going to be changing, Parallax?

If so, I don’t think so.

Like I said though, I have literally 3 pages (small font) of rate changes to plug into this thing.

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?

Thanks! =)