Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Not recognizing a Const

I'm writing a routine to write to a test file. I've had two suggestions;
delimiter=Char(9). This gives me an invalid function all. And;
Const DELIMITER As String = CHR(9), this gives me an error of "Const expression required"
It does not seem to be accepting the chr(9) or the char(9) as a valid literal to set the delimiter to.
Any ideas why?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Not recognizing a Const

"Dan T" .(donotspam) wrote in message
...
I'm writing a routine to write to a test file. I've had two suggestions;
delimiter=Char(9). This gives me an invalid function all. And;
Const DELIMITER As String = CHR(9), this gives me an error of "Const

expression required"
It does not seem to be accepting the chr(9) or the char(9) as a valid

literal to set the delimiter to.
Any ideas why?


Hi Dan,

The first instance is the one you want, but you have the function name
spelled wrong. It's Chr not Char. You can't use the results of a function to
create a constant, so the second option will not work.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Not recognizing a Const



"Rob Bovey" wrote:

"Dan T" .(donotspam) wrote in message
...
I'm writing a routine to write to a test file. I've had two suggestions;
delimiter=Char(9). This gives me an invalid function all. And;
Const DELIMITER As String = CHR(9), this gives me an error of "Const

expression required"
It does not seem to be accepting the chr(9) or the char(9) as a valid

literal to set the delimiter to.
Any ideas why?


Hi Dan,

The first instance is the one you want, but you have the function name
spelled wrong. It's Chr not Char. You can't use the results of a function to
create a constant, so the second option will not work.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *





Thanks rob that worked, but I thought it would replace the commas and quotes with the Tab, how do I remove the commas and quotes so I just have the Tab?
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Not recognizing a Const



"Rob Bovey" wrote:

"Dan T" .(donotspam) wrote in message
...
I'm writing a routine to write to a test file. I've had two suggestions;
delimiter=Char(9). This gives me an invalid function all. And;
Const DELIMITER As String = CHR(9), this gives me an error of "Const

expression required"
It does not seem to be accepting the chr(9) or the char(9) as a valid

literal to set the delimiter to.
Any ideas why?


Hi Dan,

The first instance is the one you want, but you have the function name
spelled wrong. It's Chr not Char. You can't use the results of a function to
create a constant, so the second option will not work.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *





Thanks Rob, that worked, but I thought it would replace the commas and quotes with the tab. How do I have just a Tab delimiter without the quotes and commas?
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Not recognizing a Const

And you could even just use:
vbTab
it's a constant builtin to VBA.

Const DELIMITER As String = vbTab

(And if delimiter isn't going to change in future versions, vbtab is quicker to
type!)

Dan T wrote:

I'm writing a routine to write to a test file. I've had two suggestions;
delimiter=Char(9). This gives me an invalid function all. And;
Const DELIMITER As String = CHR(9), this gives me an error of "Const expression required"
It does not seem to be accepting the chr(9) or the char(9) as a valid literal to set the delimiter to.
Any ideas why?


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Not recognizing a Const



"Dave Peterson" wrote:

And you could even just use:
vbTab
it's a constant builtin to VBA.

Const DELIMITER As String = vbTab

(And if delimiter isn't going to change in future versions, vbtab is quicker to
type!)

Dan T wrote:

I'm writing a routine to write to a test file. I've had two suggestions;
delimiter=Char(9). This gives me an invalid function all. And;
Const DELIMITER As String = CHR(9), this gives me an error of "Const expression required"
It does not seem to be accepting the chr(9) or the char(9) as a valid literal to set the delimiter to.
Any ideas why?


--

Dave Peterson



Still has commas and quotes, just adds tab to it. It there a way to just have the tab without the commas or quotes.
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Not recognizing a Const

I'm not sure what you're doing, but maybe this'll give you some ideas:

Option Explicit
Sub testme()

Dim myRow As Range
Dim myCell As Range
Dim wks As Worksheet

Dim myFileName As String
Dim FileNum As Long
Dim myLine As String

myFileName = "C:\test.txt"

Set wks = Worksheets("sheet1")

With wks

FileNum = FreeFile
Close FileNum
Open myFileName For Output As FileNum

For Each myRow In .UsedRange.Rows
myLine = ""
For Each myCell In myRow.Cells
myLine = myLine & vbTab & myCell.Text
Next myCell
If myLine < "" Then
Print #FileNum, Mid(myLine, 2)
End If
Next myRow
Close FileNum
End With

End Sub

If this doesn't help, there's lots of code you might want to look at to help:

Earl Kiosterud's Text Write program:
http://www.tushar-mehta.com/
Look for Text Write in the left hand frame.

Chip Pearson's:
http://www.cpearson.com/excel/imptext.htm

J.E. McGimpsey's:
http://www.mcgimpsey.com/excel/textfiles.html

(Although DELIMITER in all caps looks like J.E.'s code to start.)

Dan T wrote:

"Dave Peterson" wrote:

And you could even just use:
vbTab
it's a constant builtin to VBA.

Const DELIMITER As String = vbTab

(And if delimiter isn't going to change in future versions, vbtab is quicker to
type!)

Dan T wrote:

I'm writing a routine to write to a test file. I've had two suggestions;
delimiter=Char(9). This gives me an invalid function all. And;
Const DELIMITER As String = CHR(9), this gives me an error of "Const expression required"
It does not seem to be accepting the chr(9) or the char(9) as a valid literal to set the delimiter to.
Any ideas why?


--

Dave Peterson



Still has commas and quotes, just adds tab to it. It there a way to just have the tab without the commas or quotes.


--

Dave Peterson

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Not recognizing a Const

Why not post the code you use to write the file and perhaps someone can
suggest where you need to make changes.

--
Regards,
Tom Ogilvy

"Dan T" .(donotspam) wrote in message
...


"Dave Peterson" wrote:

And you could even just use:
vbTab
it's a constant builtin to VBA.

Const DELIMITER As String = vbTab

(And if delimiter isn't going to change in future versions, vbtab is

quicker to
type!)

Dan T wrote:

I'm writing a routine to write to a test file. I've had two

suggestions;
delimiter=Char(9). This gives me an invalid function all. And;
Const DELIMITER As String = CHR(9), this gives me an error of "Const

expression required"
It does not seem to be accepting the chr(9) or the char(9) as a valid

literal to set the delimiter to.
Any ideas why?


--

Dave Peterson



Still has commas and quotes, just adds tab to it. It there a way to just

have the tab without the commas or quotes.


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
Conditional format to highlight only cells with formula, not const hkbarnett Excel Worksheet Functions 2 November 19th 09 01:49 AM
Public Const on a Drive MD Excel Programming 1 July 15th 04 03:53 PM
crash changing const to public const BrianB Excel Programming 0 August 4th 03 10:13 AM
XLL - VS .Net2003 - init problem - const char strings - /Gf option?? Kevin Love Excel Programming 0 July 27th 03 11:32 PM
XLL - VS .Net2003 - init problem - const char strings - /Gf option?? Rob Bovey Excel Programming 1 July 27th 03 10:41 PM


All times are GMT +1. The time now is 10:07 PM.

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"