Results 1 to 10 of 10

Thread: [solved]How to get data from Userform to txt file?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86

    Question [solved]How to get data from Userform to txt file?

    I have a Userform in my VBA app. I need the User to input a section,date,time,period, and interval(mins).these are from textboxes. How to get these input to be printed to a text file?The format is attached.pLs help.thanks.
    Attached Files Attached Files
    Last edited by ITboy; Apr 11th, 2003 at 01:32 AM.

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    VB Code:
    1. [color="#0000A0"]Dim[/color] strSavedText [color="#0000A0"]As[/color] [color="#0000A0"]String[/color]
    2.  
    3. strSavedText = txtSection.text & vbcrlf & txtDate.text [color="#00A000"]'etc[/color]
    4.  
    5. [color="#0000A0"]Open[/color] "C:\Path\File.txt" [color="#0000A0"]For[/color] [color="#0000A0"]Output[/color] [color="#0000A0"]As[/color] #1
    6. Print #1, strSavedText
    7. [color="#0000A0"]Close[/color] #1
    8.  
    9. Msgbox "Done!"

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86
    Thanks Alex..but i need a small logic there...If the user did not enter the date and time, then it should take the current system date and time(also in separate lines).Thankx

  4. #4
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    You could so that using this:
    VB Code:
    1. [color="#0000A0"]If[/color] cstr(trim(txtdate.text)) = "" [color="#0000A0"]Then[/color]
    2.     strSavedText = strSavedText  & [color="#0000A0"]Date[/color]
    3. [color="#0000A0"]Else[/color]
    4.     strSavedText = strSavedText & cstr(trim(txtdate.text))
    5. [color="#0000A0"]End[/color] [color="#0000A0"]If[/color]

    The keyword Date as above grabs the current date, whilst the keyword Time grabs the current system time.

    You might also want to lookup the format() function in MSDN if you want to alter the format of the date & time values.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86
    Alex..need ur help again..I 've got a Shell func which passes 5 arguments(these 5 arguments should actually come from the txt file created above but I 've hardcoded it) How to pass it to my shell func in the module.This is my code.
    :-
    PHP Code:
    Function StartDoc(DocName As String) As Long
      Dim Scr_hDC 
    As Long
      Scr_hDC 
    GetDesktopWindow()
      
    Debug.Print "yoyo"
    StartDoc ShellExecute(Scr_hDC"Open"DocName"2 03/11/2002 08:15:00 7 30""C:\windows\desktop\CreateAct\", SW_SHOWNORMAL)
    Debug.Print "
    yaya"
    End Function 
    The aruments are after the DocName param..Thanks again.

  6. #6
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    err, would that be this thread http://www.vbforums.com/showthread.p...hreadid=239651 you'd be referring to there by any chance?

    Give me a min ....
    Last edited by alex_read; Apr 9th, 2003 at 07:39 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  7. #7
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    I dunno where the text file idea fits into all of this, but here's a sample project for you, it'll show a form with your textboxes, then pass the values over to your perl program - I've just tested it & the parameters are passed okay here
    Attached Files Attached Files

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86
    Alex...I understand how u did it...But why i wanted to read in from the text file is bcoz, all my functions are not in the same Form module as u did.. The place where i click a button is in Form B(which activates a Shell function) but the fields which I'm getting the parameters from is Form A... Do u get it now..???
    Like for this:
    PHP Code:
    strParameters txtSection.Text "," txtDate.Text "," txtTime.Text ","
            
    strParameters strParameters txtPeriods.Text "," txtMins.Text 
    it is impossible to do so inmy case coz strParameters is defined in my Form B but the txtSection.Text..etc etc is in Form A.U got my problem now?I was so glad tat u really took the effort to try it out to help me. Thankx alot.

  9. #9
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Try this one!
    Attached Files Attached Files

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86

    Cool

    Thank you alex..Its kinda helped me.Thanks for ur time n effort..

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