Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Strange 'Print' behaviour'

I'm using Excel as a flat database for my website data file, and a VBA
routine to output the html pages for me. So far, so good.

I came across some strange behaviour last night, which I had to use an
ugly hack to get around - the weirdness is demonstrated by:

Sub printError()
Dim MyNumber As Integer
MyNumber = 3*7
Debug.Print "This thing is "; MyNumber; "mm long"
End Sub

This will print "This thing is 21 mm long". In the code I'm outputting,
the space between the number and the following letters is invalid.

I've since discovered that declaring MyNumber as a string will still
allow me to set it to the value of a calculation(?!), and that the space
is then omitted.

Any ideas why this would be?

TIA

Nik
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Strange 'Print' behaviour'

Yes. A space is placed on each end of a number as part of its inherent
formatting.

If you look closely, if you just debug.print a number, it starts in the
second column.

Debug.Print 3 ' starts in second column.

--
Regards,
Tom Ogilvy



"Nik" wrote in message
...
I'm using Excel as a flat database for my website data file, and a VBA
routine to output the html pages for me. So far, so good.

I came across some strange behaviour last night, which I had to use an
ugly hack to get around - the weirdness is demonstrated by:

Sub printError()
Dim MyNumber As Integer
MyNumber = 3*7
Debug.Print "This thing is "; MyNumber; "mm long"
End Sub

This will print "This thing is 21 mm long". In the code I'm outputting,
the space between the number and the following letters is invalid.

I've since discovered that declaring MyNumber as a string will still allow
me to set it to the value of a calculation(?!), and that the space is then
omitted.

Any ideas why this would be?

TIA

Nik



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Strange 'Print' behaviour'

Tom Ogilvy wrote:
Yes. A space is placed on each end of a number as part of its inherent
formatting.

If you look closely, if you just debug.print a number, it starts in the
second column.

Debug.Print 3 ' starts in second column.

So it does - I hadn't noticed the double space before the number in my
example.

I don't suppose that there is any way to over-ride this that is more
elegant than declaring what should be an integer as a string?

Nik
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Strange 'Print' behaviour'

Sub printError()
Dim MyNumber As Long
MyNumber = 3*7
Debug.Print "This thing is " & format(MyNumber,"#") & "mm long"
End Sub


You save nothing using Integer instead of Long - in fact, I believe
internally, VBA converts it to long to work with it.

--
Regards,
Tom Ogilvy



"Nik" wrote in message
...
Tom Ogilvy wrote:
Yes. A space is placed on each end of a number as part of its inherent
formatting.

If you look closely, if you just debug.print a number, it starts in the
second column.

Debug.Print 3 ' starts in second column.

So it does - I hadn't noticed the double space before the number in my
example.

I don't suppose that there is any way to over-ride this that is more
elegant than declaring what should be an integer as a string?

Nik



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange if(***) behaviour? Excel 2003 - SPB Excel Discussion (Misc queries) 6 August 6th 06 05:34 PM
Strange VBA Behaviour Ricko Excel Programming 0 July 28th 05 07:53 AM
(Leo) Strange print to file behaviour Leo Excel Programming 0 July 14th 05 01:27 PM
Strange behaviour Edgar Thoemmes Excel Worksheet Functions 1 February 8th 05 03:20 PM
Strange behaviour in VBA Help Michael Singmin Excel Programming 4 June 4th 04 07:06 PM


All times are GMT +1. The time now is 11:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"