MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 28th, 2002, 03:35 AM   #1
Chris Davison
MrExcel MVP
 
Join Date: Feb 2002
Location: Millbank, London, UK
Posts: 1,790
Default

Just testing the ability to edit the subject line if I'm happy my question has been solved.....

if anyone else wants to put a solved flag, you need to do it in your intial posting, it won't work in any other posts.
===========================================


Does anyone else use JWalk's calculator toolbar ?

mine crashes whenever I click on the decimal point

"Run-time error '13' :

Type mismatch"

does anyone else have this problem ?

(I emailed him and he said he'd look into it but didn't get back to me....(I know he's very very busy)

I have this problem on two machines so know it's not my machine or the way I installed it or something......

Any ideas ?

Here's the whole code

' Copyright 2001, JWalk & Associates, Inc.
' This add-in may be freely distributed for personal use.
' It may not be distributed as part of any commercial product.
' http://j-walk.com/ss

Option Explicit
Option Private Module
Public Const APPNAME As String = "Toolbar Calculator"
' Used for undoing cell paste
Public UndoCell As Range
Public UndoValue As Variant
Public UndoFormat As String
' Global variables
Public LastInput As String
Public DecimalFlag As Boolean
Public OpFlag As String
Public NumOps As Integer
Dim Op1 As Variant
Dim Op2 As Variant
Public Readout As String

Sub ShowCalculatorToolbar()
' Executed by the Tools menu command
' and called when this workbook is opened

' If toolbar exists toggle display
Dim ComBarCalculator As CommandBar
On Error Resume Next
Set ComBarCalculator = Application.CommandBars(APPNAME)
If Err.Number = 0 Then
ComBarCalculator.Visible = Not ComBarCalculator.Visible
On Error GoTo 0
Exit Sub
Else
Call CreateToolbar
End If
On Error GoTo 0
End Sub

Sub CreateToolbar()
' Creates the toolbar
Dim ComBarCalculator As CommandBar
Dim Ctl As CommandBarControl
Dim SubCtl As CommandBarControl

' Delete it if it already exists
On Error Resume Next
Application.CommandBars(APPNAME).Delete
On Error GoTo 0

' Create the toolbar
Set ComBarCalculator = Application.CommandBars.Add(APPNAME)

' Add the Readout (edit box)
Set Ctl = Application.CommandBars(APPNAME).Controls.Add(Type:=msoControlEdit)
Ctl.width = 173

' Add the other buttons (see the AddButton procedure, below)
AddButton 30, "7"
AddButton 30, "8"
AddButton 30, "9"
AddButton 23, "" 'spacer
AddButton 30, "C", "Clear All"
AddButton 30, "CE", "Clear Entry"

AddButton 30, "4"
AddButton 30, "5"
AddButton 30, "6"
AddButton 23, "" 'spacer
AddButton 30, "+", "Plus"
AddButton 30, "-", "Minus"

AddButton 30, "1"
AddButton 30, "2"
AddButton 30, "3"
AddButton 23, "" 'spacer
AddButton 30, "X", "Multiplied by"
AddButton 30, "/", "Divided by"

AddButton 60, "0"
AddButton 30, Application.International(xlDecimalSeparator), "Decimal"
AddButton 23, "" 'spacer
AddButton 60, "=", "Equals"

' Add Help button, and sub buttons
Set Ctl = Application.CommandBars(APPNAME).Controls.Add(msoControlPopup)
With Ctl
.caption = "Help"
.width = 60
Set SubCtl = .Controls.Add 'Help
With SubCtl
.caption = "Help..."
.OnAction = "HelpClick"
.FaceId = 984
End With
Set SubCtl = .Controls.Add 'About
With SubCtl
.caption = "About..."
.OnAction = "AboutClick"
End With
End With

' Add Paste Button
Set Ctl = Application.CommandBars(APPNAME).Controls.Add
With Ctl
.Style = msoButtonCaption
.width = 112
.caption = "Paste to cell"
.TooltipText = "Paste the result to the active cell"
.OnAction = "PasteToCellClick"
End With

' Adjust the toolbar
With ComBarCalculator
.Visible = True
.width = 179 'This forces the row breaks
.Protection = msoBarNoChangeDock + msoBarNoResize + msoBarNoCustomize
End With

Call ResetCalculator
End Sub

Sub AddButton(width, caption, Optional tooltip)
' Adds a button to the CommandBar
Dim Btn As CommandBarButton
Set Btn = Application.CommandBars(APPNAME).Controls.Add
With Btn
.Style = msoButtonCaption
.width = width
.caption = caption
.State = msoButtonDown
.OnAction = "Butt*******"
If Not IsMissing(tooltip) Then .TooltipText = tooltip
If caption = "" Then .Enabled = False
End With
End Sub

Sub Butt*******()
' Event procedure for all button clicks
' Depending on the button, it calls other procedures
Dim BtnIndex
Dim Btn As Variant
BtnIndex = Application.Caller(1)
Btn = Application.CommandBars(APPNAME).Controls(BtnIndex).caption
Select Case Btn
Case 0 To 9: Call NumberClick(Btn)
Case "+", "-", "X", "/", "=": Call OperatorClick(Btn)
Case Application.International(xlDecimalSeparator): Call DecimalClick
Case "C": Call ClearClick
Case "CE": Call ClearEntryClick
Case "Paste to cell": Call PasteToCellClick
End Select
End Sub

Sub DecimalClick()
' Click event procedure for decimal point (.) key.
If Left(Readout, 1) = "*" Then Call ResetCalculator
If LastInput = "NEG" Then
Readout = "-0" & Application.International(xlDecimalSeparator)
ElseIf LastInput <> "NUMS" Then
Readout = "0" & Application.International(xlDecimalSeparator)
End If
DecimalFlag = True
LastInput = "NUMS"
Application.CommandBars(APPNAME).Controls(1).Text = Readout
End Sub

Sub NumberClick(Index)
' Click event procedure for number keys (0-9).
If Left(Readout, 1) = "*" Then Call ResetCalculator
If Application.CommandBars(APPNAME).Controls(1).width > 173 Then
MsgBox "Number is too long!", vbCritical, APPNAME
Call ResetCalculator
Exit Sub
End If
If LastInput <> "NUMS" Then
Readout = Application.International(xlDecimalSeparator)
DecimalFlag = False
End If
If DecimalFlag Then
Readout = Readout & Index
Else
Readout = Left(Readout, InStr(Readout, Application.International(xlDecimalSeparator)) - 1) & Index & Application.International(xlDecimalSeparator)
End If
If LastInput = "NEG" Then Readout = "-" & Readout
LastInput = "NUMS"
Application.CommandBars(APPNAME).Controls(1).Text = Readout
End Sub

Sub OperatorClick(Op)
' Click event procedure for operator keys (+, -, *, /, =).
Dim TempDisplay As String
Dim Msg As String
If Left(Readout, 1) = "*" Then Call ResetCalculator 'error
TempDisplay = CDbl(Readout)
If LastInput = "NUMS" Then NumOps = NumOps + 1

On Error GoTo NoCanDo
Select Case NumOps
Case 0
If Op = "-" And LastInput <> "NEG" Then
Readout = "-" & Readout
LastInput = "NEG"
End If
Case 1
Op1 = CDbl(Readout)
If Op = "-" And LastInput <> "NUMS" And OpFlag <> "=" Then
Readout = "-"
LastInput = "NEG"
End If
Case 2
Op2 = TempDisplay
Select Case OpFlag
Case "+": Op1 = CDbl(Op1) + CDbl(Op2)
Case "-": Op1 = CDbl(Op1) - CDbl(Op2)
Case "X": Op1 = CDbl(Op1) * CDbl(Op2)
Case "/": Op1 = CDbl(Op1) / CDbl(Op2)
Case "=": Op1 = CDbl(Op2)
End Select
If HasDecimal(Op1) Then Readout = Op1 Else Readout = Op1 & Application.International(xlDecimalSeparator)
NumOps = 1
End Select
If LastInput <> "NEG" Then
LastInput = "OPS"
OpFlag = Op
End If
Application.CommandBars(APPNAME).Controls(1).Text = Readout
Exit Sub
NoCanDo:
Readout = "* ERROR *"
Application.CommandBars(APPNAME).Controls(1).Text = Readout
On Error GoTo 0
End Sub

Sub ClearClick()
' Click event procedure for C (cancel) key.
Call ResetCalculator
End Sub

Sub ClearEntryClick()
' Click event procedure for CE (cancel entry) key.
Readout = "0"
DecimalFlag = False
LastInput = "CE"
Application.CommandBars(APPNAME).Controls(1).Text = Readout
End Sub

Sub PasteToCellClick()
' Put the result in the active cell
On Error Resume Next
With ActiveCell
' Save for undo
Set UndoCell = ActiveCell
UndoValue = .Value
UndoFormat = .NumberFormat
.Value = CDbl(Readout)
End With
' Move to next cell if user has that option set
If Application.MoveAfterReturn Then
Select Case Application.MoveAfterReturnDirection
Case xlDown: ActiveCell.Offset(1, 0).Activate
Case xlToRight: ActiveCell.Offset(0, 1).Activate
Case xlToLeft: ActiveCell.Offset(0, -1).Activate
Case xlUp: ActiveCell.Offset(-1, 0).Activate
End Select
End If
On Error GoTo 0
Application.OnUndo "Undo Paste From Calculator", "UndoCalculator"
End Sub

Sub ResetCalculator()
Readout = "0"
Application.CommandBars(APPNAME).Controls(1).Text = Readout
Op1 = 0
Op2 = 0
DecimalFlag = False
NumOps = 0
LastInput = "NONE"
OpFlag = " "
End Sub

Sub UndoCalculator()
' Undo the last paste operation
On Error GoTo NoCanDo
With UndoCell
.Parent.Parent.Activate
.Parent.Activate
.Activate
.Value = UndoValue
.NumberFormat = UndoFormat
End With
On Error GoTo 0
Exit Sub
NoCanDo:
MsgBox "Can't undo.", vbInformation, APPNAME
On Error GoTo 0
End Sub

Function HasDecimal(s) As Boolean
HasDecimal = InStr(s, Application.International(xlDecimalSeparator)) <> 0
End Function

Sub HelpClick()
Dim Msg As String
Msg = ""
Msg = Msg & "This Toolbar Calculator works just like a simple calculator." & vbCrLf & vbCrLf
Msg = Msg & " " & Chr(149) & " Keyboard not supported (mouse only)." & vbCrLf
Msg = Msg & " " & Chr(149) & " You cannot enter numbers directly into the result section." & vbCrLf
Msg = Msg & " " & Chr(149) & " Click 'Paste to cell' to put the result in the active cell." & vbCrLf
Msg = Msg & " " & Chr(149) & " Use Edit - Undo to restore the previous cell value." & vbCrLf
Msg = Msg & " " & Chr(149) & " The toolbar can be moved, but cannot be docked or resized." & vbCrLf
Msg = Msg & " " & Chr(149) & " The VBA code in the add-in is not protected." & vbCrLf
Msg = Msg & " " & Chr(149) & " Click the 'X' in the title bar to hide the calculator," & vbCrLf
Msg = Msg & " or use Tools - Toolbar Calculator to toggle the display." & vbCrLf
MsgBox Msg, vbInformation, APPNAME
End Sub

Sub AboutClick()
Dim Msg As String
Msg = ""
Msg = Msg & "This Toolbar Calculator was created by JWalk & Associates." & vbCrLf & vbCrLf
Msg = Msg & "This add-in file may be distributed freely, but it may not" & vbCrLf
Msg = Msg & "be sold or included with any other product." & vbCrLf & vbCrLf
Msg = Msg & "Visit 'The Spreadsheet Page' for Excel tips, macros, and downloads." & vbCrLf & vbCrLf
Msg = Msg & " " & Chr(149) & " Do you want to visit that site now?" & vbCrLf & vbCrLf
If MsgBox(Msg, vbInformation + vbYesNo, APPNAME) = vbYes Then
On Error Resume Next
ThisWorkbook.FollowHyperlink Address:="http://www.j-walk.com/ss/", NewWindow:=True
On Error GoTo 0
End If
End Sub

many thanks
Chris


[ This Message was edited by: Chris Davison on 2002-05-07 14:04 ]
Chris Davison is offline   Reply With Quote
Old Apr 28th, 2002, 09:25 AM   #2
Ian Mac
MrExcel MVP
 
Join Date: Feb 2002
Location: Newcastle, UK
Posts: 1,174
Default

Chris,

at what point does the error occur?
how do you actually get darn thing working?
__________________
"Have a good time......all the time"
Ian Mac
Ian Mac is offline   Reply With Quote
Old Apr 28th, 2002, 09:29 AM   #3
Ian Mac
MrExcel MVP
 
Join Date: Feb 2002
Location: Newcastle, UK
Posts: 1,174
Default

Scratch the how do you get it to work part (it is Sunday and I'm being crap!)

I don't seem to get the error you describe.
What version of Excel are you using?
XP's seems fine.
__________________
"Have a good time......all the time"
Ian Mac
Ian Mac is offline   Reply With Quote
Old Apr 28th, 2002, 09:37 AM   #4
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

I can't get it to let me put in a number, let alone a decimal point. I think that's because for some reason the layout of the toolbar is screw-wed. I don't have a normal looking calculator at all.

I would have to bugger about with it a lot to get it sorted. (it may work better on my desktop, rather than this laptop)
Mark O'Brien is offline   Reply With Quote
Old Apr 28th, 2002, 09:56 AM   #5
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Where's your error?
It's working fine on my sys...


Sub DecimalClick()
' Click event procedure for decimal point (.) key.
If Left(Readout, 1) = "*" Then Call ResetCalculator
If LastInput = "NEG" Then
Readout = "-0" & Application.International(xlDecimalSeparator)
ElseIf LastInput <> "NUMS" Then
Readout = "0" & Application.International(xlDecimalSeparator)
End If
DecimalFlag = True
LastInput = "NUMS"
Application.CommandBars(APPNAME).Controls(1).Text = Readout
End Sub
Tom Schreiner is offline   Reply With Quote
Old Apr 28th, 2002, 10:46 AM   #6
Chris Davison
MrExcel MVP
 
Join Date: Feb 2002
Location: Millbank, London, UK
Posts: 1,790
Default

Quote:
On 2002-04-28 08:29, Ian Mac wrote:
Scratch the how do you get it to work part (it is Sunday and I'm being crap!)

I don't seem to get the error you describe.
What version of Excel are you using?
XP's seems fine.
Hi Ian,

I'm on Excel 97 on both machines (home and work)

It's weird... I initally tried it about 6 months ago and it bombed so I emailed him. He suggested I'd got an older version and to retry while he looked into it. 6 months later and it still crashed from a new download.
Chris Davison is offline   Reply With Quote
Old Apr 28th, 2002, 10:49 AM   #7
Chris Davison
MrExcel MVP
 
Join Date: Feb 2002
Location: Millbank, London, UK
Posts: 1,790
Default

Quote:
On 2002-04-28 08:56, TsTom wrote:
Where's your error?
It's working fine on my sys...


Sub DecimalClick()
' Click event procedure for decimal point (.) key.
If Left(Readout, 1) = "*" Then Call ResetCalculator
If LastInput = "NEG" Then
Readout = "-0" & Application.International(xlDecimalSeparator)
ElseIf LastInput <> "NUMS" Then
Readout = "0" & Application.International(xlDecimalSeparator)
End If
DecimalFlag = True
LastInput = "NUMS"
Application.CommandBars(APPNAME).Controls(1).Text = Readout
End Sub
Thanks Tom,

my error is when I click the decimal point, I get the error message per above.

to enter 345.67, I click on the 3 then the 4 then the 5 then as soon as I click on the decimal point, it crashes.
Chris Davison is offline   Reply With Quote
Old Apr 28th, 2002, 11:12 AM   #8
Jack in the UK
Board Regular
 
Join Date: Feb 2002
Posts: 3,065
Default

Chris try this one.. sod the mouse i hate mice tap the intergers in by num keypad.. its faster also esc rset...

do she now crash


__________________
Free Excel based Web Toolbar available here.

Jack in the UK
J & R Excel Solutions
"making Excel work for you"
Jack in the UK is offline   Reply With Quote
Old Apr 28th, 2002, 11:51 AM   #9
Chris Davison
MrExcel MVP
 
Join Date: Feb 2002
Location: Millbank, London, UK
Posts: 1,790
Default

Jack....

NOT an option !!!

the reason I downloaded it was so I don't have to use the keyboard...

I hate going mouse / keyboard / mouse / keyboard

so being able to put numbers in via the mouse cuts out more keyboard use

Chris Davison is offline   Reply With Quote
Old Apr 28th, 2002, 11:59 AM   #10
Jack in the UK
Board Regular
 
Join Date: Feb 2002
Posts: 3,065
Default

Chris i know that silly we have had this telcon before but its a suggestion try it does it work, is so here i go hevay techi.. nar cant be bothered its sunday... check you PM's

OK the keyboard uses different technologies to mice, for a start dont eat cheese and drin coke tea and love coffe spilt on them.

BUT The keyboard has a chip thats a communicater to the com post address on the motherbaord so i guessing.. but the mouce opperates on com 1 so this post ONLY excepts points.. not the different keystrokes.. just to keep it smple ill stop there..

PLEASE try it....


__________________
Free Excel based Web Toolbar available here.

Jack in the UK
J & R Excel Solutions
"making Excel work for you"
Jack in the UK is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 01:24 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes