Results 1 to 5 of 5

Thread: loading problom im having

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    54

    Lightbulb loading problom im having

    Ok the form will have a combo box with 3 items in it (ON ENTER,ON EXIT and ON BLAH) there is also a richtextbox and a file stored in C:\POPdata.txt (below shows whats in the txt file)
    now what i want to do is when the user selects one of the items i need it to load that section and make richtextbox just that section for example if ON ENTER is selected it would just load

    AFDASDFASDGFAS
    DGHSGSFGSFGSG
    3645635634444
    From
    ON ENTER {
    AFDASDFASDGFAS
    DGHSGSFGSFGSG
    3645635634444
    }
    ================================TXT FILE===============
    ON EXIT {
    FFFFFFFGGGGG'
    FFFFFFFVVVVVV
    HSHGSGHSGL;K
    }

    ON ENTER {
    AFDASDFASDGFAS
    DGHSGSFGSFGSG
    364563563

    ON BLAH {
    4444444444
    XXXXXXXXXX
    DXXXXXDDD
    XXXXXXXXXA
    FFFFFFFFF
    }

    thanks for your help!

  2. #2
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    If I undestand you correctly you need to open a file and load some data from it into a let's say a textbox based on currewnt user selection. If that's the case thenyou may follwo this simple logic:
    VB Code:
    1. Dim strLine As String
    2. Dim Flag As Boolean
    3. Dim strText As String
    4.  
    5. Open myfile For Input As #1
    6.     Do
    7.         Line Input #1, strLine
    8.         If LCase(strLine) = "my text" Then
    9.             'set Flag
    10.             If Flag = True then str Text =strText & strLine & vbNewLine
    11.         End If
    12.     Loop Until EOF(1)
    13. Close #1
    14. Text1.Text = strText
    Roy

  3. #3
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    A small correction:
    VB Code:
    1. Dim strLine As String
    2. Dim Flag As Boolean
    3. Dim strText As String
    4.  
    5. Open myfile For Input As #1
    6.     Do
    7.         Flag = False
    8.         Line Input #1, strLine
    9.         If LCase(strLine) = "my text" Then
    10.             Flag = True
    11.         End If
    12.         If Flag = True then str Text =strText & strLine & vbNewLine
    13.     Loop Until EOF(1)
    14. Close #1
    15. Text1.Text = strText
    Roy

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    Or
    VB Code:
    1. Private msBuffer As String
    2.  
    3. Private Sub Form_Load()
    4.   OpenFile "C:\POPData.txt"
    5.   List1.AddItem "ON EXIT"
    6.   List1.AddItem "ON ENTER"
    7.   List1.AddItem "ON BLAH"
    8. End Sub
    9.  
    10. Private Sub List1_Click()
    11.   If List1.ListIndex < 0 Then Exit Sub
    12.  
    13.   Text1.Text = GetSection(List1.List(List1.ListIndex))
    14. End Sub
    15.  
    16. Private Sub OpenFile(ByVal sFile As String)
    17.   Dim iFile As Integer
    18.  
    19.   iFile = FreeFile
    20.   Open sFile For Binary Access Read As iFile
    21.     msBuffer = Space(LOF(iFile))
    22.     Get #iFile, , msBuffer
    23.   Close iFile
    24. End Sub
    25.  
    26. Function GetSection(ByVal sSection As String) As String
    27.   Dim lPos As Long
    28.  
    29.   lPos = InStr(1, msBuffer, sSection & " {" & vbCrLf, vbTextCompare)
    30.   If lPos = 0 Then Exit Function
    31.   lPos = lPos + Len(sSection) + 4
    32.   GetSection = Mid(msBuffer, lPos, InStr(lPos, msBuffer, vbCrLf & "}", vbTextCompare) - lPos)
    33. End Function

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    54

    Talking thank you aaron

    that code worked great thanks it was just what i was looking for but now how would i save just that section to the file without deleting the rest of the stuff there?

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