User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 427,202 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,274 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 1120 | Replies: 2
Reply
Join Date: Feb 2008
Posts: 4
Reputation: ventrica is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ventrica ventrica is offline Offline
Newbie Poster

help!how to write file into notepad in VB?

  #1  
Mar 24th, 2008
this is my simple program and i need to save or write the info that i key in in a notepad and also have the function to displat the info in the notepad. Can any one help me?TQ

this is my simple program in VB. how can i write the info such as packet type and others in to a notepad and display record ?TQ

  1. ''General_Declaration of the form
  2. Dim sItem As String
  3. Dim sPacket As String
  4. Dim sSourceIP As String
  5. Dim temp As LinkList
  6. Dim Head As LinkList
  7. Dim First As LinkList 'Alwyas Points Starting of the List
  8. Dim i As Integer
  9.  
  10. Private Sub Class_Initialize()
  11. Set pNext = gthing
  12. End Sub
  13.  
  14. Private Sub Class_Terminate()
  15. Set pNext = Nothing
  16. End Sub
  17.  
  18. '''Insert in to a node
  19. Private Sub InsertNode()
  20.  
  21.  
  22. 'Do While Not UCase(sItem) = "END"
  23. 'i = i + 1
  24.  
  25. 'sItem = InputBox("Enter the Item", , "")
  26. 'sItem = Trim(sItem)
  27. sPacket = InputBox("Packet Type:", , "")
  28. sSourceIP = InputBox("Source IP Address:", , "")
  29.  
  30. If Head Is Nothing Then
  31. Set temp = New LinkList
  32. temp.Protocol_Type = sPacket
  33. temp.Source_IP_Add = sSourceIP
  34. Set Head = temp
  35. Set First = Head
  36. Else
  37. Set temp = New LinkList
  38. temp.Protocol_Type = sPacket
  39. temp.Source_IP_Add = sSourceIP
  40. Set Head.pNext = temp
  41. Set Head = temp
  42. End If
  43. 'If UCase(sItem) = "END" Then
  44. Set Head.pNext = Nothing
  45. ' End If
  46. 'Loop
  47.  
  48. End Sub
  49. '''''''---------------------------------------------------
  50. 'Delete a Particular Node
  51.  
  52. Private Sub DeleteNode()
  53. Dim sDelStr As String
  54. Dim d As LinkList
  55. Dim holdPrev As LinkList 'Hold Previous location while deleting
  56. Dim a
  57. Set temp = Nothing
  58. Set p = Nothing
  59. Set holPrev = Nothing
  60. Set d = First
  61.  
  62.  
  63. If d Is Nothing Then
  64. ' Text1.Text = "No Items In the List
  65. ' ! Insert Something 'before Delete !"
  66. a = MsgBox("NO MATCH FOUND. NO RECORD DELETED", vbInformation)
  67. Exit Sub
  68. End If
  69.  
  70. sDelStr = InputBox("Please Enter Soure IP Address Of The Packet That You Want To Delete: ")
  71. sDelStr = UCase(sDelStr)
  72.  
  73.  
  74. Do While Not d Is Nothing
  75.  
  76.  
  77. If UCase(d.Source_IP_Add) = sDelStr Then
  78. a = MsgBox("Are you sure", vbOKCancel)
  79. If a = vbOK Then
  80. If holPrev Is Nothing Then
  81. Set First = d.pNext
  82. 'Call DisPlayNode
  83. Exit Sub
  84. End If
  85. Set d = holPrev
  86. Set d.pNext = temp.pNext
  87. If d.pNext Is Nothing Then 'if deleted node is last node
  88. Set Head = d
  89. End If
  90. a = MsgBox("RECORD DELETED", vbInformation)
  91. Exit Sub
  92. Else
  93. a = MsgBox("RECORD NOT DELETED", vbInformation)
  94. Exit Sub
  95. End If
  96.  
  97.  
  98. Else
  99. Set holPrev = d
  100. Set temp = d.pNext
  101. Set d = d.pNext
  102. End If
  103. Loop
  104. a = MsgBox("NO MATCH FOUND. NO RECORD DELETED", vbInformation)
  105. Set p = Nothing
  106. End Sub
  107.  
  108. ''''''-------------------------------------
  109. 'Display all Nodes in the list
  110.  
  111. Private Sub DisPlayNode()
  112. Dim p As LinkList
  113. Dim a
  114. Dim msg
  115.  
  116. Set p = First
  117. If p Is Nothing Then
  118. a = MsgBox("NO RECORDS TO DISPLAY", vbInformation)
  119. Exit Sub
  120. End If
  121.  
  122. msg = "ProType|SourceIPAdd"
  123.  
  124. Do While Not p Is Nothing
  125. msg = msg & vbNewLine & p.Protocol_Type & vbTab & p.Source_IP_Add
  126.  
  127. Set p = p.pNext
  128. Loop
  129. a = MsgBox(msg, vbInformation)
  130.  
  131. Set p = Nothing
  132. End Sub
  133. ''''-----------------------
  134.  
  135. Private Sub SearchNode()
  136. Dim d As LinkList
  137. Set d = First
  138. Dim sSearch As String
  139. Dim a
  140.  
  141. sSearch = InputBox("Please Enter Source IP Address :")
  142. sSearch = UCase(sSearch)
  143.  
  144. Do While Not d Is Nothing
  145. If UCase(d.Source_IP_Add) = sSearch Then
  146. a = MsgBox("RECORD FOUND" & vbNewLine & d.Protocol_Type & vbTab & d.Source_IP_Add, vbInformation)
  147. Exit Sub
  148. Else
  149. Set d = d.pNext
  150. End If
  151. Loop
  152. a = MsgBox("NO MATCH FOUND", vbInformation)
  153.  
  154. End Sub
  155.  
  156. '''''Cleanup all allocated memory
  157.  
  158. Private Sub free()
  159. Set temp = Nothing
  160. Set Head = Nothing
  161. Set First = Nothing
  162. Set holdPrev = Nothing
  163. End Sub
  164.  
  165. Private Sub cmdAdd_Click()
  166. Call InsertNode
  167. End Sub
  168.  
  169. Private Sub cmdDelete_Click()
  170. Call DeleteNode
  171. End Sub
  172.  
  173. Private Sub cmdDetect_Click()
  174. Call SearchNode
  175. End Sub
  176.  
  177. Private Sub cmdDisplay_Click()
  178. Call DisPlayNode
  179.  
  180. End Sub
  181.  
  182. Private Sub cmdExit_Click()
  183. Call free
  184. Unload Me
  185. End Sub
Last edited by WolfPack : Mar 24th, 2008 at 11:20 am. Reason: Added code tags. Use them when you post code.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2008
Location: Cebu, Philippines
Posts: 122
Reputation: cometburn is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 19
cometburn's Avatar
cometburn cometburn is offline Offline
Junior Poster

Re: help!how to write file into notepad in VB?

  #2  
Mar 24th, 2008
i didnt read your code. but if writing on a notepad is your problem, i hope this helps.
  1. Dim fso As New FileSystemObject
  2. Dim strm As TextStream
  3. Set strm = fso.OpenTextFile("c:\test.txt", ForWriting)
  4. strm.WriteLine ("String to write")
Last edited by cometburn : Mar 24th, 2008 at 9:34 pm.
Proud to be Philippine made...
Reply With Quote  
Join Date: Apr 2008
Posts: 34
Reputation: techtix is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
techtix techtix is offline Offline
Light Poster

Re: help!how to write file into notepad in VB?

  #3  
Apr 3rd, 2008
The FSO option works great if you are writing to a text file, but it would still need to be opened.

Simple:
Call Shell("NotePad.exe " & FileName, vbNormalFocus)

Better:
Private Const SW_SHOWNORMAL As Long = 1

Private Declare Function ShellExecute Lib "shell32.dll" _
   Alias "ShellExecuteA" _
  (ByVal hwnd As Long, _
   ByVal lpOperation As String, _
   ByVal lpFile As String, _
   ByVal lpParameters As String, _
   ByVal lpDirectory As String, _
   ByVal nShowCmd As Long) As Long

Call ShellExecute(Me.hWnd, "Open", "c:\TextFile.txt", vbNullString, vbNullString, SW_SHOWNORMAL)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 10:43 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC