Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URGENT PLEASE HELP - VB QUESTIONS

Status
Not open for further replies.

AnthonyH

MIS
Aug 16, 2001
7
US
I have a simple question - for a problem that I have not been able to solve - I'm trying to write a VB form to do this simple procedure automatically.

Open a plain text file c:\test\A54001.min
Save the file exactly as it is.
Close the file.

The catch is that I want to do it for 1200 files, in sequence A54001.min thru A551200.min.

I can't even do it for 1 file.

I've written this code for a VB form:

Private Sub Command1_Click()
On Error GoTo FileError
Open "c:\test\A54001.min" For Append As #1
Close #1
Exit Sub

FileError:
MsgBox "File Error!"
End Sub

It runs but nothing happens to my file.


Please help!!!
Thanks in advanced...
 
You are not doing anything to it except opening and closing it. what do you want to happen exactly?
 
Here is something my friend just wrote. Can you make any sense of it?


Dim varpart As Variant
Dim strpart As String
Dim strname As String
Dim fso As FileSystemObject
Dim intoutput As Integer
Dim intreal As Integer

Private Sub Command1_Click()

varpart = 54000
intoutput = 1
intreal = intoutput + 1
Do Until (varpart = 55120)
varpart = varpart + 1
strpart = CStr(varpart)

strname = "c:\A" & strpart & ".min"
Open strname For Output As #intreal
Close intreal
Loop

End Sub


 
Yes, I can make sense of it. Basically does what you said you needed to do in your first post. Kinda sloppy, incrementing the file number by 1 for each loop is not a good idea, but it probably would run. Sure wouldn't put those files in c:\ . . . could be a mess to clean up.

You still haven't answered the real question. What are you trying to do???? Are you trying to create 1200 empty files? Maybe trying to update the timestamps on existing files? What?
 
create the emmpty files with the following A5****.min
format - keep creating until I get to the end which is
A551200.min.
 
...in sequence A54001.min thru A55200.min. ...

Try this

Option Explicit
Dim i as long, File as string, Path as string, Ext as string
Path = "C:\TestPath\"
Ext = ".min"
For i = 54001 to 55200
File = "A" + Trim(Str(i))
Open (Path + File + Ext) For Append As #1
Close
Next
Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Normal practice for string concatenation is to use '&' operator rather than '+' operator

The '+' operator will only concatenate strings under limited circumstances - see '+ operator' in VBHelp for details
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
>The '+' operator will only concatenate strings

Well, not if the parameters are variants, since VB will cast for you...;-)
 
Back to the original questions - here is a much more detailed explanation of what we need to accomplished with
VB or even PERL....

I need to open, save and close 1200 very short files. They are strictly text files to be used in CNC machines, as job code for cutting metal on lathes.

When we transfer them to the machines, they won't run unless we have already opened them and saved them. We do not want to make any changes at all.

I can open a file in notepad, save it as the same name, and then close it. Then the machine will read it. I just have 1200 to do at a time.

Is there a way to automate this using VB or even PERL
to open the files (1200) close it...no file or it's name
will be change..

Thanks,
Anthony
 
I used to be a NC programmer...
I have done this before...

this Should work...

Path = "C:\TestPath\"
Ext = ".min"
For i = 54001 to 55200
File = "A" + Trim(Str(i))
Open (Path + File + Ext) For Append As #1
Close
Next


And... Johnwm,
if '+' is used Str() ... it has the same effect as &...

try this with a new Form with a command button...

Private Sub Command1_Click()
Dim a As String, b As Integer, c As String
a = "1"
b = 2
c = a & b
Print c
c = a + b
Print c
c = a + Trim(Str(b))
Print c
End Sub

the output will be:
12
3
12


so in this case... if the &'s are changing to AND's then use + Trim(Str(x)) as an alternative Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
lol... oops...
I was thinking about... thread707-443435
go ahead and use & x or + trim(str(x))
they BOTH function the same
* though & requires less typing... Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
You take my point! [smile]
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
If you want to know the history of the two, here it is.

The earlier versions of VB used the + sign for both addition and concatenation. Somewhere around VB4, & was introduced to perform concatenation due to problems with implicit data type conversions. 1 + "2" doesn't really tell you if you want to convert "2" to numeric and add them together or convert 1 to string and concatenate them. Microsoft strongly recomends using & for concatenation but left the functionality for + as is for backwards compatibility.

What is really funny though, Microsoft to this day still has examples using + as concatenation. However, I imagine this is just code from the old days that never was updated when used in current documentation.

You can use what you want but & makes for easier reading. With the +, you have to stop to understand the context of the statement before determining if it means addition or concatenation.

Hope this clear it up.

Chris.
 
I agree... The main reason I was using + was that I got the 2 threads mixed up...
Thats the result of Lack-Of-Sleep + (or &) programing ;-)
Personally I usually use &...
Good Luck... (and @ 4:00 am... Good NIGHT!) Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top