Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Opening text files with vb6

I want to populate a textbox on screen upon loading a form. I have the code to parse the text working.

I still have two problems.

1) How can I check to see if the file is still in the working directory where it was installed? The user should not have re/moved it, but I can't control my users.

2) Using the common dialog controls, how do I handle the situation where the user clicks 'Cancel' instead of opening the file?

All help greatly appreciated.


Comments

  • : I want to populate a textbox on screen upon loading a form. I have the code to parse the text working.

    : I still have two problems.

    : 1) How can I check to see if the file is still in the working directory where it was installed? The user should not have re/moved it, but I can't control my users.

    : 2) Using the common dialog controls, how do I handle the situation where the user clicks 'Cancel' instead of opening the file?

    : All help greatly appreciated.


    Hi Frank,

    You can check to see if a file exists with this line:


    If Dir$("C:YourPathYourFileName") = "" then msgbox ("File does not exist")

    If Dir$("C:YourPathYourFileName") <> "" then msgbox ("File does exist")


    With input boxes, if the user presses cancel, then nothing or an empty string is returned, I'm not sure which.

    So in your code if you had an input box and the user clicked Cancel, your code would look something like this:


    x = InputBox ("Enter Criteria")

    If x = "" then exit sub 'or whatever you want it to do here.


    Hope that will help


    Cheers!

    Albert





  • : I want to populate a textbox on screen upon loading a form. I have the code to parse the text working.

    : I still have two problems.

    : 1) How can I check to see if the file is still in the working directory where it was installed? The user should not have re/moved it, but I can't control my users.

    : 2) Using the common dialog controls, how do I handle the situation where the user clicks 'Cancel' instead of opening the file?

    : All help greatly appreciated.


    Hi Frank,

    You can check to see if a file exists with this line:


    If Dir$("C:YourPathYourFileName") = "" then msgbox ("File does not exist")

    If Dir$("C:YourPathYourFileName") <> "" then msgbox ("File does exist")


    With input boxes, if the user presses cancel, then nothing or an empty string is returned, I'm not sure which.

    So in your code if you had an input box and the user clicked Cancel, your code would look something like this:


    x = InputBox ("Enter Criteria")

    If x = "" then exit sub 'or whatever you want it to do here.


    Hope that will help


    Cheers!

    Albert





  • : I want to populate a textbox on screen upon loading a form. I have the code to parse the text working.

    : I still have two problems.

    : 1) How can I check to see if the file is still in the working directory where it was installed? The user should not have re/moved it, but I can't control my users.

    : 2) Using the common dialog controls, how do I handle the situation where the user clicks 'Cancel' instead of opening the file?

    : All help greatly appreciated.


    All CommonDialogBoxes have a member called CancelError. If you set this to true, the Box will generate an error every time the user selects cancel. Now write an error-handler around your Box's Open-Call and put all the code you want to execute on Cancel into this error-handler.

    Error-Handlers are set up by using 'On Error Goto'. Do not forget to switch your err-handler off after using the dialog.


    If you have questions concerning err-handling or dialogs or need examples, send me a mail.


    -nv




  • Shawn CarterShawn Carter Member Posts: 0

    ________ ( http://forcoder.org ) free video tutorials and ebooks about || Python, Visual Basic .NET, Delphi, Assembly, Go, PL/SQL, R, Perl, C#, MATLAB, Scratch, PHP, Objective-C, Ruby, C++, C, Swift, JavaScript, Visual Basic, Java Hack, Dart, Lisp, VBScript, Alice, ML, Rust, D, Clojure, Kotlin, Fortran, F#, COBOL, Erlang, Apex, SAS, FoxPro, Bash, LabVIEW, Crystal, Julia, Ada, Scheme, Logo, Lua, Scala, Awk, ABAP, Transact-SQL, Prolog || _

Sign In or Register to comment.