I'm currently working on a project which acts in a similar fasion to the "Build Your Car Online" programs, only on one page. I want the program to access a sub procedure which adds values based on which set of option buttons were clicked (Each set (Color, Car, Two/Four Door) has their own frame). Whenever I click the command button however, I get an error message stating "Compile Error ByRef arguement type mismatch". Also, the values aren't adding up at the end of the program. I'm terrible at writing code so for all I know, this is nearly all wrong. Thanks for your time and help.

Private Sub Command1_Click()
Dim car, color, door As String, cost, cost1, cost2, cost3 As Single
Call showcost(color, cost1, cost2, car, door)

MsgBox "You have selected a " & color & door & car & "Costing: $" & cost1 + cost2 & "."

Public Sub showcost(color, car, door As String, cost1, cost2 As Single)

If optFocus.Value = True Then
  car = "Focus"
  cost1 = cost + 16500
 ElseIf optFusion.Value = True Then
   car = "Fusion"
   cost1 = cost + 16000
  ElseIf optTaurus.Value = True Then
    car = "Taurus"
    cost1 = cost + 15500
End If

If optRed.Value = True Then
    color = "Red, "
 ElseIf optBlue.Value = True Then
     color = "Blue, "
  ElseIf optBlack.Value = True Then
     color = "Black, "
   ElseIf optWhite.Value = True Then
       color = "White, "
End If
    
If optTWoDoor.Value = True Then
  door = "two door, "
 ElseIf optFourDoor.Value = True Then
  door = "four door, "

    
If chkHeat.Value = True Then
    cost2 = cost + 1000
ElseIf chkLeather.Value = True Then
    cost2 = cost + 600
End If

End Sub

    
End Sub

I figured out the error message but I still can't get the costs to add up in the output.

Well lets start with your declaration statement...

Dim car, color, door As String, cost, cost1, cost2, cost3 As Single

Just so you know, car, color, cost, cost1, cost2 are all varients while only door is a string and cost3 is a single.

Next off, since you are doing cost? = cost? + value and each of those cost's are declared within the click event, they will loose their value once the click event is exited.

Then, I'm not sure if you copied your code correctly but it looks like you have declares a sub proceedure within the click event proceedure....

The showcost sub should not be wrapped by the click event of the command button, it should be its own sub.

Good Luck

This article has been dead for over six months. Start a new discussion instead.