Results 1 to 13 of 13

Thread: Opening a file

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715

    Wink

    Ok I'm gonna make 2 exe's on the first one this is what its gonna do:

    Code:
    Private Sub Command1_Click()
    Open "c:\a.dat" For Output As #1
    Write #1, txtfn.Text, txtln.Text, txtcp.Text
    Close #1
    End Sub

    then I got another EXE that tries to open C:\a.dat and put

    the stuff I saved in three diffrent labels:

    lblfn
    lblln
    lnlcp

    can some one please tell me how to open it?
    and put it in labels

    thanks in advance
    NXSupport - Your one-stop source for computer help

  2. #2
    Guest
    the property that relates to the text inside a label is:

    Label2.Caption

    do you want to overwrite the first file, or add to the end of it? If you want to add to the end, use the same method except change the word "Output" to "Append".

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    I just want to save it in the first exe, and open it in the 2nd

    basicly, nothing is written to the file from the 2nd exe

    can you please give me the code? please cause I tryed diffrent ways of getting it to work, and no success
    NXSupport - Your one-stop source for computer help

  4. #4
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Here you go. Your second program should contain the following code. This example assumes you have three labels and a command button on the form.

    Code:
    Private Sub Command1_Click()
    
    Dim strItem1 As String
    Dim strItem2 As String
    Dim strItem3 As String
    
    Open "c:\a.dat" For Input As #1
    Input #1, strItem1, strItem2, strItem3
    Close #1
    
    Label1.Caption = strItem1
    Label2.Caption = strItem2
    Label3.Caption = strItem3
    
    End Sub
    Note: The default property of a label is Caption, so the last 3 lines could be written as:
    Label1 = strItem1
    Label2 = strItem2
    Label3 = strItem3


    [Edited by BruceG on 07-10-2000 at 01:28 PM]
    "It's cold gin time again ..."

    Check out my website here.

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?> give it a shot..see what happens

    Code:
    Private Sub Command2_Click()
    dim intNum as integer
    dim myVar1 as string, myVar2 as string, myVar3 as string
    
    intnum = freefile
    
    Open "c:\a.dat" For Input As intnum
    input #1, myVar1, myVar2, myVar3
    label1.caption = myVar1
    label2.caption = myVar2
    label3.caption = MyVar3
    Close #intNum
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715

    Re: <?> give it a shot..see what happens

    the stuff isn't numbers, to it woun't work Joe
    NXSupport - Your one-stop source for computer help

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715

    Wink THANKS

    thanks alot bruce!!!
    NXSupport - Your one-stop source for computer help

  8. #8
    Guest
    who said it has to be numbers, and it does actually work.

    Other people are sometimes right!

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    ok, sorry, but bruces way worked, and he did spost it first, sorry
    NXSupport - Your one-stop source for computer help

  10. #10
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    You're welcome, dimava.

    FYI, dimava, Wayne (HeSaidJoe) was not wrong. He used the integer to declare a file handle to use with the Open statement, first by setting it to FreeFile, which is a built-in VB function that returns an integer representing a free (available) file handle. This variable is then used in the Open statement (... as #intnum) instead of a literal value (... as #1).

    Wayne's technique is actually more professional, and is the technique I use for my professional apps.

    See ya.
    "It's cold gin time again ..."

    Check out my website here.

  11. #11
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    not a problem
    ...we are not in competition..
    I was typing while his went through..if
    it had been there I wouldn't have posted
    since our code is basically the same..
    except I use FreeFile which you should use
    instead of numbers...Look it up...

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    ok, after I posted that I didn't need numbers, I reviewed the code again, and realized that I was wrong, because the first time I didn't look through the code carefully
    NXSupport - Your one-stop source for computer help

  13. #13
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Thank you Bruce...:>
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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