Results 1 to 36 of 36

Thread: [RESOLVED] Open file in textbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Location
    Sweden
    Posts
    173

    Resolved [RESOLVED] Open file in textbox

    Hi again!

    I need help with opening a textfile into a textbox...I thought I maybe could do something like this:

    VB Code:
    1. Open "c:/test.txt" For Input As #1
    2.     Do Until 8 = 5
    3.         On Error GoTo ready
    4.         Input #1, newline
    5.         Text1.Text = Text1 & vbCrLf & newline
    6.     Loop
    7. ready:
    8. 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?

    Please help!

    //Alex
    Last edited by cyber_alex; May 25th, 2006 at 04:38 AM.
    Please Help Us To Save Ana

    You never fail before you stop trying!
    ______________________________
    If I manage to say something good...please reputate
    ______________________________
    ________

    Links:
    Intellithing
    Digitala.nu
    Norrköpings Goklubb
    WoW Trade Center

  2. #2
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: Open file in textbox

    VB Code:
    1. Private Sub itmOpen_Click()
    2.     Dim strFileName As String   'String of file to open
    3.     Dim strText As String       'Contents of file
    4.     Dim strFilter As String     'Common Dialog filter string
    5.     Dim strBuffer As String     'String buffer variable
    6.     Dim FileHandle%             'Variable to hold file handle
    7.    
    8.     'Set the Common Dialog filter
    9.     strFilter = "Text (*.txt)|*.txt|All Files (*.*)|*.*"
    10.     cdMain.Filter = strFilter
    11.    
    12.     'Open the common dialog
    13.     cdMain.ShowOpen
    14.    
    15.    
    16.     'Make sure the retrieved filename is not a blank string
    17.     If cdMain.filename <> "" Then
    18.        
    19.         'If it is not blank open the file
    20.         strFileName = cdMain.filename
    21.        
    22.         'Get a free file handle and assign it to the file handle variable
    23.         FileHandle% = FreeFile
    24.        
    25.         'Open the file
    26.         Open strFileName For Input As #FileHandle%
    27.        
    28.         'Make the mouse cursor an hourglass
    29.         MousePointer = vbHourglass
    30.        
    31.         'Traverse the lines of the file
    32.         Do While Not EOF(FileHandle%) ' Check for end of file.
    33.            
    34.             'Read a line of the file
    35.             Line Input #FileHandle%, strBuffer    ' Read line of data.
    36.            
    37.             'Add the line from the output buffer to the text string
    38.             strText = strText & strBuffer & vbCrLf
    39.         Loop
    40.        
    41.         'Change the mousepointer back to the arrow
    42.         MousePointer = vbDefault
    43.        
    44.         'Close the file once you have had your way with it
    45.         Close #FileHandle%
    46.        
    47.         'Assign the retrieved text to the text box
    48.         txtMain.Text = strText
    49.        
    50.         'Put the file name in the form caption
    51.         frmMain.Caption = "Text Editor- [" & strFileName & "]"
    52.     End If
    53. End Sub
    You need a commondialog control in there as well
    VB.NET MVP 2008 - Present

  3. #3
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Open file in textbox

    VB Code:
    1. Dim sText As String
    2. Open "C:\test.txt" For Input As #1
    3.     sText = Input(LOF(1), #1)
    4. Close #1
    5. Text1.Text = sText

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Location
    Sweden
    Posts
    173

    Re: Open file in textbox

    I did what you said and adjusted my code a bit...and it works perfect!!

    Tnx a lot HanneSThEGreaT!!
    I'll reputate you at once!
    Please Help Us To Save Ana

    You never fail before you stop trying!
    ______________________________
    If I manage to say something good...please reputate
    ______________________________
    ________

    Links:
    Intellithing
    Digitala.nu
    Norrköpings Goklubb
    WoW Trade Center

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Location
    Sweden
    Posts
    173

    Re: Open file in textbox

    wow!! Your stuff was even better bushmobile! (no offense HanneSThEGreaT )

    How do I save the stuff that is in the textbox now?
    Please Help Us To Save Ana

    You never fail before you stop trying!
    ______________________________
    If I manage to say something good...please reputate
    ______________________________
    ________

    Links:
    Intellithing
    Digitala.nu
    Norrköpings Goklubb
    WoW Trade Center

  6. #6
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: Open file in textbox

    Quote Originally Posted by cyber_alex
    wow!! Your stuff was even better bushmobile! (no offense HanneSThEGreaT )
    None taken

    Save:
    VB Code:
    1. Private Sub itmSave_Click()
    2.     Dim strFileName As String   'String of file to open
    3.     Dim strText As String       'Contents of file
    4.     Dim strFilter As String     'Common Dialog filter string
    5.     Dim strBuffer As String     'String buffer variable
    6.     Dim FileHandle%             'Variable to hold file handle
    7.    
    8.     'Set the Common Dialog filter
    9.     strFilter = "Text (*.txt)|*.txt|All Files (*.*)|*.*"
    10.     cdMain.Filter = strFilter
    11.    
    12.     'Open the common dialog in save mode
    13.     cdMain.ShowSave
    14.    
    15.     'Make sure the retrieved filename is not a blank string
    16.     If cdMain.filename <> "" Then
    17.         'If it is not blank open the file
    18.         strFileName = cdMain.filename
    19.        
    20.         'Assign a value to the text variable
    21.         strText = txtMain.Text
    22.        
    23.         'Get a free file handle and assign it to the file handle variable
    24.         FileHandle% = FreeFile
    25.        
    26.         'Open a file for writing
    27.         Open strFileName For Output As #FileHandle%
    28.        
    29.         'Set an hour glass cursor just in case it takes a while
    30.         MousePointer = vbHourglass
    31.        
    32.         'Do the write
    33.         Print #FileHandle%, strText
    34.        
    35.         'Reset the cursor to the Windows default.
    36.         MousePointer = vbDefault
    37.        
    38.         'Close the file once you have had your way with it
    39.         Close #FileHandle%
    40.     End If
    41.    
    42. End Sub
    VB.NET MVP 2008 - Present

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Open file in textbox

    VB Code:
    1. Open "C:\output.txt" For Output As #1
    2.     Print #1, Text1.Text
    3. Close #1

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Location
    Sweden
    Posts
    173

    Re: Open file in textbox

    hmm..better wait a minute or two to see if bushmobile comes up with a tiny version of your code...
    Please Help Us To Save Ana

    You never fail before you stop trying!
    ______________________________
    If I manage to say something good...please reputate
    ______________________________
    ________

    Links:
    Intellithing
    Digitala.nu
    Norrköpings Goklubb
    WoW Trade Center

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Location
    Sweden
    Posts
    173

    Re: Open file in textbox

    HAHA!! I knew it!! Your so funny lol:
    Please Help Us To Save Ana

    You never fail before you stop trying!
    ______________________________
    If I manage to say something good...please reputate
    ______________________________
    ________

    Links:
    Intellithing
    Digitala.nu
    Norrköpings Goklubb
    WoW Trade Center

  10. #10
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Open file in textbox

    Quote Originally Posted by cyber_alex
    hmm..better wait a minute or two to see if bushmobile comes up with a tiny version of your code...
    this time the code's are pretty much identical, i just have bothered putting the commondialog stuff in.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Location
    Sweden
    Posts
    173

    Re: Open file in textbox

    Tnx both of you...my program runs perfect now!
    Please Help Us To Save Ana

    You never fail before you stop trying!
    ______________________________
    If I manage to say something good...please reputate
    ______________________________
    ________

    Links:
    Intellithing
    Digitala.nu
    Norrköpings Goklubb
    WoW Trade Center

  12. #12
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: Open file in textbox

    This is a funny thread
    But there's actually a lesson that can be learnt here..

    Cyber_Alex, so you see that there are always multiple ways to solve one problem. If you were to work within a group, and the group was given a certain task to do. Everyone within that group, will most probably come up with different ideas / implementations to get the same result
    VB.NET MVP 2008 - Present

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Location
    Sweden
    Posts
    173

    Re: Open file in textbox

    yeah, your right...that's what makes programming an art!

    ..this really has been a touching thread...
    Please Help Us To Save Ana

    You never fail before you stop trying!
    ______________________________
    If I manage to say something good...please reputate
    ______________________________
    ________

    Links:
    Intellithing
    Digitala.nu
    Norrköpings Goklubb
    WoW Trade Center

  14. #14
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] Open file in textbox

    Now, cyber_alex, put them both together in one Sub the can perform saving and loading
    VB Code:
    1. Private Sub SaveLoadTextBox(pstrOperation As String, pstrFileName As String)
    2.  
    3. Select Case pstrOperation
    4.  
    5.       Case "save"
    6.          'run HanneSThEGreaT code
    7.       Case "load"
    8.          'run bushmobiles code
    9. End Select
    10. End Sub
    11.  
    12. Private Sub cmdSave_Click()
    13. SaveLoad "save", "c:\cyber_alex.txt"
    14. End Sub
    15.  
    16. Private Sub Form_Load()
    17. SaveLoad "load", c:\cyber_alex.txt"
    18. End Sub

  15. #15
    Lively Member
    Join Date
    Feb 2004
    Posts
    65

    Re: Open file in textbox

    Quote Originally Posted by bushmobile
    VB Code:
    1. Dim sText As String
    2. Open "C:\test.txt" For Input As #1
    3.     sText = Input(LOF(1), #1)
    4. Close #1
    5. Text1.Text = sText
    is this the same as inputting to the textbox? i created a form with combo boxes and textbox. when the program runs, the textbox should be a field for input. is this the same?

  16. #16
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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 :-)

  17. #17
    Lively Member
    Join Date
    Feb 2004
    Posts
    65

    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!

  18. #18
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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:
    1. Dim sText As String
    2. Open txtFile.text For Input As #1
    3.     sText = Input(LOF(1), #1)
    4. 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)

  19. #19
    Lively Member
    Join Date
    Feb 2004
    Posts
    65

    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..

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Location
    Sweden
    Posts
    173

    Re: [RESOLVED] Open file in textbox

    seems like this thread just woke up again!
    Please Help Us To Save Ana

    You never fail before you stop trying!
    ______________________________
    If I manage to say something good...please reputate
    ______________________________
    ________

    Links:
    Intellithing
    Digitala.nu
    Norrköpings Goklubb
    WoW Trade Center

  21. #21
    Lively Member
    Join Date
    Feb 2004
    Posts
    65

    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:
    1. Dim sText As String
    2. Open txtFile.text For Input As #1
    3.     sText = Input(LOF(1), #1)
    4. 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...

  22. #22
    Addicted Member gt123's Avatar
    Join Date
    May 2006
    Location
    United Kingdom
    Posts
    145

    Re: Open file in textbox

    Quote Originally Posted by bushmobile
    VB Code:
    1. Dim sText As String
    2. Open "C:\test.txt" For Input As #1
    3.     sText = Input(LOF(1), #1)
    4. Close #1
    5. Text1.Text = sText
    Hi there,

    I used this code to try and read a text file with multiple lines into a text box for display on multiple lines. However, the text that was loaded appears with the first line followed by two black squares and then the second line, all displayed on the first line of the text box.

    How do I fix this so that both lines in the text file do actually appear on separate lines in the text box?

  23. #23
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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 :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  24. #24
    Addicted Member gt123's Avatar
    Join Date
    May 2006
    Location
    United Kingdom
    Posts
    145

    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:
    1. 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?

  25. #25
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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:
    1. 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:
    1. for proc = 0 to ubound(process())
    2. TerminateProcess (process(proc))
    3. 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 :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  26. #26
    Addicted Member gt123's Avatar
    Join Date
    May 2006
    Location
    United Kingdom
    Posts
    145

    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:
    1. 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:
    1. for proc = 0 to ubound(process())
    2. TerminateProcess (process(proc))
    3. 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.

  27. #27
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: [RESOLVED] Open file in textbox

    You originally quoted a piece of code:
    VB Code:
    1. Dim sText As String
    2. Open "C:\test.txt" For Input As #1
    3.     sText = Input(LOF(1), #1)
    4. Close #1
    5. 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 :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  28. #28
    Addicted Member gt123's Avatar
    Join Date
    May 2006
    Location
    United Kingdom
    Posts
    145

    Re: [RESOLVED] Open file in textbox

    Quote Originally Posted by smUX
    You originally quoted a piece of code:
    VB Code:
    1. Dim sText As String
    2. Open "C:\test.txt" For Input As #1
    3.     sText = Input(LOF(1), #1)
    4. Close #1
    5. 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?
    Last edited by gt123; Jun 10th, 2006 at 11:31 AM.

  29. #29
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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 :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  30. #30
    Addicted Member gt123's Avatar
    Join Date
    May 2006
    Location
    United Kingdom
    Posts
    145

    Re: [RESOLVED] Open file in textbox

    I managed to adapt it slightly and it now works, the code is as follows:

    VB Code:
    1. Private Sub EndAll()
    2.  
    3.     Dim sText As String
    4.     Dim Process() As String
    5.     Dim proc As Integer
    6.  
    7.     Open App.Path & "\processlist.txt" For Input As #1
    8.         sText = Input(LOF(1), #1)
    9.     Close #1
    10.  
    11.     Process = Split(sText, vbCrLf)
    12.  
    13.     For proc = 0 To UBound(Process())
    14.         TerminateProcess (Process(proc))
    15.     Next proc
    16.    
    17. End Sub

    Thanks alot.

  31. #31
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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 :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  32. #32
    Addicted Member gt123's Avatar
    Join Date
    May 2006
    Location
    United Kingdom
    Posts
    145

    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.

  33. #33
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: [RESOLVED] Open file in textbox

    Ah, then that should work perfectly :-)

    Although I have one suggestion:

    VB Code:
    1. Open App.Path & "\processlist.txt" For Input As #1
    2. sText = Input(LOF(1), #1)
    3. Close #1

    Change it to

    VB Code:
    1. fre = freefile
    2. Open App.Path & "\processlist.txt" For Input As #fre
    3. sText = Input(LOF(1), #fre)
    4. 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:-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  34. #34
    Addicted Member gt123's Avatar
    Join Date
    May 2006
    Location
    United Kingdom
    Posts
    145

    Re: [RESOLVED] Open file in textbox

    Quote Originally Posted by smUX
    Ah, then that should work perfectly :-)

    Although I have one suggestion:

    VB Code:
    1. Open App.Path & "\processlist.txt" For Input As #1
    2. sText = Input(LOF(1), #1)
    3. Close #1

    Change it to

    VB Code:
    1. fre = freefile
    2. Open App.Path & "\processlist.txt" For Input As #fre
    3. sText = Input(LOF(1), #fre)
    4. 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

  35. #35
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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 :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  36. #36
    Addicted Member gt123's Avatar
    Join Date
    May 2006
    Location
    United Kingdom
    Posts
    145

    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:
    1. Private Sub tmrHotkey_Timer()
    2.    'Responds to the hotkey F10 and runs the sub EndAll
    3.    
    4.    Dim HotOnceOnly As Boolean
    5.     If Not GetAsyncKeyState(121) = 0 Then
    6.         If (HotOnceOnly = False) Then
    7.  
    8.             EndAll
    9.  
    10.         End If
    11.         HotOnceOnly = True
    12.     ElseIf GetAsyncKeyState(121) = 0 Then HotOnceOnly = False 'Can you else if only one hotkey per timer
    13.     End If
    14. 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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width