|
-
July 16th, 2001, 09:18 AM
#1
Files (still...)
Me again
1. If I want to programatically create a new file, and it ALREADY Exists - is there a way/function to test for it?
2. How do I limit a user's reply to an Input box - eg must only reply with 2 char?
Thanks again
-
July 16th, 2001, 09:30 AM
#2
Re: Files (still...)
I'm not really certain about your first question so I'll have to skip it for now, but as for your second question regarding the data retreived frm an input box..
I would put some error checking code in after the input box is called.
retval = InputBox "Enter some data: ","Title bar"
If len(retval) > 2 then
InputBox "Invalid Entry, Please try again: ", "Title bar"
End If
Hope that helps!
-
July 16th, 2001, 09:31 AM
#3
Re: Files (still...)
4 ways to find if file exists
1.
Private Function FileExistsWithDir(ByVal filename As String)
Dim file_name As String
On Error Resume Next
file_name = Dir$(filename)
FileExistsWithDir = (file_name <> "")
End Function
'----
FileExists = Not (Dir(filespec)="")
'// there! filespec is the filename with full path. If the file exists then
'// FileExits = True, if it does not exist, then FileExists = False.
'// Simple really.
2.
Private Function FileExistsWithOpen(ByVal filename As String)
Dim fnum As String
fnum = FreeFile
On Error GoTo FileDoesntExist
Open filename For Input As fnum
Close fnum
FileExistsWithOpen = True
Exit Function
FileDoesntExist:
FileExistsWithOpen = False
End Function
3,
Private Function FileExistsWithFileLen(ByVal filename As String)
Dim length As Long
On Error GoTo FileDoesntExist
length = FileLen(filename)
FileExistsWithFileLen = True
Exit Function
FileDoesntExist:
FileExistsWithFileLen = False
End Function
4.
Private Function FileExistsWithAttrib(txt)
Dim lRetVal As Long
On Error GoTo FileDoesntExist:
lRetVal = GetAttr(txt)
FileExistsWithAttrib = True
Exit Function
FileDoesntExist:
FileExistsWithAttrib = False
End Function
>>How do I limit a user's reply to an Input box - eg must only reply with 2 char?
You can enter info not to the Inputbox but Text box with Max = 2
Iouri Boutchkine
[email protected]
-
July 16th, 2001, 09:33 AM
#4
Re: Files (still...)
#1 Checking if a file already exists:
dim strFile as string
strFile = Dir("c:\myfile.dat")
If strFile <> "" then
' file exists
else
' file does not exist
end if
#2 Max 2 input
private Sub text1_Change()
If len(Text1.Text) > 2 then
Beep ' sound a beep
Text1.text = Left(Text1.Text,2)
End If
End Sub
Tom Cannaerts
[email protected]
Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|