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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why doesnt my code work?

Status
Not open for further replies.

mettodog

Vendor
Jul 11, 2000
94
US
dim filename as string
filename = filename1.text

form1.caption = filename

filename1.text's caption property is "myfile"

when the form loads, the caption is myfile

but when you type something else in the filename1.text box, form1's caption remains myfile

also, when i open a text file, i want the filename to be displayed in filename1.text, so i used this code

filename1.text = commondialog1.filename

but this code doesnt work either. why doesnt this code(s) work?
 
in which event did u write the code in.
when ever u load a file either by pressing a command button or any other way see that u assign the commandialog1.filename to the text property of the text box and also do that form.caption= so and so
what ever u want

 
It sounds like you need to use the Change event of the text box to set the caption of the form.

When you show the open dialog, set the text box text to the file chosen, and then the Change event of the text box will update the forms caption.

Try the code below - to use the code, create a form and add a text box called filename1, and a command button called cmdOpen. Also, add a reference to Microsoft Common Dialog Control (in Project, References). If you cannot see this listed, browse to comdlg32.ocx (normally found in either c:\winnt\system32 or c:\windows\system).

Option Explicit

Private Sub cmdOpen_Click()
Dim objComDlg As CommonDialog
Set objComDlg = New CommonDialog
objComDlg.Flags = cdlOFNExplorer
objComDlg.Filter = "All Files (*.*)|*.*"
objComDlg.CancelError = False
objComDlg.ShowOpen
If Len(objComDlg.FileName & &quot;&quot;) <> 0 Then
filename1.Text = objComDlg.FileName ' will change the form caption
End If
Set objComDlg = Nothing
End Sub

Private Sub filename1_Change()
Form1.Caption = filename1.Text ' will change the form caption
End Sub

Private Sub Form_Load()
filename1.Text = &quot;myFile&quot; ' will change the form caption
End Sub


Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top