|
-
Nov 14th, 2002, 02:43 PM
#1
Thread Starter
Member
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!
-
Nov 14th, 2002, 03:36 PM
#2
PowerPoster
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:
Dim strLine As String
Dim Flag As Boolean
Dim strText As String
Open myfile For Input As #1
Do
Line Input #1, strLine
If LCase(strLine) = "my text" Then
'set Flag
If Flag = True then str Text =strText & strLine & vbNewLine
End If
Loop Until EOF(1)
Close #1
Text1.Text = strText
-
Nov 14th, 2002, 03:38 PM
#3
PowerPoster
A small correction:
VB Code:
Dim strLine As String
Dim Flag As Boolean
Dim strText As String
Open myfile For Input As #1
Do
Flag = False
Line Input #1, strLine
If LCase(strLine) = "my text" Then
Flag = True
End If
If Flag = True then str Text =strText & strLine & vbNewLine
Loop Until EOF(1)
Close #1
Text1.Text = strText
-
Nov 14th, 2002, 03:53 PM
#4
Or
VB Code:
Private msBuffer As String
Private Sub Form_Load()
OpenFile "C:\POPData.txt"
List1.AddItem "ON EXIT"
List1.AddItem "ON ENTER"
List1.AddItem "ON BLAH"
End Sub
Private Sub List1_Click()
If List1.ListIndex < 0 Then Exit Sub
Text1.Text = GetSection(List1.List(List1.ListIndex))
End Sub
Private Sub OpenFile(ByVal sFile As String)
Dim iFile As Integer
iFile = FreeFile
Open sFile For Binary Access Read As iFile
msBuffer = Space(LOF(iFile))
Get #iFile, , msBuffer
Close iFile
End Sub
Function GetSection(ByVal sSection As String) As String
Dim lPos As Long
lPos = InStr(1, msBuffer, sSection & " {" & vbCrLf, vbTextCompare)
If lPos = 0 Then Exit Function
lPos = lPos + Len(sSection) + 4
GetSection = Mid(msBuffer, lPos, InStr(lPos, msBuffer, vbCrLf & "}", vbTextCompare) - lPos)
End Function
-
Nov 14th, 2002, 08:14 PM
#5
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|