ALARM= ALARM1
ZONE= ZONE6
DESCRIPTION= NEED TO REPLACE
ALARM= ALARM5
ZONE= ZONE5
DESCRIPTION= OK FOR 2 YEAR
ALARM= ALARM9
ZONE= ZONE7
DESCRIPTION= NEED MAINTANENCE
When textfile contain "ALARM=" i can load alarm name to listbox with the code below and display
ALARM1
ALARM5
ALARM9 on the listbox
'+++++++++++++++++++++++++
Private Sub Command1_Click()
nFileNum = FreeFile
Open "C:\3.txt" For Input As nFileNum
lLineCount = 1
Do While Not EOF(nFileNum)
Line Input #nFileNum, sNextLine
sNextLine = sNextLine & vbCrLf
sText = sNextLine
If InStr(sText, "ALARM=") = 1 Then
List1.AddItem (Mid(sText, 7, (Len(sText) - 7)))
End If
Loop
Close nFileNum
End Sub
'++++++++++++++++++
What i want now is this function
Private Sub List1_Click()
text1.text= ?????????
End Sub
I mean ,when i click ALARM1 on list item i want to display
ALARM= ALARM1
ZONE= ZONE6
DESCRIPTION= NEED TO REPLACE
When i click ALARM9 on list item i want to display
ALARM= ALARM9
ZONE= ZONE7
DESCRIPTION= NEED MAINTANENCE
And so on, there is one space line between these group.
I have attach my sample project. That will be great if anyone can find the solution.
hmmm... from your code I bet the entries into the list box are not quite what you are expecting...
Code:
If Left(sNextLine, 6) = "ALARM=" Then
List1.AddItem sNextLine
Redim Preserve MyArray(List1.ListCount) As String
MyArray(List1.ListCount) = sNextLine
Else
MyArray(List1.ListCount) = MyArray(List1.ListCount) & sNextLine
End If
Then...
Code:
Private Sub List1_Click()
Dim ForLoopCounter As Integer
For ForLoopCounter = 0 To List1.ListCount - 1
If List1.Selected(ForLoopCounter) = True Then
Text1.Text = MyArray(ForLoopCounter + 1)
Exit For
End If
Next ForLoopCounter
End Sub
You need to modify YOUR code to his, or HIS code to yours. Can't mix variable names. It just double-spaces lines, but you can put YOUR If string inside of the loop. (Hint)
Here's two ways:
Code:
Option Explicit
Private Sub Form_Load()
Dim x As Integer, st As String, y As Integer
Dim ff As Integer
Dim strBuff As String
Dim str() As String
ff = FreeFile
Open App.Path & "\to do.txt" For Input As #ff
strBuff = Input(LOF(ff), ff)
Close #ff
' ----------------- two ways to skin a cat --------------
MsgBox "Lines = " & Len(strBuff) - Len(Replace(strBuff, vbCrLf, "x")) + 1
' -------------------------------------------------------
str() = Split(strBuff, vbCrLf)
MsgBox "There are " & UBound(str) + 1 & " lines in the file"
Dim words() As String
For x = 0 To UBound(str)
words = Split(str(x)) ' Split into WORDS
For y = 0 To UBound(words)
st = st & str(x) & vbCrLf & vbCrLf ' one line for each word
Next y
Next x
MsgBox st
End Sub
Thank for your info, the code you are providing is to display all lines from file to messagebox , as i mention on this thread and in my code sample i already got loading require items ( "ALARM1", "ALARM5" , "ALARM9" )on listbox.
What i want is, When i click "ALARM9" on listbox i want to display on textbox
ALARM= ALARM9
ZONE= ZONE7
DESCRIPTION= NEED MAINTANENCE """only"""
When i click "ALARM1" on listbox i want to display on textbox
ALARM= ALARM1
ZONE= ZONE6
DESCRIPTION= NEED TO REPLACE """only"""
When i click "ALARM5" on listbox i want to display on textbox
ALARM= ALARM5
ZONE= ZONE5
DESCRIPTION= OK FOR 2 YEAR """only"""
Thanks
Last edited by davidkhan; February 21st, 2010 at 09:34 AM.
I thought you'd get that part. If you want to display three things at once, put them on the same line! Separate them with a character that won't be used. / , * ~ are usually OK
ALARM= ALARM1
ZONE= ZONE6
DESCRIPTION= NEED TO REPLACE
ALARM= ALARM5
ZONE= ZONE5
DESCRIPTION= OK FOR 2 YEAR
ALARM= ALARM9
ZONE= ZONE7
DESCRIPTION= NEED MAINTANENCE
If it looked like THIS (first):
ALARM= ALARM1/ZONE= ZONE6/DESCRIPTION= NEED TO REPLACE
ALARM= ALARM5/ZONE= ZONE5/DESCRIPTION= OK FOR 2 YEAR
ALARM= ALARM9/ZONE= ZONE7/DESCRIPTION= NEED MAINTANENCE
It'd be easy to parse, but if you omit the labels, you'd have this:
ALARM1/ZONE6/NEED TO REPLACE
ALARM5/ZONE5/OK FOR 2 YEAR
ALARM9/ZONE7/NEED MAINTANENCE
Which is what it should look like. Just parse CrLf, then "/"
Thanks for your info, it is not possible to change because the file is about 30MB, i am using to with VB.net/CSHARP , it is OK, but now i want to combine with some more useful source code in VB and that is why try to translate in VB6. If you interest , i can sent you this VB.net project.
I think I know, what you want. You want to store the additional info t an Alarm somewhere.
Why not use a collection. You declare a collection for the additional data and then you load like this:
Code:
Private Dim MoreData as Collection
Private Sub LoadFile(FileName As String)
dim a$, b$, c$
List1.Clear
Set MoreData = New Collection
Open FileName For Input As #1
While Not EOF(1)
Line Input #1, a$
If InStr(a$, "ALARM=") Then
List1.AddItem Trim(Mid$(a$, 7))
Line Input #1, a$: b$=Trim(Mid$(a$,6))
Line Input #1, a$: c$=Trim(mid$(a$,13))
MoreData.Add b$ + "/" + c$
End If
Wend
Close #1
End Sub
when an ALARM line is encountered, the Alarm is added to the listbox.
Then 2 more lines are read in, the values concatenated with "/" and added to the collection.
You have to watch out when retrieving the data, though. ListBox elements start with 0, Collections start with 1.
That is, List1.Listitem(0) will contain "ALARM1", but the according data is in
MoreData(1), which is "ZONE6/NEED TO REPLACE"
Private Sub listBox1_MouseDoubleClick(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim num As Integer = Convert.ToInt32(Me.listBox1.SelectedIndex.ToString)
Dim strArray As String() = File.ReadAllLines(".//data1.csv")
Dim item As String = String.Empty
Dim str2 As String
For Each str2 In strArray
If ((str2.IndexOf("Package:") > -1) AndAlso (item.Length > 0)) Then
Me.entries.Add(item)
item = (str2 & ChrW(10))
Else
item = (item & str2 & ChrW(10))
End If
Next
Me.entries.Add(item)
Me.richTextBox1.Text = Me.entries.Item(num)
End Sub
and it seems as if you're doing something else when a toolstrip is reached (but I did not see it in your exe) :
Now, repeat : what are you looking for? Because even if I am amble to see the code you did not posted, I am not able to understand your needing
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Thanks for your reply , i already post complete code in VB.NET and at the top of forum when i start this thread, but people complain and i edit for that. The reason i post binary + sample is to undersatand people exactly what i mean. Even now i might need to delete this EXE as some people even private mail me and complain that this is not VB.NET forum.
This reflector generate code is exactly the same as original code
The only main thing i want is not when a toolstrip is reached , when mouse doubleclick, reading that csv data "BLOCK BY BLOCK to reach empty line of that block" and display on textbox, (that means not line counting , not ..........., data might contain 3 line, 4 line 100 lines in one BLOCK as like in the sample file i sent) , that is all i need .
the other function i don't need that.
Thanks
Last edited by davidkhan; February 25th, 2010 at 04:44 AM.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.