|
-
May 20th, 2005, 03:14 AM
#1
Thread Starter
Member
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:
(globalvar.bas)
Option Explicit
Public pn1 As New partnamelist
(frm_field)
Private Sub fieldupload()
With pn1 'I made a class named partnamelist having these 4 properties: part, description, quantity, and version
.part = txt_part.text
.description = txt_desc.Text
.quantity = txt_qty.Text
.version = txt_version.Text
End With
End Sub
Private Sub cmd_apply_Click()
dim filename as string
If Len(txt_part.text) = 0 And _
Len(txt_desc.Text) = 0 And _
Len(txt_qty.Text) = 0 And _
Len(txt_version.Text) = 0 Then
MsgBox "please enter the necessary values."
txt_part.setfocus
Else
fieldupload
filename = txt_filename.text 'Specified filename of the user
MsgBox ("Creating profile... Please choose what directory to save your profile.")
frm_dir.Show vbModal
End If
End Sub
'(frm_dir)
Private Sub Form_Load()
txt_pnprofile.Text = frm_field.filename + ".pnp" '--> "pnp" here in my example is my chosen extension.
End Sub
Private Sub cmd_ok_Click()
txt_profilepath.Text = file1.Path & file1.FileName & "\" & txt_plprofile.Text 'file1 is a file listbox btw
MsgBox "Saving " & txt_profilepath & " as new profile."
SaveProfile txt_profilepath.Text, pn1
profilepath = txt_profilepath.Text
End Sub
Private Sub SaveProfile(WhatFile As String, TheProfile As namelist)
Dim FreeFileHandle As Integer
FreeFileHandle = FreeFile
Open WhatFile For Output As FreeFileHandle
With TheProfile
Print #FreeFileHandle, "[Part] " & .part
Print #FreeFileHandle, "[Description] " & .description
Print #FreeFileHandle, "[Quantity] " & .quantity
Print #FreeFileHandle, "[Version] " & .version
End With
Close FreeFileHandle
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]
-
May 20th, 2005, 03:34 AM
#2
Re: Retrieve data from a text file and display in a textbox.
Have you tried soemthing like this:
VB Code:
(globalvar.bas)
Option Explicit
Public pn1 As New partnamelist
(frm_field)
Private Sub fieldupload()
With pn1 'I made a class named partnamelist having these 4 properties: part, description, quantity, and version
.part = txt_part.text
.description = txt_desc.Text
.quantity = txt_qty.Text
.version = txt_version.Text
End With
End Sub
Private Sub cmd_apply_Click()
dim filename as string
If Len(txt_part.text) = 0 And _
Len(txt_desc.Text) = 0 And _
Len(txt_qty.Text) = 0 And _
Len(txt_version.Text) = 0 Then
MsgBox "please enter the necessary values."
txt_part.setfocus
Else
fieldupload
filename = txt_filename.text 'Specified filename of the user
MsgBox ("Creating profile... Please choose what directory to save your profile.")
frm_dir.Show vbModal
End If
End Sub
'(frm_dir)
Private Sub Form_Load()
txt_pnprofile.Text = frm_field.filename + ".pnp" '--> "pnp" here in my example is my chosen extension.
End Sub
Private Sub cmd_ok_Click()
txt_profilepath.Text = file1.Path & file1.FileName & "\" & txt_plprofile.Text 'file1 is a file listbox btw
MsgBox "Saving " & txt_profilepath & " as new profile."
SaveProfile txt_profilepath.Text, pn1
profilepath = txt_profilepath.Text
End Sub
Private Sub SaveProfile(WhatFile As String, TheProfile As namelist)
Dim FreeFileHandle As Integer
FreeFileHandle = FreeFile
Open WhatFile For Output As FreeFileHandle
With TheProfile
Print #FreeFileHandle, "[Part] " & .part
txt_part.Text = .part
Print #FreeFileHandle, "[Description] " & .description
txt_description.Text = .description
Print #FreeFileHandle, "[Quantity] " & .quantity
txt_quantity.Text = .quantity
Print #FreeFileHandle, "[Version] " & .version
txt_version.Text = .version
End With
Close FreeFileHandle
End Sub
Not shure but I think that should work 
Cheers,
RyanJ
-
May 22nd, 2005, 08:45 PM
#3
Thread Starter
Member
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
-
May 22nd, 2005, 09:59 PM
#4
Re: Retrieve data from a text file and display in a textbox.
Here is one way to do it:
EDIT: It changed!
VB Code:
Private Sub LoadProfile(WhatFile As String, TheProfile As namelist)
Dim FreeFileHandle As Integer, A$,B() as String
FreeFileHandle = FreeFile
Open WhatFile For Input As FreeFileHandle
With TheProfile
LineInput #FreeFileHandle, a ' "[Part] " & .part
b=split(a," ")
.part = b(1)
txt_part.Text = .part
LineInput #FreeFileHandle, a ' "[Description] " & .description
b=split(a," ")
.description = b(1)
txt_description.Text = .description
LineInput #FreeFileHandle, a ' "[Quantity] " & .quantity
b=split(a," ")
.quantity = b(1)
txt_quantity.Text = .quantity
LineInput #FreeFileHandle, a ' "[Version] " & .version
b=split(a," ")
.version = b(1)
txt_version.Text = .version
End With
Close FreeFileHandle
End Sub
-
May 22nd, 2005, 10:18 PM
#5
Thread Starter
Member
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:
Private Sub LoadProfile(WhatFile As String, TheProfile As namelist)
Dim FreeFileHandle As Integer, A$,B() as String
FreeFileHandle = FreeFile
Open WhatFile For Input As FreeFileHandle
With TheProfile
[COLOR=Red]LineInput #FreeFileHandle, a ' "[Part] " & .part[/COLOR]
b=split(a," ")
.part = b(1)
txt_part.Text = .part
[COLOR=Red]LineInput #FreeFileHandle, a ' "[Description] " & .description[/COLOR]
b=split(a," ")
.description = b(1)
txt_description.Text = .description
[COLOR=Red]LineInput #FreeFileHandle, a ' "[Quantity] " & .quantity[/COLOR]
b=split(a," ")
.quantity = b(1)
txt_quantity.Text = .quantity
[COLOR=Red]LineInput #FreeFileHandle, a ' "[Version] " & .version[/COLOR]
b=split(a," ")
.version = b(1)
txt_version.Text = .version
End With
Close FreeFileHandle
End Sub
Last edited by seraphicmortal; May 22nd, 2005 at 10:26 PM.
Reason: only line input is in red text.
-
May 22nd, 2005, 10:35 PM
#6
Re: Retrieve data from a text file and display in a textbox.
Sorry about that. I didn't test it first.
Just add a space to the lines in RED!
-
May 22nd, 2005, 11:00 PM
#7
Thread Starter
Member
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.
-
May 22nd, 2005, 11:02 PM
#8
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.
-
May 22nd, 2005, 11:19 PM
#9
Thread Starter
Member
-
May 22nd, 2005, 11:20 PM
#10
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?
-
May 22nd, 2005, 11:28 PM
#11
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.
-
May 22nd, 2005, 11:28 PM
#12
Thread Starter
Member
Re: Retrieve data from a text file and display in a textbox.
OK button from the form directory (frm_dir).
VB Code:
Private Sub cmd_ok_Click()
txt_profilepath.Text = file1.Path & file1.FileName & "\" & txt_plprofile.Text
Select Case Me.Caption
Case "Save Profile"
If isFile(txt_profilepath.Text) Then
If MsgBox("File " & txt_profilepath & " exists. Do you want to overwrite the current profile?{Y/N]", vbQuestion + vbYesNo, App.ProductName + " Prompt") = vbYes Then
SaveProfile txt_profilepath.Text, pl1
Else
txt_profilepath.Text = file1.Path & file1.FileName & "\" & txt_plprofile.Text & "-02"
SaveProfile txt_profilepath.Text, pl1
End If
Else
MsgBox "Saving " & txt_profilepath & " as new profile."
SaveProfile txt_profilepath.Text, pl1
End If
profilepath = txt_profilepath.Text
frm_field.cmd_next.Enabled = True
Case "Load Profile"
MsgBox "Loading " & txt_profilepath & " profile."
LoadProfile txt_profilepath.Text, pl1
End Select
Me.Hide
End Sub
I think it's in this code where the user specifies what file (or profile) to load.
-
May 22nd, 2005, 11:31 PM
#13
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
-
May 22nd, 2005, 11:32 PM
#14
Thread Starter
Member
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'... =(
-
May 22nd, 2005, 11:32 PM
#15
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.
-
May 22nd, 2005, 11:35 PM
#16
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.
-
May 22nd, 2005, 11:36 PM
#17
Thread Starter
Member
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!
-
May 22nd, 2005, 11:37 PM
#18
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.
-
May 22nd, 2005, 11:38 PM
#19
Re: Retrieve data from a text file and display in a textbox.
 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.
-
May 22nd, 2005, 11:55 PM
#20
Thread Starter
Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|