By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,097 Members | 1,405 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,097 IT Pros & Developers. It's quick & easy.

How can i store my collected data to notepad through VB

P: 2
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=CreateObject("Excel.Application")
i wrote: NewFile=CreateObject("Notepad.Application") but come out error saying no active x application.

below is my sample code:

Expand|Select|Wrap|Line Numbers
  1. Dim array_data As String
  2. Dim x As Integer
  3. Dim list_array As Variant
  4.  
  5. List1.Clear
  6. array_data = "yes"
  7.  
  8. CommonDialog1.CancelError = True
  9. On Error GoTo CancelButton
  10. CommonDialog1.Filter = "Text files (*.txt|*.txt"
  11. CommonDialog1.ShowSave
  12. Newfile = CommonDialog1.FileName
  13.  
  14. Open Newfile For Output As #1
  15.  
  16. If array_data <> "" Then
  17.     ReDim Preserve received_data(Text3.Text)
  18.     For x = 0 To Text3.Text
  19.         received_data(x) = x & "," & array_data
  20.     Next x
  21.     End If
  22.  
  23. For Each list_array In received_data
  24.     Write #1, list_array
  25.     List1.AddItem List1.Text & vbCrLf & list_array
  26. Next
  27.  
  28. Close #1
  29.  
  30. CancelButton:
  31. Exit Sub
thank you
Apr 4 '07 #1
Share this Question
Share on Google+
4 Replies


100+
P: 149
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=CreateObject("Excel.Apllication")

i wrote: NewFile=CreateObject("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.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
Hi ,

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

Dim lstatus As Long

lstatus = Shell("NOTEPAD.EXE ", vbNormalFocus)
Apr 4 '07 #2

vijaydiwakar
100+
P: 579
u can save it using ur code and open it using shell or ole
Good Luck
Apr 4 '07 #3

Expert 5K+
P: 8,434
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.
Apr 5 '07 #4

P: 47
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
Expand|Select|Wrap|Line Numbers
  1.     Dim fsys As New Scripting.FileSystemObject
  2.     Dim Txtfl As Scripting.TextStream
  3.     Dim OutPath As String="C:\mydata\"
  4.     Dim ACC_TYPE, ACC_NO, CR_OR_DBT, DESCP, CHQ_NO, CHQ_DT,  AMOUNT, BRANCH_CODE, ORG_DT As String
  5.  
  6.         Dim TempConn As New OleDb.OleDbConnection
  7.         Dim cmdAsciiDetails As OleDb.OleDbCommand
  8.         Dim daAsciiDetails As OleDb.OleDbDataReader
  9.         TempConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & application.startuppath 
  10.  
  11.  
  12. Txtfl = fsys.CreateTextFile(OutPath & "savedata.txt" , True, False)
  13.  
  14.  dim sqlQuery as string = "Select * from CHEQUE_DETAILS where LOT_NO=" & txt1.Text.Trim & " Order By Index_No"
  15.  
  16.         TempConn.Open()
  17.         cmdAsciiDetails = New OleDb.OleDbCommand(sqlQuery, TempConn)
  18.         daAsciiDetails = cmdAsciiDetails.ExecuteReader
  19.  
  20.         While daAsciiDetails.Read
  21.             ACC_TYPE = "CA"
  22.             ACC_NO = IIf(daAsciiDetails.Item("AC_NO") Is    System.DBNull.Value, "", daAsciiDetails.Item("AC_NO"))
  23.             ACC_NO = PadL(CStr(ACC_NO), 10, "0")
  24.             CR_OR_DBT = "D"
  25.             DESCP = "TO_CHQSDR"
  26.             CHQ_NO = PadL(CStr(daAsciiDetails.Item("CHEQUE_NO")), 8, "0")
  27.             If daAsciiDetails.Item("CHEQUE_DATE") Is System.DBNull.Value Then
  28.                 CHQ_DT = PadL("", 8, "0")
  29.             Else
  30.                 CHQ_DT = Format(daAsciiDetails.Item("CHEQUE_DATE"), "ddMMyyyy")
  31.             End If
  32.             AMOUNT = PadL(CStr(Format(daAsciiDetails.Item("AMOUNT"), "0.00")), 13, "0")
  33.             BRANCH_CODE = PadL("CHV199", 6, "0") '
  34.             If daAsciiDetails.Item("CA_DATE") Is System.DBNull.Value Then
  35.                 ORG_DT = PadL("", 8, "0")
  36.             Else
  37.                 ORG_DT = Format(daAsciiDetails.Item("CA_DATE"), "ddMMyyyy")
  38.             End If
  39.  
  40.             Txtfl.WriteLine(ACC_TYPE & " " & ACC_NO & " " & CR_OR_DBT & " " & DESCP & "  " & _
  41.                             CHQ_NO & " " & CHQ_DT & " " & AMOUNT & " " & BRANCH_CODE & " " & _
  42.                             ORG_DT)
  43.  
  44.         End While
  45.         daAsciiDetails.Close()
  46.         TempConn.Close()
  47. txtfl.close()
  48.  
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.Good Luck.
Apr 10 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.