VB Whats up with this code?

Charlie

Board Regular
Joined
Mar 1, 2002
Messages
134
I coded this, it worked fine until I wanted to print the remaining cash after an evening of indulgence.
I get a division by zero error, whats my problem.

Option Explicit



Private Sub cmdStart_Click()
'Declare required storage
Dim Casinos As Integer
Dim Door_Ch As Currency
Dim Money_Res As Currency
Dim Cash As Currency
Dim Money_Spent As Currency

'ask user to input amount of cash taken out
Cash = InputBox("Please input amount taken ", "Cash to Spend")

Door_Ch = 1 * 6
Money_Res = Cash - Door_Ch - Money_Spent Mod (Casinos 3)
Casinos = Cash - Door_Ch

'Display output in Pic box
picMessage.Print "Door charges paid ", "£"; (Door_Ch)
picMessage.Print "Amount to spend after charges ", "£"; (Cash - Door_Ch)
picMessage.Print "In each casino he spent in casinos ", "£"; (Casinos / 3)
picMessage.Print "The amount he has left is ", "£"; (Money_Res)
End Sub

Beats me.
Thanx
Charlie
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I dont getcha Andrew,Which do you think is in the wrong order.
This code works fine until I entered the line for printing the remainder.
The Casinos line is Cash minus Door Charge of 6 and whats left divided by 3 because I have been to 3 casinos.
what I want it to do is print the remaining change after division by 3, if you follow me.

Charlie
 
Upvote 0
Because you haven't assigned a value to Casinos until the next line:

Money_Spent Mod (Casinos 3)

will return DIV/0. Mod gives the remainder after divison and Casinos3 is zero.

And where are you defining Money_Spent?
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top