[RESOLVED] Open file in textbox
Hi again! :wave:
I need help with opening a textfile into a textbox...I thought I maybe could do something like this:
VB Code:
Open "c:/test.txt" For Input As #1
Do Until 8 = 5
On Error GoTo ready
Input #1, newline
Text1.Text = Text1 & vbCrLf & newline
Loop
ready:
Close
But as you understand everything that's in Text1 goes on one line and the newline thing goes on another...but I want every new input to go on a new line...do you understand what I'm looking for? :ehh:
Please help! :(
//Alex
Re: [RESOLVED] Open file in textbox
Now, cyber_alex, put them both together in one Sub the can perform saving and loading
VB Code:
Private Sub SaveLoadTextBox(pstrOperation As String, pstrFileName As String)
Select Case pstrOperation
Case "save"
'run HanneSThEGreaT code
Case "load"
'run bushmobiles code
End Select
End Sub
Private Sub cmdSave_Click()
SaveLoad "save", "c:\cyber_alex.txt"
End Sub
Private Sub Form_Load()
SaveLoad "load", c:\cyber_alex.txt"
End Sub
Re: [RESOLVED] Open file in textbox
That snippet would load the file into a string then put that string into a textbox...is that what you mean? If not, explain further plz :-)
Re: [RESOLVED] Open file in textbox
let's say you have a gui , and on this gui, u have a textbox , combo boxes...when you compile...you get your form loaded... you want to input filename in the textbox...and then store this string to pass in another parameter or write to a text file , i am not sure how this information is stored actually! :(
Re: [RESOLVED] Open file in textbox
Ah, you want the FILENAME to tell the program what file to open and that file to be stored in a string?
VB Code:
Dim sText As String
Open txtFile.text For Input As #1
sText = Input(LOF(1), #1)
Close #1
That would open the location stored in textbox txtFile and write it to sText (string). If you're doing a lot of loading and saving, I suggest you replace all #1 with #fre and at the start (after the Dim) put fre=freefile (which basically works out the next free file number to use)
Re: [RESOLVED] Open file in textbox
hi smUX, actually this question here is pretty related to the other question i have about stored procedures...that you answered...let me think this through and explain it more clearly as to what i'm trying to do. thanks so far..
Re: [RESOLVED] Open file in textbox
seems like this thread just woke up again! :lol:
Re: [RESOLVED] Open file in textbox
Quote:
Originally Posted by smUX
Ah, you want the FILENAME to tell the program what file to open and that file to be stored in a string?
VB Code:
Dim sText As String
Open txtFile.text For Input As #1
sText = Input(LOF(1), #1)
Close #1
That would open the location stored in textbox txtFile and write it to sText (string). If you're doing a lot of loading and saving, I suggest you replace all #1 with #fre and at the start (after the Dim) put fre=freefile (which basically works out the next free file number to use)
yes, i want that. But i've changed my form so there are two options. I have added from menu Editor, the "file" so that i can go to open and select the file i want to store. So with this GUI interface, what i'm getting is, i don't need to make these events like the SQL statements i see in that code from the link i showed you? I would do it just as vb scripts that i've been doing? I got confused when my coworker said he'll do stored procedures...
i was thinking if i would have to wait on his stored procedures to put in my program. But if i'm not really dealing with the DB (not my part) then i dont need to worry about the sql statements, right?? because there are no "add", "delete", "search"...commands in my GUI interface...
Re: [RESOLVED] Open file in textbox
Try setting the textbox as multiline, the two boxes are the VbCrLf at the end of each line :-)
Note: If it *IS* multiline, copy one of the black boxes and go to immediate window then type "print asc("X")" (replace the X with the black box) and tell us the value :-)
Re: [RESOLVED] Open file in textbox
Quote:
Originally Posted by smUX
Try setting the textbox as multiline, the two boxes are the VbCrLf at the end of each line :-)
Note: If it *IS* multiline, copy one of the black boxes and go to immediate window then type "print asc("X")" (replace the X with the black box) and tell us the value :-)
That fixed it, thank you.
Also, in my code there is this line:
VB Code:
TerminateProcess ("notepad.exe")
How do I make it so that the TerminateProcess runs and will close every single process listed within the text file, rather than just the single one entered?
Re: [RESOLVED] Open file in textbox
Ah, this is a good question...not much of a challenge, but a good question :-)
First thing you need to do is split the string up into an array...simple matter of doing
VB Code:
process = split (textinput, vbcrlf)
which assumes the text file input was saved to textinput (rename as appropriate. Now in process() you have a list of the programs (I assume that's what you mean) so you now need to know how many there are...a simple ubound(process()) will tell you this...then call using a for/next loop
VB Code:
for proc = 0 to ubound(process())
TerminateProcess (process(proc))
next proc
I can't guarantee that works 100% as I'm writing from memory, without "terminateprocess()" function and without VB, but should only need minor tweaks :-)
Re: [RESOLVED] Open file in textbox
Quote:
Originally Posted by smUX
Ah, this is a good question...not much of a challenge, but a good question :-)
First thing you need to do is split the string up into an array...simple matter of doing
VB Code:
process = split (textinput, vbcrlf)
which assumes the text file input was saved to textinput (rename as appropriate. Now in process() you have a list of the programs (I assume that's what you mean) so you now need to know how many there are...a simple ubound(process()) will tell you this...then call using a for/next loop
VB Code:
for proc = 0 to ubound(process())
TerminateProcess (process(proc))
next proc
I can't guarantee that works 100% as I'm writing from memory, without "terminateprocess()" function and without VB, but should only need minor tweaks :-)
I haven't opened the text file yet on this form, so how do I open it while saving the contents into an array? I've never used arrays before with the exception of a small animation.
Re: [RESOLVED] Open file in textbox
You originally quoted a piece of code:
VB Code:
Dim sText As String
Open "C:\test.txt" For Input As #1
sText = Input(LOF(1), #1)
Close #1
Text1.Text = sText
Simply remove the last line, and in my code where I put "textinput" you put "sText"...put that file load code just before my split() line and it should load, split then action each terminateprocess :-)
Re: [RESOLVED] Open file in textbox
Quote:
Originally Posted by smUX
You originally quoted a piece of code:
VB Code:
Dim sText As String
Open "C:\test.txt" For Input As #1
sText = Input(LOF(1), #1)
Close #1
Text1.Text = sText
Simply remove the last line, and in my code where I put "textinput" you put "sText"...put that file load code just before my split() line and it should load, split then action each terminateprocess :-)
That was for a form where the process list could be edited, on this form the text is not loaded into a text box. Is there a way to do this without a text box, or would I need to just make an invisible one?
Also, don't I need to define the process array somewhere/how?
Re: [RESOLVED] Open file in textbox
Quote:
Originally Posted by gt123
That was for a form where the process list could be edited, on this form the text is not loaded into a text box. Is there a way to do this without a text box, or would I need to just make an invisible one?
I don't fully understand. If you want the process list *edited* then the processes that are listed in the text box to be terminated you leave the load file bit as is but instead change MY code to take its data from text1.text (or whatever you call the text box) rather than inputtext.
If you don't need the textbox, the previous code I told you should work (where you work directly from the string to the array). The text data is just as usable whether it's in a string or a textbox :-)
Quote:
Originally Posted by gt123
Also, don't I need to define the process array somewhere/how?
Nope, split() does that for you :-)
Re: [RESOLVED] Open file in textbox
I managed to adapt it slightly and it now works, the code is as follows:
VB Code:
Private Sub EndAll()
Dim sText As String
Dim Process() As String
Dim proc As Integer
Open App.Path & "\processlist.txt" For Input As #1
sText = Input(LOF(1), #1)
Close #1
Process = Split(sText, vbCrLf)
For proc = 0 To UBound(Process())
TerminateProcess (Process(proc))
Next proc
End Sub
Thanks alot. :)
Re: [RESOLVED] Open file in textbox
Looks about right...dunno why you're getting processes through a text file though, I'm sure other people here can tell you how to get a list of running processes directly within VB :-)
Re: [RESOLVED] Open file in textbox
Quote:
Originally Posted by smUX
Looks about right...dunno why you're getting processes through a text file though, I'm sure other people here can tell you how to get a list of running processes directly within VB :-)
The program is to terminate a list of specified processes via a button click or hotkey. The text file just contains that list of processes to be closed.
Re: [RESOLVED] Open file in textbox
Ah, then that should work perfectly :-)
Although I have one suggestion:
VB Code:
Open App.Path & "\processlist.txt" For Input As #1
sText = Input(LOF(1), #1)
Close #1
Change it to
VB Code:
fre = freefile
Open App.Path & "\processlist.txt" For Input As #fre
sText = Input(LOF(1), #fre)
Close #fre
And of course declare fre as integer. This ensures that if you have any other files opened it doesn't crash as it opens using a free handle:-)
Re: [RESOLVED] Open file in textbox
Quote:
Originally Posted by smUX
Ah, then that should work perfectly :-)
Although I have one suggestion:
VB Code:
Open App.Path & "\processlist.txt" For Input As #1
sText = Input(LOF(1), #1)
Close #1
Change it to
VB Code:
fre = freefile
Open App.Path & "\processlist.txt" For Input As #fre
sText = Input(LOF(1), #fre)
Close #fre
And of course declare fre as integer. This ensures that if you have any other files opened it doesn't crash as it opens using a free handle:-)
Done, thanks :)
Re: [RESOLVED] Open file in textbox
Glad I could help...I may be a bad programmer at times but I've a wealth of knowledge about certain aspects of programming...you know the saying, Jack of all trades and master of none :-)
Re: [RESOLVED] Open file in textbox
Quote:
Originally Posted by smUX
Glad I could help...I may be a bad programmer at times but I've a wealth of knowledge about certain aspects of programming...you know the saying, Jack of all trades and master of none :-)
Well, you managed to help me just fine. The only thing i'm wondering about is having a customisable hotkey. It's currently set to F10 using the following code:
VB Code:
Private Sub tmrHotkey_Timer()
'Responds to the hotkey F10 and runs the sub EndAll
Dim HotOnceOnly As Boolean
If Not GetAsyncKeyState(121) = 0 Then
If (HotOnceOnly = False) Then
EndAll
End If
HotOnceOnly = True
ElseIf GetAsyncKeyState(121) = 0 Then HotOnceOnly = False 'Can you else if only one hotkey per timer
End If
End Sub
Does anyone have any idea how I can change this to a key combination within the code, or have the option to customize the hotkey completely?