-
1 Attachment(s)
ABOUT STRING READING FROM textfile
Hello,
I got a text file with that kind of data
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.
Many thanks
-
Re: ABOUT STRING READING FROM textfile
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
Good Luck
-
Re: ABOUT STRING READING FROM textfile
Many thanks for you reply, i was trying to compile your code and when button click i got
"compiler error: variable not defined " , highlight to this code "ReDim Preserve MyArray(List1.ListCount) As String"
Do you know what it could be problem?
Thanks
-
Re: ABOUT STRING READING FROM textfile
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
-
Re: ABOUT STRING READING FROM textfile
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
-
Re: ABOUT STRING READING FROM textfile
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
-
Re: ABOUT STRING READING FROM textfile
Sorry i am not cleared what you mean , can you explain more about it?
Thanks
-
Re: ABOUT STRING READING FROM textfile
You have this:
Quote:
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):
Quote:
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:
Quote:
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 "/"
-
Re: ABOUT STRING READING FROM textfile
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.
Thanks
-
Re: ABOUT STRING READING FROM textfile
I don't understand that. Use VB6 -or- VB.net and try again
-
Re: ABOUT STRING READING FROM textfile
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"
-
1 Attachment(s)
Re: ABOUT STRING READING FROM textfile
Thanks for your info, I think i havn't seen the code to load on the Textbox corresponding to listbox, is that code loading to listbox items?
Anyway i have attach my sample BINARY(EXE) in .NET and sample data as well, so you will see exactly what the function look like.
Many thanks
-
Re: ABOUT STRING READING FROM textfile
Shouldn't you be posting this is the .Net section if your program is .Net advise you get in VB6 will be different and may not work.
-
Re: ABOUT STRING READING FROM textfile
something you are doing :
Code:
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) :
Code:
Process.Start("WGET\wget.exe", ("http://gb.archive.ubuntu.com/ubuntu/" & Me.textBox1.Text))
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
-
Re: ABOUT STRING READING FROM textfile
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
-
1 Attachment(s)
Re: ABOUT STRING READING FROM textfile
so, seems as if you're looking for a way to read the file as a bounch of records and that those records might have different length. Moreover you cannot change the file itself to make sure it can respect a true standard as per start and end of records.
Not an easy job, but regExp can help in parsing it.
I am not reading it each time , I read it all at once to load the listBox, and in listBox I put objects that hold all infos. It might be done better (could be faster, smarter,...) but have a look at how I loaded listbox and then how richtextbox is populated on (single) click
-
Re: ABOUT STRING READING FROM textfile
Thanks for your reply, but the project you are attaching in VB.NET, What i need is in VB6. I know how to translate any .net language conversion such as VC++ .NET , VB.NET , no problem. What i need is in VB6 as i don't know nothing about it.
Thanks
-
Re: ABOUT STRING READING FROM textfile
then let me send your post back to vb 6.0 forum
-
Re: ABOUT STRING READING FROM textfile
if what you need is a different way to read from a file in vb 6.0, you might find something of interesting here:
http://www.codeguru.com/forum/showth...highlight=file
(look also last answers)
and here:
http://www.codeguru.com/forum/showth...5994#post65994
-
Re: ABOUT STRING READING FROM textfile
Have you tried the code in post #2???
-
Re: ABOUT STRING READING FROM textfile
Would you please also NOT post rar-archives, because some of us have problems with some rar formats, as it seems.
Please post .zip files which everybody is able to open.
Then let me put a question: what was wrong with the sample I gave?
It should read all alarm blocks, no matter how many empty lines it encounters between blocks.
-
Re: ABOUT STRING READING FROM textfile
Quote:
Originally Posted by
davidkhan
Many thanks for you reply, i was trying to compile your code and when button click i got
"compiler error: variable not defined " , highlight to this code "ReDim Preserve MyArray(List1.ListCount) As String"
Do you know what it could be problem?
Thanks
Most likely you did not define the variable. The code given is not a complete program but rather a couple of routines. You need to define any variables that will be used.
-
Re: ABOUT STRING READING FROM textfile
Quote:
Originally Posted by
WoF
some of us have problems with some rar formats, as it seems.
try 7-zip. it is free and opens rar...
-
Re: ABOUT STRING READING FROM textfile
I paid a few $ to upgrade to WinZip 12.0
It's great, opens CAB files, and RAR, and ARJ, etc
-
Re: ABOUT STRING READING FROM textfile
Winrar opens pretty much everything as well. Lots of files on the internet are in Rar format. Everyone should have something to open them. In general RAR has a tigher compression resultign in smaller files and can handle larger files than Zip but the win rar program supports about everything you would ever need to do.
7Z, ACE, ARJ, BZ2, CAB, GZ, ISO, JAR, LZH, TAR, UUE, Z
-
1 Attachment(s)
Re: ABOUT STRING READING FROM textfile
Hello, sorry about the RAR file, i will post it in ZIP file again, but just for advice i have been using WINRAR for 5 years , whenever i need it i download straight from their web,no serial need , no crack but it can do most of the function without even popup reminder to register.
Regarding about the gentleman "WoF" , i when i testing ,there is nothing load to the textbox , but anyway rather than just explaining i will attach my sample binary in VB.net and sample data again in ZIP.
If you want to test big file size like 30MB or something please download from http://gb.archive.ubuntu.com/ubuntu/...6/Packages.bz2 or some other package you want
Thanks
-
1 Attachment(s)
Re: ABOUT STRING READING FROM textfile
***? Do you think we're crazy? We don't run any .exe's around here.
I did download and open your CSV file. From the contents, I can probably guess what you're about to attempt, and we'll stop it right now.
EDIT: Upgraded to WinZip 14.0 for FREE! Glad I bought the upgrade for 1 year. ZIPX is probably the best, but nobody can open them
-
Re: ABOUT STRING READING FROM textfile
Quote:
Originally Posted by
dglienna
***? Do you think we're crazy? We don't run any .exe's around here.
at least, not if we cannot first get the sources from it...Ever tried Lutz Roeder Reflector?
-
Re: ABOUT STRING READING FROM textfile
Maybe it downloads every 14th link after some phrase? No thanks...
-
Re: ABOUT STRING READING FROM textfile
I got a look at sources of first exe he attached (not at this last one), and the download was manual (but did not worked on my system). No automathic download was there. He simply parsed the cvs file to show a list of package you could find at ubuntu site, and to give you infos on the package you selected. Nothing of harmful in that. The only strange thing is the request to translate code in Vb 6.0, which seems a step back, plus the request to access a sequential file like it were an indexed one by a developer who stated he could deal with Vb.Net, C#, Visual C, but know nothing of Vb6.0...and of ascii files.
-
Re: ABOUT STRING READING FROM textfile
hello , eventhough i make extesion CSV , it is not csv, not comma seperated, not tab seperated , it is just plain file, because when you extract http://gb.archive.ubuntu.com/ubuntu/...6/Packages.bz2 file has no extension, so i make extension something else. So you can just open in simple text editor.
Actually i was just impress Ubunu Synaptic Package Manager , and just try for one step, but it is too far to be like that.
Anyway thanks for all replies.
Thanks