Excel VB problem line. :: MrExcel Message Board


 FAQFAQ
   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   StatisticsStatistics 
 RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Online StoreOnline Store

MrExcel Message Board Forum Index -> Excel Questions

VB problem line.
Post new topic   Reply to topic
Last Thread | Next Thread  >   Printable version
  Author    Thread

Charlie
Board Master


Joined: 02 Mar 2002
Posts: 124


Status: Offline

 Reply with quote  

I have a problem line in my code, to my reckoning it should tell me I have paid no more door charges.
The code executes but does not give me a print message.
what is wrong with it?

Option Explicit

Private Sub cmdQUIT_Click()
'Terminate Application
End
End Sub

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


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 ", ""; (Cash - 6) Mod 3
If (Cash - 6) Mod 3 >= 2 Then
picMessage.Print "He can visit one more Casino "
If (Cash - 6) Mod 3 = 2 Then
picMessage.Print "He has paid 2 more in door charges "[PROBLEM]
ElseIf (Cash - 6) Mod 3 < 2 Then
picMessage.Print "He pays no more door charges "[/PROBLEM]

End If
End If

End Sub


[ This Message was edited by: Charlie on 2002-10-28 08:12 ]

Post Mon Oct 28, 2002 1:11 pm 
 View user's profile Send private message Send e-mail

Andrew Poulsom
MrExcel MVP


Joined: 22 Jul 2002
Posts: 8178

Flag: Uk

Status: Offline

 Reply with quote  

Give some examples of how much cash you took and the expected reults.

Post Mon Oct 28, 2002 1:26 pm 
 View user's profile Send private message

Charlie
Board Master


Joined: 02 Mar 2002
Posts: 124


Status: Offline

 Reply with quote  

The cash taken is user defined variable.
The expected results are either 0 1 2 change after visting the 3 casinos 2 means he can pay 1 more door charge less than 2 means he has no more door charges to pay.
The damn thing should work Andrew.
Say if I take 28, I have left 1 meaning I do not pay any more door charges.
My code should then print "No more door charges "
Charlie

[ This Message was edited by: Charlie on 2002-10-28 08:49 ]

Post Mon Oct 28, 2002 1:36 pm 
 View user's profile Send private message Send e-mail

Andrew Poulsom
MrExcel MVP


Joined: 22 Jul 2002
Posts: 8178

Flag: Uk

Status: Offline

 Reply with quote  

Conditions 2 and 3 will never be true because they are inside the statement:

If (Cash - 6) Mod 3 >= 2 Then

Your code should be:

code:

If (Cash - 6) Mod 3 >= 2 Then
   picMessage.Print "He can visit one more Casino "
ElseIf (Cash - 6) Mod 3 = 2 Then
   picMessage.Print "He has paid 2 more in door charges "[PROBLEM]
ElseIf (Cash - 6) Mod 3 < 2 Then
   picMessage.Print "He pays no more door charges "[/PROBLEM]
End If




Remove the second End If.

Post Mon Oct 28, 2002 1:51 pm 
 View user's profile Send private message

Charlie
Board Master


Joined: 02 Mar 2002
Posts: 124


Status: Offline

 Reply with quote  

Thankyou Andrew,theres a pint at my local with your name on it mate icon_smile.gif

Charlie

Post Mon Oct 28, 2002 2:26 pm 
 View user's profile Send private message Send e-mail
  Display posts from previous:      

MrExcel Message Board Forum Index -> Excel Questions


Forum Jump:
Jump to:  

Post new topic   Reply to topic
Page 1 of 1



Add To Favorites

 


Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB: 2.0.4 © 2001 phpBB Group

Need help posting your first question? Read how to post

Need extra help ? Couldn't get the answer you needed ? Get a free quote from our Consulting Team

Download Colo's HTML Maker utility for displaying your Excel Worksheet on the board.

Download VB HTML Maker to post your code on the board


Check out our new index to 485 Excel Articles.


Return to MrExcel Consulting

All contents Copyright 1998-2004 by MrExcel.com
If you believe information posted here is from your copyrighted source, notify us per the Terms of Use
Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.