Use the following. But, instead of appending the .txt in your code to the string you used to specify the file name, type it in manually.
VB Code:
Private Sub Load_Click()
Dim stringDataL As String
sInput = InputBox("Load file name:")
If StrPtr(sInput) = 0 Then
Exit Sub
ElseIf StrPtr(sInput) <> 0 And sInput = "" Then
MsgBox "Please type a filename!"
Else
ff = FreeFile()
Open sInput For Input Lock Write As #ff 'open text
While Not EOF(ff)
Line Input #ff, stringDataL
With Text1
.Text = .Text & (stringDataL) & vbCrLf
End With
Wend
Close #1
End If
End Sub
Artificial Intelligence At War! - The best game of its genre Program your own robot and watch it fight in 3d! Droidarena 3
If I have been useful, please Rate My Post
Support FireFox -
Microsoft Visual Studio .NET Professional 2003
Microsoft Visual Studio 6, Enterprise Edition
Microsoft Windows XP Professional, Service Pack 2
yay! thanks, what do i need to let the user select what position they want to save to?
i know i need the drive list, dir list, and drive list box, or whatever..but i dont want those ugly squares coming up.
is there a way to let them choose where to save like in word or anything?
Use the CommonDialog control, then use the following code in a savebutton.
VB Code:
With CommonDialog1
.InitDir = "C:"
.FileName = "MyFile.txt"
.Filter = "Text File (*.txt)|*.txt"
.DialogTitle = "Locate where you want to save your text file"
.ShowSave
Open .FileName For Output Lock Read As #1
Print #1, Text1.Text & vbNullChar
Close #1
End With
Artificial Intelligence At War! - The best game of its genre Program your own robot and watch it fight in 3d! Droidarena 3
If I have been useful, please Rate My Post
Support FireFox -
Microsoft Visual Studio .NET Professional 2003
Microsoft Visual Studio 6, Enterprise Edition
Microsoft Windows XP Professional, Service Pack 2
how would i do loadbutton then?
thanks alot for that one ^^
edit*
heres what i got:
Code:
Private Sub Load_Click()
With CommonDialog1
.InitDir = "C:"
.FileName = ""
.Filter = "Text File (*.txt)|*.txt"
.DialogTitle = "Load file:"
.Showload
Open .FileName For Input As #1
Print #1, Text1.Text & vbNullChar
Text1.Text = Input(LOF(ff), #ff)
Close #1
End With
End Sub
This is what I use. I have a Common Dialog Control by itself on a form that is small. I use it for all the dialogs in my app. I subclass it like shown. This is when clicking on a textbox, it puts the selected filename in the textbox.
The same dialog works for printing, saving, and everything else.
never mind. I'll upload it. the label is where I move it to. you could substitute the button, or a label or whatever you want. even 0,0
it just moves the new form.
unzip it to your program directory, and you will have the frmCommonDialog.frm
Just right click in the properties area (where the forms are) and click ADD FORM, then click existing, then double-click on my form. Then it will be in your program. Then save it so that it will be in there in the future.
Don't you have Option Explicit in all modules? And Compie on Demand?
That would show the error. Do you have all variables defined? It sounds like you misspelled a module name (function or subroutine) they should be easy to check. btw - you are using the Common Dialog.
Oh. in my form, it is going to move the common dialog control right next to the label! Oops. forgot about that. Just pick a control on your form that you want the Common Dialog to appear next to. Then set the x and y of the new form to someone close to the control
(use any control that you want)
x = mycontrol.Left + mycontrol.Width
y = mycontrol.Top
what would that do/how do i use them..(if its something besides the obvious <<)
edit**
figured that out..
but it seems what happends is this:
it saves the file and adds 1 line of {enter} then a few spaces
that gives the error..
once i delete all the spaces it loads it and stuff..
anyone know whats wrong?
take out vbnullchar. its for strings that have to have the null character (like some API's must have)
to resize, just use the form.width and form.height. I'm not good at doing it. If the for is 400, the text box is 325 to 350 but if it is
only 200, then textbox is only 125 to 140 or so.
I think you have to use a Rich Text Box to get any fancy formatting. You can choose the font, but that's about it for the listbox. Even MSN is a RTB. Word is also a RTB. It's really the only way to do this. Pretty heavy stuff.
okay, 2 questions
how do i make the scrollbar? the scrollbars thing doesnt do squat..
also, it saves to the text box, but say i type this:
Yay im happy.aoscnmd a sdf.
this will come up upon load:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs17 Yay im happy.aoscnmd a sdf.
\par }
hmm..you didnt tell me what your variabled were so i did this:
Code:
Private Sub load_Click()
Dim realpath As Variant
Dim rtbReceipt As Variant
With CommonDialog1
On Error Resume Next
.Filter = "Rich Text File (*.rtf)|*.rtf"
.InitDir = "c:\"
.ShowOpen
.CancelError = False
End With
Open CommonDialog1.FileName For Input As #1
rtbReceipt.LoadFile realpath & "ReceiptFile.rtf" = Input$(LOF(1), #1)
Close #1
End Sub
i dont understand how to get the rtbReceipt.LoadFile realpath & "ReceiptFile.rtf" into my textbox
sorry. you over-complicated things. the rtbreceipt is my richtextbox. change it to your own. i don't load the filename, it is supplied by my program. you would do the same thing that you had before, but change the file extension to rtf.