PC Review


Reply
Thread Tools Rate Thread

code works on some computers, but not on others

 
 
Phillip M. Feldman
Guest
Posts: n/a
 
      15th Oct 2008
The following simple program is supposed to display one message box
containing the string "Jan", and a second one containing six month names
separated by dashes. At least one person reports getting this result from the
code, but when I run it on my two laptop computers, the first message box is
empty, and the second contains only the five dashes (no month names). All of
these are Windows XP PCs running Excel 2003. Any suggestions as to why this
is happening will be greatly appreciated.

Option Base 1
Dim Arr() As String

Sub assignArray()
ReDim Arr(5)

Arr(1) = “Jan”
Arr(2) = “Feb”
Arr(3) = “Mar”
Arr(4) = “Apr”
Arr(5) = “May”

MsgBox Arr(1)

ReDim Preserve Arr(6)

Arr(6) = “Jun”

MsgBox Arr(1) + "-" + Arr(2) + "-" + Arr(3) + "-" + Arr(4) + "-" + Arr(5)
+ "-" + Arr(6)
End Sub
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      16th Oct 2008
The problem appears to be the font for the quote marks. I copied the code
you posted and got the results you described. When I changed the quote marks
on the months, it worked. Below is the code with the courier font quote
marks. Try it.

Sub assignArray()
Dim myArr() As Variant
ReDim myArr(5) As Variant

myArr(1) = "Jan"
myArr(2) = "Feb"
myArr(3) = "Mar"
myArr(4) = "Apr"
myArr(5) = "May"

MsgBox myArr(1)

ReDim Preserve myArr(6)
myArr(6) = "Jun"

MsgBox myArr(1) + "-" + myArr(2) + "-" + myArr(3) + "-" + myArr(4) _
+ "-" + myArr(5) + "-" + myArr(6)
End Sub


"Phillip M. Feldman" wrote:

> The following simple program is supposed to display one message box
> containing the string "Jan", and a second one containing six month names
> separated by dashes. At least one person reports getting this result from the
> code, but when I run it on my two laptop computers, the first message box is
> empty, and the second contains only the five dashes (no month names). All of
> these are Windows XP PCs running Excel 2003. Any suggestions as to why this
> is happening will be greatly appreciated.
>
> Option Base 1
> Dim Arr() As String
>
> Sub assignArray()
> ReDim Arr(5)
>
> Arr(1) = “Jan”
> Arr(2) = “Feb”
> Arr(3) = “Mar”
> Arr(4) = “Apr”
> Arr(5) = “May”
>
> MsgBox Arr(1)
>
> ReDim Preserve Arr(6)
>
> Arr(6) = “Jun”
>
> MsgBox Arr(1) + "-" + Arr(2) + "-" + Arr(3) + "-" + Arr(4) + "-" + Arr(5)
> + "-" + Arr(6)
> End Sub

 
Reply With Quote
 
Phillip M. Feldman
Guest
Posts: n/a
 
      17th Oct 2008
You are 100 percent right about the quotes. I hadn't realized that using one
type of double quote symbol rather than another made such a difference.
Thanks!

The behavior of the program is now much closer to what I expected. In
particular, the first message box shows the string "Jan", which is correct.
The second message box shows the string "Jan-Feb-Mar-Apr-May-", which is
missing the sixth month name. It seems as though the redim statement is not
working. Any suggestions will be appreciated.
 
Reply With Quote
 
Phillip M. Feldman
Guest
Posts: n/a
 
      17th Oct 2008
Cancel previous. It appears that I failed to correct one of the quote
characters. The VBA editor should flag this, but it doesn't.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula only works on some computers Libby Microsoft Excel Worksheet Functions 13 12th May 2008 02:02 PM
VPN works but I can't access computers wpr Windows XP Work Remotely 9 28th Dec 2006 10:00 AM
works on some of my computers!!! JKlein Microsoft Access Form Coding 3 6th Dec 2006 02:40 AM
Networking 2 computers, 1 works =?Utf-8?B?bHlsZXNiYWNrMg==?= Windows XP Networking 2 7th Feb 2006 08:13 PM
Building EXE that works on other computers? =?Utf-8?B?Z2FiYm90dA==?= Microsoft Dot NET 5 10th Mar 2005 09:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:29 AM.