Results 1 to 20 of 20

Thread: Retrieve data from a text file and display in a textbox.

  1. #1

    Thread Starter
    Member seraphicmortal's Avatar
    Join Date
    May 2005
    Posts
    56

    Resolved Retrieve data from a text file and display in a textbox.

    Hi! I hope someone could help me with this.

    I want to retrieve data saved in .pnp file and display it in the same txtboxes and same order as it was saved.

    My current code is:

    VB Code:
    1. (globalvar.bas)
    2. Option Explicit
    3.  
    4. Public pn1 As New partnamelist
    5.  
    6. (frm_field)
    7. Private Sub fieldupload()
    8.     With pn1 'I made a class named partnamelist having these 4 properties: part, description, quantity, and version
    9.         .part = txt_part.text
    10.         .description = txt_desc.Text
    11.         .quantity = txt_qty.Text
    12.         .version = txt_version.Text
    13.     End With
    14. End Sub
    15.  
    16. Private Sub cmd_apply_Click()
    17. dim filename as string    
    18.     If Len(txt_part.text) = 0 And _
    19.        Len(txt_desc.Text) = 0 And _
    20.        Len(txt_qty.Text) = 0 And _
    21.        Len(txt_version.Text) = 0 Then
    22.         MsgBox "please enter the necessary values."
    23.         txt_part.setfocus
    24.     Else
    25.         fieldupload
    26.         filename = txt_filename.text 'Specified filename of the user
    27.         MsgBox ("Creating profile...  Please choose what directory to save your profile.")
    28.         frm_dir.Show vbModal
    29.     End If
    30. End Sub
    31.  
    32.  
    33. '(frm_dir)
    34.  
    35. Private Sub Form_Load()
    36.     txt_pnprofile.Text = frm_field.filename + ".pnp"     '--> "pnp" here in my example is my chosen extension.
    37. End Sub
    38.  
    39. Private Sub cmd_ok_Click()
    40.     txt_profilepath.Text = file1.Path & file1.FileName & "\" &  txt_plprofile.Text 'file1 is a file listbox btw
    41.         MsgBox "Saving " & txt_profilepath & " as new profile."
    42.         SaveProfile txt_profilepath.Text, pn1
    43.     profilepath = txt_profilepath.Text
    44. End Sub
    45.  
    46. Private Sub SaveProfile(WhatFile As String, TheProfile As namelist)
    47. Dim FreeFileHandle  As Integer
    48.  
    49.     FreeFileHandle = FreeFile
    50.     Open WhatFile For Output As FreeFileHandle
    51.     With TheProfile
    52.         Print #FreeFileHandle, "[Part] " & .part
    53.         Print #FreeFileHandle, "[Description] " & .description
    54.         Print #FreeFileHandle, "[Quantity] " & .quantity
    55.         Print #FreeFileHandle, "[Version] " & .version
    56.     End With
    57.     Close FreeFileHandle
    58. End Sub

    Output of egfile.pnp:
    [Description] b42
    [MakerCode] c65
    [PartnameCode] x32
    [Quantity] x75
    [SymbolicCode] q21

    After clicking RETRIEVE button, I want that b42 will be displayed in txt_description.text and so on and so forth.

    How do I do this? I don't know how to use Line Input # Statement as well.

    Anybody, pls. help.
    Last edited by seraphicmortal; May 23rd, 2005 at 12:02 AM. Reason: [RESOLVED]

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Retrieve data from a text file and display in a textbox.

    Have you tried soemthing like this:

    VB Code:
    1. (globalvar.bas)
    2. Option Explicit
    3.  
    4. Public pn1 As New partnamelist
    5.  
    6. (frm_field)
    7. Private Sub fieldupload()
    8.     With pn1 'I made a class named partnamelist having these 4 properties: part, description, quantity, and version
    9.         .part = txt_part.text
    10.         .description = txt_desc.Text
    11.         .quantity = txt_qty.Text
    12.         .version = txt_version.Text
    13.     End With
    14. End Sub
    15.  
    16. Private Sub cmd_apply_Click()
    17. dim filename as string    
    18.     If Len(txt_part.text) = 0 And _
    19.        Len(txt_desc.Text) = 0 And _
    20.        Len(txt_qty.Text) = 0 And _
    21.        Len(txt_version.Text) = 0 Then
    22.         MsgBox "please enter the necessary values."
    23.         txt_part.setfocus
    24.     Else
    25.         fieldupload
    26.         filename = txt_filename.text 'Specified filename of the user
    27.         MsgBox ("Creating profile...  Please choose what directory to save your profile.")
    28.         frm_dir.Show vbModal
    29.     End If
    30. End Sub
    31.  
    32.  
    33. '(frm_dir)
    34.  
    35. Private Sub Form_Load()
    36.     txt_pnprofile.Text = frm_field.filename + ".pnp"     '--> "pnp" here in my example is my chosen extension.
    37. End Sub
    38.  
    39. Private Sub cmd_ok_Click()
    40.     txt_profilepath.Text = file1.Path & file1.FileName & "\" &  txt_plprofile.Text 'file1 is a file listbox btw
    41.         MsgBox "Saving " & txt_profilepath & " as new profile."
    42.         SaveProfile txt_profilepath.Text, pn1
    43.     profilepath = txt_profilepath.Text
    44. End Sub
    45.  
    46. Private Sub SaveProfile(WhatFile As String, TheProfile As namelist)
    47. Dim FreeFileHandle  As Integer
    48.  
    49.     FreeFileHandle = FreeFile
    50.     Open WhatFile For Output As FreeFileHandle
    51.     With TheProfile
    52.         Print #FreeFileHandle, "[Part] " & .part
    53.         txt_part.Text = .part
    54.         Print #FreeFileHandle, "[Description] " & .description
    55.         txt_description.Text = .description
    56.         Print #FreeFileHandle, "[Quantity] " & .quantity
    57.         txt_quantity.Text = .quantity
    58.         Print #FreeFileHandle, "[Version] " & .version
    59.         txt_version.Text = .version
    60.     End With
    61.     Close FreeFileHandle
    62. End Sub


    Not shure but I think that should work

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  3. #3

    Thread Starter
    Member seraphicmortal's Avatar
    Join Date
    May 2005
    Posts
    56

    Unhappy Re: Function to retrieve data from a text file and display in a textbox.

    I wana know what function to use that would retrieve the data being inputted in the textbox (which is saved in a .pnp file)....

    Can anyone help?
    Last edited by seraphicmortal; May 22nd, 2005 at 08:49 PM. Reason: Changed the title

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Retrieve data from a text file and display in a textbox.

    Here is one way to do it:
    EDIT: It changed!

    VB Code:
    1. Private Sub LoadProfile(WhatFile As String, TheProfile As namelist)
    2. Dim FreeFileHandle  As Integer, A$,B() as String
    3.  
    4.     FreeFileHandle = FreeFile
    5.     Open WhatFile For Input As FreeFileHandle
    6.     With TheProfile
    7.         LineInput #FreeFileHandle, a ' "[Part] " & .part
    8.         b=split(a," ")
    9.         .part = b(1)
    10.         txt_part.Text = .part
    11.         LineInput #FreeFileHandle, a '  "[Description] " & .description
    12.         b=split(a," ")
    13.         .description = b(1)
    14.         txt_description.Text = .description
    15.         LineInput #FreeFileHandle, a '  "[Quantity] " & .quantity
    16.         b=split(a," ")
    17.         .quantity = b(1)
    18.         txt_quantity.Text = .quantity
    19.         LineInput #FreeFileHandle, a '  "[Version] " & .version
    20.         b=split(a," ")
    21.         .version = b(1)
    22.         txt_version.Text = .version
    23.     End With
    24.     Close FreeFileHandle
    25. End Sub

  5. #5

    Thread Starter
    Member seraphicmortal's Avatar
    Join Date
    May 2005
    Posts
    56

    Question Re: Retrieve data from a text file and display in a textbox.

    Hi! Dglienna, I tried your suggestion but even if I haven't compiled it yet, the lines below turns red.(what's the error in this?)

    VB Code:
    1. Private Sub LoadProfile(WhatFile As String, TheProfile As namelist)
    2. Dim FreeFileHandle  As Integer, A$,B() as String
    3.  
    4.     FreeFileHandle = FreeFile
    5.     Open WhatFile For Input As FreeFileHandle
    6.     With TheProfile
    7.         [COLOR=Red]LineInput #FreeFileHandle, a ' "[Part] " & .part[/COLOR]        
    8.         b=split(a," ")
    9.         .part = b(1)
    10.         txt_part.Text = .part
    11.         [COLOR=Red]LineInput #FreeFileHandle, a '  "[Description] " & .description[/COLOR]
    12.         b=split(a," ")
    13.         .description = b(1)
    14.         txt_description.Text = .description
    15.         [COLOR=Red]LineInput #FreeFileHandle, a '  "[Quantity] " & .quantity[/COLOR]
    16.         b=split(a," ")
    17.         .quantity = b(1)
    18.         txt_quantity.Text = .quantity
    19.         [COLOR=Red]LineInput #FreeFileHandle, a '  "[Version] " & .version[/COLOR]
    20.         b=split(a," ")
    21.         .version = b(1)
    22.         txt_version.Text = .version
    23.     End With
    24.     Close FreeFileHandle
    25. End Sub
    Last edited by seraphicmortal; May 22nd, 2005 at 10:26 PM. Reason: only line input is in red text.

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Retrieve data from a text file and display in a textbox.

    Sorry about that. I didn't test it first.
    VB Code:
    1. Line Input

    Just add a space to the lines in RED!

  7. #7

    Thread Starter
    Member seraphicmortal's Avatar
    Join Date
    May 2005
    Posts
    56

    Re: Retrieve data from a text file and display in a textbox.

    Oooh! My bad....didn't see that as well...hehehe =)

    I tried compiling it though after putting the space and it says
    Run Time Error '76':
    Path Not Found.

  8. #8
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Retrieve data from a text file and display in a textbox.

    You have to specifiy the path to the file you want to load when you call the procedure.

  9. #9

    Thread Starter
    Member seraphicmortal's Avatar
    Join Date
    May 2005
    Posts
    56

    Question Re: Retrieve data from a text file and display in a textbox.

    I did do that Baja.. Yet I don't understand why it says Path not Found.

    Let me walk you through.
    If a user clicks RETRIEVE button, it will go to a frm_dir (directory form), if the profile he wants exists....all he has to do is click the file and and press OK (by doing this, the user is specifying what file (profile) to be loaded, i think...). Then it will display
    txt_description.text = b42
    txt_MakerCode.text = c65
    txt_PartnameCode.text = x32
    txt_Quantity.text = x75
    txt_SymbolicCode.text = q21

    anyone, help me.
    Last edited by seraphicmortal; May 22nd, 2005 at 11:21 PM. Reason: corrected typographical errors

  10. #10
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Retrieve data from a text file and display in a textbox.

    What are you using to allow user to select the file, and how?

  11. #11
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Retrieve data from a text file and display in a textbox.

    The best solution to debug this would be to set a break point somewhere before the call of the procedure, and then use F8 key to step through the code line by line and see exactly what data get passed as the Path (WhatFile) parameter.

  12. #12

    Thread Starter
    Member seraphicmortal's Avatar
    Join Date
    May 2005
    Posts
    56

    Red face Re: Retrieve data from a text file and display in a textbox.

    OK button from the form directory (frm_dir).

    VB Code:
    1. Private Sub cmd_ok_Click()
    2.     txt_profilepath.Text = file1.Path & file1.FileName & "\" & txt_plprofile.Text
    3.  
    4. Select Case Me.Caption
    5.     Case "Save Profile"
    6.         If isFile(txt_profilepath.Text) Then
    7.             If MsgBox("File " & txt_profilepath & " exists.  Do you want to overwrite the current profile?{Y/N]", vbQuestion + vbYesNo, App.ProductName + " Prompt") = vbYes Then
    8.                 SaveProfile txt_profilepath.Text, pl1
    9.             Else
    10.                 txt_profilepath.Text = file1.Path & file1.FileName & "\" & txt_plprofile.Text & "-02"
    11.                 SaveProfile txt_profilepath.Text, pl1
    12.             End If
    13.         Else
    14.             MsgBox "Saving " & txt_profilepath & " as new profile."
    15.             SaveProfile txt_profilepath.Text, pl1
    16.         End If
    17.  
    18.         profilepath = txt_profilepath.Text
    19.         frm_field.cmd_next.Enabled = True
    20.  
    21.     Case "Load Profile"
    22.         MsgBox "Loading " & txt_profilepath & " profile."
    23.             LoadProfile txt_profilepath.Text, pl1
    24. End Select
    25.     Me.Hide
    26. End Sub

    I think it's in this code where the user specifies what file (or profile) to load.

  13. #13
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Retrieve data from a text file and display in a textbox.

    I am not sure about this, but I think you need to put a slash between these Path and FileName:

    txt_profilepath.Text = file1.Path & "\" & file1.FileName

  14. #14

    Thread Starter
    Member seraphicmortal's Avatar
    Join Date
    May 2005
    Posts
    56

    Re: Retrieve data from a text file and display in a textbox.

    WhatFile points to the correct file. I don't why it says 'Path not Found'... =(

  15. #15
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Retrieve data from a text file and display in a textbox.

    Also, you can put this line:

    MsgBox txt_profilepath.Text

    after this line:

    txt_profilepath.Text = file1.Path & file1.FileName & "\" & txt_plprofile.Text


    That way you will see if the path looks OK.

  16. #16
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Retrieve data from a text file and display in a textbox.

    If the path is ok, then the problem is in your loading procedure (LoadProfile). If it is then post it's code here.

  17. #17

    Thread Starter
    Member seraphicmortal's Avatar
    Join Date
    May 2005
    Posts
    56

    Re: Retrieve data from a text file and display in a textbox.

    Still Path Not Found Baja...but the slash was something to be added as well. Thanx!

  18. #18
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Retrieve data from a text file and display in a textbox.

    The file gets loaded here;

    What is this: txt_plprofile.Text

    that should be the file name to load.

  19. #19
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Retrieve data from a text file and display in a textbox.

    Quote Originally Posted by baja_yu
    Also, you can put this line:

    MsgBox txt_profilepath.Text

    after this line:

    txt_profilepath.Text = file1.Path & file1.FileName & "\" & txt_plprofile.Text


    That way you will see if the path looks OK.
    Use that, it will show you what you are trying to load. If that is ok then the error is elswhere.

  20. #20

    Thread Starter
    Member seraphicmortal's Avatar
    Join Date
    May 2005
    Posts
    56

    Resolved Re: Retrieve data from a text file and display in a textbox.

    Ahhhhhh!!! Silly me!! Path not found since I placed file1.FileName & "\" & txt_plprofile.text when in fact file1.fileName and txt_plprofile.text means the same!!!!

    Thanks a lot!!!!!

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