file handling - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

file handling

AraxArax Posts: 13Member
i try to open a zip file with

open "filename" for input as #1

and then save the file into a variable, but when i try to write the file with

open "filename" for output as #1
write #1, variable
close #1

the file is rather messy and wont work... can anyone help?

Comments

  • PavlinIIPavlinII Posts: 404Member
    : i try to open a zip file with
    :
    : open "filename" for input as #1
    :
    : and then save the file into a variable, but when i try to write the file with
    :
    : open "filename" for output as #1
    : write #1, variable
    : close #1
    :
    : the file is rather messy and wont work... can anyone help?
    :
    [red][b]Do not use Write #1, Variable [/b][/red] because Write is "formated output" - it can do some rubbish with text and numbers .... And Write gives quotation marks on beginnig and end of Variable.. So if you use
    Variable = "hello"
    then in your file will appears:
    "hello"

    [green][b]Use Print #1, Variable[/b][/green] instead write... It should be enough... If you're sure that your Variable is filled correctly ;-)

    PavlinII
  • AraxArax Posts: 13Member
    : : i try to open a zip file with
    : :
    : : open "filename" for input as #1
    : :
    : : and then save the file into a variable, but when i try to write the file with
    : :
    : : open "filename" for output as #1
    : : write #1, variable
    : : close #1
    : :
    : : the file is rather messy and wont work... can anyone help?
    : :
    : [red][b]Do not use Write #1, Variable [/b][/red] because Write is "formated output" - it can do some rubbish with text and numbers .... And Write gives quotation marks on beginnig and end of Variable.. So if you use
    : Variable = "hello"
    : then in your file will appears:
    : "hello"
    :
    : [green][b]Use Print #1, Variable[/b][/green] instead write... It should be enough... If you're sure that your Variable is filled correctly ;-)
    :
    : PavlinII
    :
    it still wont work
    i use this code:
    [code]Dim line

    Open "c: est.rar" For Input As #1
    Open "c: est2.rar" For Output As #2
    While Not EOF(1)
    Line Input #1, line
    Print #2, line
    MsgBox line
    Wend
    Close #1
    Close #2
    [/code]
  • PavlinIIPavlinII Posts: 404Member
    : : : i try to open a zip file with
    : : :
    : : : open "filename" for input as #1
    : : :
    : : : and then save the file into a variable, but when i try to write the file with
    : : :
    : : : open "filename" for output as #1
    : : : write #1, variable
    : : : close #1
    : : :
    : : : the file is rather messy and wont work... can anyone help?
    : : :
    : : [red][b]Do not use Write #1, Variable [/b][/red] because Write is "formated output" - it can do some rubbish with text and numbers .... And Write gives quotation marks on beginnig and end of Variable.. So if you use
    : : Variable = "hello"
    : : then in your file will appears:
    : : "hello"
    : :
    : : [green][b]Use Print #1, Variable[/b][/green] instead write... It should be enough... If you're sure that your Variable is filled correctly ;-)
    : :
    : : PavlinII
    : :
    : it still wont work
    : i use this code:
    : [code]Dim line
    :
    : Open "c: est.rar" For Input As #1
    : Open "c: est2.rar" For Output As #2
    : While Not EOF(1)
    : Line Input #1, line
    : Print #2, line
    : MsgBox line
    : Wend
    : Close #1
    : Close #2
    : [/code]
    :
    :-) [gray]I said: "If you're sure that your Variable is filled correctly"[/gray] ;-)
    Your code wont work because:
    Line Input reads file and it returns string from actual position to LF [gray](Chr(13))[/gray][blue]OR[/blue] LF-CR [gray](Chr(13) & Chr(10))[/gray] and that OR is your problem, because Print writes LF-CR everytime... You you have some CRs additional... And in binary file (like theese archives) isn't combination LF-CR compulsory...
    So, use this code:
    [code]Dim AllFile As String
    Open "E:_TempTest.rar" For Binary As #1
    AllFile = Space(FileLen("E:_Temp est.rar"))
    Get #1, , AllFile
    Close #1

    Open "E:_Temp est2.rar" For Binary As #2
    Put #2, , AllFile
    Close #2[/code]
    Hope, it will help ;-)
    PavlinII
Sign In or Register to comment.