Results 1 to 7 of 7

Thread: [RESOLVED] Help need it

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    18

    Resolved [RESOLVED] Help need it

    Dear forum,

    I am a totally new in programming with visual basic 6. I must made a program and I have a question. In my program in main form I have a button to save a file with the data that the user has entered. When the save button pushed /clicked a new form shows and guide the user to find where the file must be saved. But when I try to do that the rest of the code for the saving is executed and the files always goes to the root directory app.path.
    How I could stop the code to run and continue after the user has selects the path which the file must be saved?
    Thanks in advance for your time.

  2. #2
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Help need it

    Hi konstantinos29

    Welcome to the forum

    How are you getting the user to enter the path for the file to be saved?

    My suggestion would be to take a look at the Common Dialog Box.

    Take a look here, or search these forums for more info. There is plenty here.
    It's where I go for all my help.

    Hope this helps.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  3. #3

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    18

    Re: Help need it

    Dear friend,

    May be I am not so clear. I have the main from (let’s called form1). In that form the user put some data into the form. When finishing there are two buttons the save and the exit. When the save button have been clicked a new from shows. In that new from the user select the path of where the file must be saved. After the path the from2 where the path has been chosen the program must continue with the gathering the information from the form 1 made some conversion and finally close the file. The problem is that when the user chooses the path the program has already finish with the saving of the file and as path always takes the app.path.
    I give you the code of the procedure.


    Dim stream As Integer
    Dim basic(6), reject(6), rejectnum(6), span(6) As Double
    Dim rejection(6), filepath As String

    Text1.Tag = Text1.Text ‘save the text1.text because here returns the path
    frmfile.Show vbModal ‘ the form which take the path
    filepath = Text1.Text ‘start the code which must stopped until the data from the previous form must return. That code executes and I have the file always at app.path path always.

    Text1.Text = Text1.Tag
    basic(1) = CDbl(Trim$(Text1.Text)) * check(Trim$(cbounit1.Text))
    basic(2) = CDbl(Trim$(Text2.Text)) * check(Trim$(cbounit2.Text))
    basic(3) = CDbl(Trim$(Text3.Text)) * check(Trim$(cbounit3.Text))
    basic(4) = CDbl(Trim$(Text4.Text)) * check(Trim$(cbounit4.Text))
    basic(5) = CDbl(Trim$(Text5.Text))
    basic(6) = CDbl(Trim$(Text6.Text))
    rejectnum(1) = CDbl(Trim$(textbox7.Text)) * check(Trim$(cbounit5))
    span(1) = CDbl(Trim$(textbox13.Text)) * check(Trim$(cbounit11))
    rejectnum(2) = CDbl(Trim$(textbox8.Text)) * check(Trim$(cbounit6))
    span(2) = CDbl(Trim$(textbox14.Text)) * check(Trim$(cbounit12))
    rejectnum(3) = CDbl(Trim$(textbox9.Text)) * check(Trim$(cbounit7))
    span(3) = CDbl(Trim$(textbox15.Text)) * check(Trim$(cbounit13))
    rejectnum(4) = CDbl(Trim$(textbox10.Text)) * check(Trim$(cbounit8))
    span(4) = CDbl(Trim$(textbox16.Text)) * check(Trim$(cbounit14))
    rejectnum(5) = CDbl(Trim$(textbox11.Text)) * check(Trim$(cbounit9))
    span(5) = CDbl(Trim$(textbox17.Text)) * check(Trim$(cbounit15))
    rejectnum(6) = CDbl(Trim$(textbox12.Text)) * check(Trim$(cbounit10))
    span(6) = CDbl(Trim$(textbox18.Text)) * check(Trim$(cbounit16))
    reject(1) = CDbl(Trim$(Combo1.Text))
    reject(2) = CDbl(Trim$(Combo2.Text))
    reject(3) = CDbl(Trim$(Combo3.Text))
    reject(4) = CDbl(Trim$(Combo4.Text))
    reject(5) = CDbl(Trim$(Combo5.Text))
    reject(6) = CDbl(Trim$(Combo6.Text))
    rejection(1) = Combo1.Text
    rejection(2) = Combo2.Text
    rejection(3) = Combo3.Text
    rejection(4) = Combo4.Text
    rejection(5) = Combo5.Text
    rejection(6) = Combo6.Text
    stream = FreeFile
    filepath = filepath + ".dat"
    Open filepath For Output As #stream
    For i = 1 To 6
    Print #stream, basic(i)
    Next i
    For i = 1 To 6
    Print #stream, rejection(i), reject(i), rejectnum(i), span(i)
    Next i
    Close #stream
    End Sub

  5. #5

    Re: Help need it

    just a question
    is the textbox(Text1.Text ) contains the complete path where it needs to be saved. or else by default it will be saved in the root application directory

    if you want to save in a predefined directory please change your code as follows

    filepath = filepath + ".dat"
    strDir = app.Path & "\Output\"
    filepath = strDir + filepath
    Open filepath For Output As #stream

    if your program saves before you enter the path. BY RIGHT the calling routin will wait till the modal form is closed if you are facing problem with that

    why dont you just assign the path and the make the rest in a function. And call the save function later after a validation that validates the file path you want

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    18

    Re: Help need it

    dear pon,

    The path it must be change dynamically from the user.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    18

    Re: Help need it

    I have another problem. When i use the modal forms and i made the executable code it seems not closing. I do not knwo why but it looks to left almost all form opens. I suppose that when the form made modal none of the rest of command about closing have effect on that. I do not know why. I post the code for everyone which have some time to take a look for a beginner which need depsertly help. I include and the executable and i like your opinions. Thank in advance for your time.
    Attached Files Attached Files

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