Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Other Basic conversion to vb

I am old Power Basic programmer. (In DOS)

to open file and write to it looked like this:

Open "filename" as #1 for output as (then you select the type of file
you want)

then to output to that file you use print... like

Print #1, whatever

When your done you use close #1


What is the vb equivalent? How do you open a file, tell what kind it is
then write to it and close it?

I've looked in the help files under open, file, close, & save and
haven't found it.

Thanks

John


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Other Basic conversion to vb

John,

The syntax is the same. See help for the Open statement (not the
method of the Workbook object) in VBA help.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"John" wrote in message
...
I am old Power Basic programmer. (In DOS)

to open file and write to it looked like this:

Open "filename" as #1 for output as (then you select the type
of file you want)

then to output to that file you use print... like

Print #1, whatever

When your done you use close #1


What is the vb equivalent? How do you open a file, tell what
kind it is then write to it and close it?

I've looked in the help files under open, file, close, & save
and haven't found it.

Thanks

John




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Other Basic conversion to vb

This is low level file io and hasn't changed. (primarily used for text
files although random access and binary access are supported)

If you want to open a workbook


Workbooks.Open "C:\MyFiles\Myfile2.xls"

What is it you are trying to do?

--
Regards,
Tom Oiglvy

"John" wrote in message
...
I am old Power Basic programmer. (In DOS)

to open file and write to it looked like this:

Open "filename" as #1 for output as (then you select the type of file
you want)

then to output to that file you use print... like

Print #1, whatever

When your done you use close #1


What is the vb equivalent? How do you open a file, tell what kind it is
then write to it and close it?

I've looked in the help files under open, file, close, & save and
haven't found it.

Thanks

John




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Other Basic conversion to vb

I wanted to save a PART of a workseet to a text file. Below is my
attempt using macro record (commented) and my sort of down and dirty one
which works well enough. The commented one saves the entire workseet. I
couldn't make it stop doing that.

The types to change into strings I found by trial and error.

John

Sub SaveSheet()
'
'
' *** Best I could do using record macro
' *** This saves entire worksheet, not the selected part
' *** In addition it changes the canme of the sheet in the Workbook
' Sheets("MN INV").Select '
' Range("A16:E28").Select
' ChDir "C:\Temp"
' ActiveWorkbook.SaveAs Filename:= _
' "C:\Temp\TestThisPuppy.txt" _
' , FileFormat:=xlText, CreateBackup:=False
' *** End Attempt using Macro Recording
'

Dim PutIt As Variant
Dim Row, Col as Byte
Sheets("MN INV").Select
Open "C:\temp\TestThisPuppy.txt" For Output As #1

For Row = 16 To 28
PutIt = ""

For Col = 1 To 5
Select Case VarType(Cells(Row, Col))
Case 5 To 7: PutIt = PutIt + Str$(Cells(Row, Col))
Case Else: PutIt = PutIt + Cells(Row, Col)
End Select
If Col < 5 Then PutIt = PutIt + Chr$(9)
Next

Print #1, PutIt
Next

Close #1
End Sub

Tom Ogilvy wrote:

This is low level file io and hasn't changed. (primarily used for text
files although random access and binary access are supported)

If you want to open a workbook


Workbooks.Open "C:\MyFiles\Myfile2.xls"

What is it you are trying to do?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Other Basic conversion to vb

Sub SaveSheet()
Dim sh as Worksheet, sh1 as Worksheet
set sh = Sheets("MN INV")
workbooks.Add xlWBATWorksheet
set sh1 = ActiveSheet
sh.Range("A16:E28").copy sh1.Range("A1")
sh1.Parent.SaveAs Filename:= _
"C:\Temp\TestThisPuppy.txt", _
FileFormat:=xlText, CreateBackup:=False
sh1.parent.Close SaveChanges:=False ' Already Saved.
End sub

32 bit processor, so row and col will be converted to long anyway. Also

Dim row, col as Byte

row is a variant, col is a byte

+ is overloaded for concatenation, so better to use the & which is the
concatenation operator.

Str$(Cells(Row, Col)) puts a space in front of the value in Cells(row,col).
Maybe what you want or not. cStr(cells(row,col)) would not put in a space,
however & Cells(row,col) would coerce it to a string anyway without
explicit conversion.


--
Regards,
Tom Ogilvy


"John" wrote in message
...
I wanted to save a PART of a workseet to a text file. Below is my
attempt using macro record (commented) and my sort of down and dirty one
which works well enough. The commented one saves the entire workseet. I
couldn't make it stop doing that.

The types to change into strings I found by trial and error.

John

Sub SaveSheet()
'
'
' *** Best I could do using record macro
' *** This saves entire worksheet, not the selected part
' *** In addition it changes the canme of the sheet in the Workbook
' Sheets("MN INV").Select '
' Range("A16:E28").Select
' ChDir "C:\Temp"
' ActiveWorkbook.SaveAs Filename:= _
' "C:\Temp\TestThisPuppy.txt" _
' , FileFormat:=xlText, CreateBackup:=False
' *** End Attempt using Macro Recording
'

Dim PutIt As Variant
Dim Row, Col as Byte
Sheets("MN INV").Select
Open "C:\temp\TestThisPuppy.txt" For Output As #1

For Row = 16 To 28
PutIt = ""

For Col = 1 To 5
Select Case VarType(Cells(Row, Col))
Case 5 To 7: PutIt = PutIt + Str$(Cells(Row, Col))
Case Else: PutIt = PutIt + Cells(Row, Col)
End Select
If Col < 5 Then PutIt = PutIt + Chr$(9)
Next

Print #1, PutIt
Next

Close #1
End Sub

Tom Ogilvy wrote:

This is low level file io and hasn't changed. (primarily used for text
files although random access and binary access are supported)

If you want to open a workbook


Workbooks.Open "C:\MyFiles\Myfile2.xls"

What is it you are trying to do?






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default Other Basic conversion to vb

You have already got the most accessible reference: if you have Excel.
Press Alt + F11 then F1 and search for the keywords. As regards files, what
is true of VBA is also true of VB.


"John" wrote:

I am old Power Basic programmer. (In DOS)

to open file and write to it looked like this:

Open "filename" as #1 for output as (then you select the type of file
you want)

then to output to that file you use print... like

Print #1, whatever

When your done you use close #1


What is the vb equivalent? How do you open a file, tell what kind it is
then write to it and close it?

I've looked in the help files under open, file, close, & save and
haven't found it.

Thanks

John



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
Help on conversion Help on formula[_2_] Excel Discussion (Misc queries) 3 September 11th 09 07:13 AM
XLS to CSV conversion border21 Excel Programming 2 June 10th 04 02:38 AM
XML Conversion GeneO Excel Programming 2 February 26th 04 02:59 PM
basic variant to array conversion Jeff Sward Excel Programming 1 January 26th 04 07:59 PM
hex conversion Ruchi[_2_] Excel Programming 2 October 31st 03 04:41 AM


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

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

About Us

"It's about Microsoft Excel"