How can i store my collected data to notepad through VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • keeaun
    New Member
    • Apr 2007
    • 2

    How can i store my collected data to notepad through VB

    hi all,
    i'm quite new to VB and i want to store my collected data to VB automatically once i press the command button. Till now i only manage to save through the pop up window using the commondialog1. can anyone please help me? may i know how to declare a notepad application in VB like :-
    Newfile=CreateO bject("Excel.Ap plication")

    i wrote: NewFile=CreateO bject("Notepad. Application") but come out error saying no active x application.

    below is my sample code:

    Code:
    Dim array_data As String
    Dim x As Integer
    Dim list_array As Variant
    
    List1.Clear
    array_data = "yes"
    
    CommonDialog1.CancelError = True
    On Error GoTo CancelButton
    CommonDialog1.Filter = "Text files (*.txt|*.txt"
    CommonDialog1.ShowSave
    Newfile = CommonDialog1.FileName
    
    Open Newfile For Output As #1
    
    If array_data <> "" Then
        ReDim Preserve received_data(Text3.Text)
        For x = 0 To Text3.Text
            received_data(x) = x & "," & array_data
        Next x
        End If
    
    For Each list_array In received_data
        Write #1, list_array
        List1.AddItem List1.Text & vbCrLf & list_array
    Next
    
    Close #1
    
    CancelButton:
    Exit Sub
    thank you
    Last edited by Killer42; Apr 5 '07, 03:50 AM. Reason: Please use [CODE]...[/CODE] tags around your code.
  • ansumansahu
    New Member
    • Mar 2007
    • 149

    #2
    Originally posted by keeaun
    hi all,
    i'm quite new to VB and i want to store my collected data to VB automatically once i press the command button. Till now i only manage to save through the pop up window using the commondialog1. can anyone please help me? may i know how to declare a notepad application in VB like :-

    Newfile=CreateO bject("Excel.Ap llication")

    i wrote: NewFile=CreateO bject("Notepad. Application") but come out error saying no active x application.

    below is my sample code:

    Dim array_data As String
    Dim x As Integer
    Dim list_array As Variant

    List1.Clear
    array_data = "yes"

    CommonDialog1.C ancelError = True
    On Error GoTo CancelButton
    CommonDialog1.F ilter = "Text files (*.txt|*.txt"
    CommonDialog1.S howSave
    Newfile = CommonDialog1.F ileName

    Open Newfile For Output As #1

    If array_data <> "" Then
    ReDim Preserve received_data(T ext3.Text)
    For x = 0 To Text3.Text
    received_data(x ) = x & "," & array_data
    Next x
    End If

    For Each list_array In received_data
    Write #1, list_array
    List1.AddItem List1.Text & vbCrLf & list_array
    Next

    Close #1

    CancelButton:
    Exit Sub

    thank you
    Hi ,

    You can open the notepad using the following code inside the button_click event

    Dim lstatus As Long

    lstatus = Shell("NOTEPAD. EXE ", vbNormalFocus)

    Comment

    • vijaydiwakar
      Contributor
      • Feb 2007
      • 579

      #3
      u can save it using ur code and open it using shell or ole
      Good Luck

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        I'm a little confused about something. Do you actually have a need for the Notepad application, or do you just want to save some data to a text file? They are not the same thing.

        Comment

        • SanjuMtr
          New Member
          • Mar 2007
          • 47

          #5
          Originally posted by Killer42
          I'm a little confused about something. Do you actually have a need for the Notepad application, or do you just want to save some data to a text file? They are not the same thing.
          I have a same question as killer said.if u want to save data in text file or execute notepad application. if the 1st one then the functionality is different from 2nd one. if 1st on e your requirement here a sample code.
          read the code carefully and try to understand the logic behind it.not just copy the code good luck
          Code:
              Dim fsys As New Scripting.FileSystemObject
              Dim Txtfl As Scripting.TextStream
              Dim OutPath As String="C:\mydata\"
              Dim ACC_TYPE, ACC_NO, CR_OR_DBT, DESCP, CHQ_NO, CHQ_DT,  AMOUNT, BRANCH_CODE, ORG_DT As String
          
                  Dim TempConn As New OleDb.OleDbConnection
                  Dim cmdAsciiDetails As OleDb.OleDbCommand
                  Dim daAsciiDetails As OleDb.OleDbDataReader
                  TempConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & application.startuppath 
          
          
          Txtfl = fsys.CreateTextFile(OutPath & "savedata.txt" , True, False)
                  
           dim sqlQuery as string = "Select * from CHEQUE_DETAILS where LOT_NO=" & txt1.Text.Trim & " Order By Index_No"
          
                  TempConn.Open()
                  cmdAsciiDetails = New OleDb.OleDbCommand(sqlQuery, TempConn)
                  daAsciiDetails = cmdAsciiDetails.ExecuteReader
          
                  While daAsciiDetails.Read
                      ACC_TYPE = "CA"
                      ACC_NO = IIf(daAsciiDetails.Item("AC_NO") Is    System.DBNull.Value, "", daAsciiDetails.Item("AC_NO"))
                      ACC_NO = PadL(CStr(ACC_NO), 10, "0")
                      CR_OR_DBT = "D"
                      DESCP = "TO_CHQSDR"
                      CHQ_NO = PadL(CStr(daAsciiDetails.Item("CHEQUE_NO")), 8, "0")
                      If daAsciiDetails.Item("CHEQUE_DATE") Is System.DBNull.Value Then
                          CHQ_DT = PadL("", 8, "0")
                      Else
                          CHQ_DT = Format(daAsciiDetails.Item("CHEQUE_DATE"), "ddMMyyyy")
                      End If
                      AMOUNT = PadL(CStr(Format(daAsciiDetails.Item("AMOUNT"), "0.00")), 13, "0")
                      BRANCH_CODE = PadL("CHV199", 6, "0") '
                      If daAsciiDetails.Item("CA_DATE") Is System.DBNull.Value Then
                          ORG_DT = PadL("", 8, "0")
                      Else
                          ORG_DT = Format(daAsciiDetails.Item("CA_DATE"), "ddMMyyyy")
                      End If
          
                      Txtfl.WriteLine(ACC_TYPE & " " & ACC_NO & " " & CR_OR_DBT & " " & DESCP & "  " & _
                                      CHQ_NO & " " & CHQ_DT & " " & AMOUNT & " " & BRANCH_CODE & " " & _
                                      ORG_DT)
          
                  End While
                  daAsciiDetails.Close()
                  TempConn.Close()
          txtfl.close()
          there are lot of user define functions exist in code that i am not describeing it here rather than giving u the a overall view as per your requirement.Goo d Luck.

          Comment

          Working...