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

''General_Declaration of the form
Dim sItem As String
Dim sPacket As String
Dim sSourceIP As String
Dim temp As LinkList
Dim Head As LinkList
Dim First As LinkList  'Alwyas Points Starting of the List
Dim i As Integer

Private Sub Class_Initialize()
Set pNext = gthing
End Sub

Private Sub Class_Terminate()
Set pNext = Nothing
End Sub

'''Insert in to a node
Private Sub InsertNode()


    'Do While Not UCase(sItem) = "END"
    'i = i + 1

    'sItem = InputBox("Enter the Item", , "")
    'sItem = Trim(sItem)
    sPacket = InputBox("Packet Type:", , "")
    sSourceIP = InputBox("Source IP Address:", , "")

        If Head Is Nothing Then
            Set temp = New LinkList
            temp.Protocol_Type = sPacket
            temp.Source_IP_Add = sSourceIP
            Set Head = temp
            Set First = Head
        Else
            Set temp = New LinkList
            temp.Protocol_Type = sPacket
            temp.Source_IP_Add = sSourceIP
            Set Head.pNext = temp
            Set Head = temp
        End If
        'If UCase(sItem) = "END" Then
        Set Head.pNext = Nothing
       ' End If
    'Loop
    
End Sub
'''''''---------------------------------------------------
'Delete a Particular Node

Private Sub DeleteNode()
Dim sDelStr As String
Dim d As LinkList
Dim holdPrev As LinkList 'Hold Previous location while deleting
Dim a
Set temp = Nothing
Set p = Nothing
Set holPrev = Nothing
Set d = First


    If d Is Nothing Then
'        Text1.Text = "No Items In the List
' ! Insert Something 'before Delete !"
    a = MsgBox("NO MATCH FOUND. NO RECORD DELETED", vbInformation)
        Exit Sub
    End If
    
sDelStr = InputBox("Please Enter Soure IP Address Of The Packet That You Want To Delete: ")
sDelStr = UCase(sDelStr)


  Do While Not d Is Nothing
  
  
        If UCase(d.Source_IP_Add) = sDelStr Then
            a = MsgBox("Are you sure", vbOKCancel)
            If a = vbOK Then
                If holPrev Is Nothing Then
                    Set First = d.pNext
                    'Call DisPlayNode
                    Exit Sub
                End If
                Set d = holPrev
                Set d.pNext = temp.pNext
                If d.pNext Is Nothing Then  'if deleted node is last node
                    Set Head = d
                End If
                a = MsgBox("RECORD DELETED", vbInformation)
                Exit Sub
            Else
                a = MsgBox("RECORD NOT DELETED", vbInformation)
                Exit Sub
            End If

            
       Else
           Set holPrev = d
           Set temp = d.pNext
           Set d = d.pNext
        End If
    Loop
     a = MsgBox("NO MATCH FOUND. NO RECORD DELETED", vbInformation)
     Set p = Nothing
End Sub

''''''-------------------------------------
'Display all Nodes in the list

Private Sub DisPlayNode()
Dim p As LinkList
Dim a
Dim msg

Set p = First
If p Is Nothing Then
    a = MsgBox("NO RECORDS TO DISPLAY", vbInformation)
Exit Sub
End If

msg = "ProType|SourceIPAdd"

Do While Not p Is Nothing
        msg = msg & vbNewLine & p.Protocol_Type & vbTab & p.Source_IP_Add
        
        Set p = p.pNext
Loop
a = MsgBox(msg, vbInformation)

Set p = Nothing
End Sub
''''-----------------------

Private Sub SearchNode()
Dim d As LinkList
Set d = First
Dim sSearch As String
Dim a

sSearch = InputBox("Please Enter Source IP Address :")
sSearch = UCase(sSearch)

Do While Not d Is Nothing
    If UCase(d.Source_IP_Add) = sSearch Then
        a = MsgBox("RECORD FOUND" & vbNewLine & d.Protocol_Type & vbTab & d.Source_IP_Add, vbInformation)
        Exit Sub
    Else
        Set d = d.pNext
    End If
Loop
a = MsgBox("NO MATCH FOUND", vbInformation)

End Sub

'''''Cleanup all allocated memory

Private Sub free()
Set temp = Nothing
Set Head = Nothing
Set First = Nothing
Set holdPrev = Nothing
End Sub

Private Sub cmdAdd_Click()
    Call InsertNode
End Sub

Private Sub cmdDelete_Click()
    Call DeleteNode
End Sub

Private Sub cmdDetect_Click()
    Call SearchNode
End Sub

Private Sub cmdDisplay_Click()
   Call DisPlayNode

End Sub

Private Sub cmdExit_Click()
    Call free
    Unload Me
End Sub

i didnt read your code. but if writing on a notepad is your problem, i hope this helps.

Dim fso As New FileSystemObject
Dim strm As TextStream
Set strm = fso.OpenTextFile("c:\test.txt", ForWriting)
strm.WriteLine ("String to write")

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)
This article has been dead for over six months. Start a new discussion instead.