|
-
Nov 12th, 2008, 05:17 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Prob with saving the data from more controls - CommonDialog
Hi All
I have something like this – how see, I use CommonDialog control. I don’t know how I fix it.
How I would it to make?
This is a sub to read – here's OK, need only procedure of handling any errors
Code:
Option Explicit
Dim strBufor As String
Dim strKatalog As String
Dim strPlikZapis As String
Dim strPlikOdczyt As String
Dim intNumPlik As Integer
Dim IntLic As Integer
Private Sub cmdOdczyt_Click()
Dim data() As String
With cdlMyDialog
.CancelError = True
.InitDir = strKatalog
.Flags = cdlOFNHideReadOnly
.fileName = ""
.Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
.ShowOpen
strPlikOdczyt = .fileName
End With
intNumPlik = FreeFile
Open strPlikOdczyt For Binary Access Read As #intNumPlik '<<< open the file
strBufor = Input$(LOF(intNumPlik), intNumPlik)
Close #intNumPlik
data = Split(strBufor, vbNewLine) '<<< get the data
For IntLic = 0 To 6
txtRaz(IntLic) = data(IntLic) '<<< entry to determine of objects
Next
Combo1.Text = data(7)
Following is a sub to write – here's a wrong. I don't know, what?
Code:
Private Sub cmdZapis_Click()
With cdlMyDialog
.CancelError = True
.InitDir = strKatalog
.Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist
.fileName = ""
.Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
.ShowSave
strPlikZapis = .fileName
End With
intNumPlik = FreeFile
Open strPlikZapis For Binary Access Write As #intNumPlik
For IntLic = 0 To 6 '<<< And here it's this prob
Put #intNumPlik, , CStr(txtRaz(IntLic)) '<<< try it so, unfortunately it to give a one the line,
' <<< still is a wrongly
Next '<<< What is a wrong ???? How to make?
Put #intNumPlik, , strBufor
Close #intNumPlik
Please help me, thanks in advance
Last edited by Tamgovb; Nov 12th, 2008 at 05:26 PM.
I know, I know, my English is bad, sorry .....
-
Nov 12th, 2008, 06:26 PM
#2
Re: Prob with saving the data from more controls - CommonDialog
What is the error? Or what is wrong? Can you be specific
Oh, I see now. When you read the lines from the text file, you used Split() on vbNewLine. That stripped the vbNewLine out of the data, you have to put it back:
Code:
For IntLic = 0 To 6
Put #intNumPlik, , CStr(txtRaz(IntLic) & vbNewLine)
Next
However, I'd recommend the following and not using For Binary
Code:
Open strPlikZapis For OutPut As #intNumPlik
For IntLic = 0 To 6
Print #intNumPlik, txtRaz(IntLic)
Next
Print #intNumPlik, strBufor
...
This way, the file is guaranteed to be overwritten without any 'garabage' at the end of the file. For example, if txtRaz(0) thru txtRaz(6) had 500 characters when you read the file, and later you made those textboxes just have 1 character each, you would think your file should be 493 characters smaller, no? Well, it will be the same size with 493 junk characters at the end of the file. But when you open a file For Output, you are completely overwriting the file.
Last edited by LaVolpe; Nov 12th, 2008 at 06:42 PM.
-
Nov 13th, 2008, 09:21 AM
#3
Thread Starter
Hyperactive Member
Re: Prob with saving the data from more controls - CommonDialog
Hi
Yeah, I was not idle in this time and at the same time I found on a different forums the same of information. Those information tell me the same, exactly like you me tell - I should change the mode of writes to files. Ok, thanks a lot, I will to do it
I greet
I know, I know, my English is bad, sorry .....
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
|