Newbie Dummy

TKulak
10-19-2009, 04:30 PM
Hello, I am in a Visual Basic programming class (beginner), and I am lost. I have to write a program and I think it uses If/Else statements. If anyone can help me with what I have already or point me in the right direction I can scan my parameters and email them to you.

Thanks in advance. I am not asking for you to do it, I just need a jump start!

vb5prgrmr
10-19-2009, 10:03 PM
Well,....

If you_post_your_code = True Then
we_can_help_you = True
Else
there_is_nothing_we_can_do = True
End If



Good Luck

TKulak
10-19-2009, 10:05 PM
This is what I have so far and it doesn't work. Trying to get a calculation but cant get result.

Option Explicit
Dim intSales As Single
Dim intCommission As String

Private Sub cmdCalculate_Click()

intSales = Val(txtSales.Text)
lblResult = intCommission

'Calculate Commission
If intSales >= 0 < 99999 Then
intCommission = intSales * 0
ElseIf intSales >= 100000 < 200000 Then
intCommission = (intSales * 0.01)
ElseIf intSales >= 200001 < 300000 Then
intCommission = (intSales * 0.015)
ElseIf intSales >= 300001 < 400000 Then
intCommission = (intSales * 0.0175)
ElseIf intSales >= 400001 Then
intCommission = (intSales * 0.02)
End If

End Sub


Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdPrint_Click()
PrintForm
cmdClear.SetFocus
End Sub

vb5prgrmr
10-19-2009, 10:41 PM
Okay, intCommission should be a double and not a string or you should...

intCommission = CStr(intSales * 0.02)


and it looks like your if elseif is working correctly but I do not see where you display the value... Ah!!! I see....

lblResult.Caption = intCommission

should be after your if elseif calculation section...



Good Luck

TKulak
10-19-2009, 10:45 PM
I still get zero for my Commission no matter what I do even with the corrections.

Option Explicit
Dim intSales As Single
Dim intCommission As Double

Private Sub cmdCalculate_Click()

intSales = Val(txtSales.Text)

'Calculate Commission
If intSales >= 0 < 99999 Then
intCommission = intSales * 0
ElseIf intSales >= 100000 < 200000 Then
intCommission = (intSales * 0.01)
ElseIf intSales >= 200001 < 300000 Then
intCommission = (intSales * 0.015)
ElseIf intSales >= 300001 < 400000 Then
intCommission = (intSales * 0.0175)
ElseIf intSales >= 400001 Then
intCommission = (intSales * 0.02)
End If

lblResult = intCommission

End Sub


Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdPrint_Click()
PrintForm
cmdClear.SetFocus
End Sub

ZaCkOX
10-20-2009, 02:04 AM
You need to make the "IF THEN END IF" statements readable for my eyeS!!! Ah my eyes!!


Option Explicit

'Declares
Dim dblSales As Double
Dim dblCommission As Double

Private Sub cmdCalculate_Click()

'Announce
dblSales = CDbl(txtSales.Text)

'Calculate Commission
If dblSales >= 0 < 99999 Then
dblCommission = dblSales * 0
ElseIf dblSales >= 100000 < 200000 Then
dblCommission = (dblSales * 0.01)
ElseIf dblSales >= 200001 < 300000 Then
dblCommission = (dblSales * 0.015)
ElseIf dblSales >= 300001 < 400000 Then
dblCommission = (dblSales * 0.0175)
ElseIf dblSales >= 400001 Then
dblCommission = (dblSales * 0.02)
End If

'Return The Answer In A Label
lblResult.Caption = dblCommission 'This Label Will Auto convert To String For Displaying Your Answer

End Sub

Private Sub cmdExit_Click()

'Leave Program
End

End Sub

Private Sub cmdPrint_Click()

'Print And Move Focus
PrintForm
cmdClear.SetFocus

End Sub



You usually want to indent or space the bottom code if it applies to the top. It helps make it a little easier to read. You can even re-indent and more but this is a little easier for me. Also, you have intCommission, intSales... those should be integers if you have int in front. Otherwise change to dblSales, dblCommission. Hope that helps....

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum