|
-
Sep 17th, 2002, 07:53 AM
#1
Thread Starter
Lively Member
Take part of all lines in a text box
I have several lines that are like this:
5:16pm up 9 min(s), 1 user, load average: 0.03, 0.06, 0.04
6:16pm up 9 min(s), 2 user, load average: 0.03, 0.06, 0.04
7:16pm up 9 min(s), 3 user, load average: 0.03, 0.06, 0.04
I just what this part of the line(0.03, 0.06, 0.04)
Anyone has an idea? I don´t!
-
Sep 17th, 2002, 07:57 AM
#2
Frenzied Member
Well
if you now every line of "5:16pm up 9 min(s), 1 user, load average:" then you could use the VB Replace function
to replace 5:16pm up 9 min(s), 1 user, load average: with " "
"Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
- Zack de la Rocha
Hear me roar.
-
Sep 17th, 2002, 08:46 AM
#3
Frenzied Member
Assuming that there is a CR/LF pair at the end of each line, you could always do something simple like:
VB Code:
Temp1 = Mid(Text1, 43)
MsgBox Left(Temp1, 16)
Temp2 = Mid(Temp1, 43 + 16 + 2)
MsgBox Left(Temp2, 16)
Temp3 = Mid(Temp2, 43 + 16 + 2)
MsgBox Left(Temp3, 16)
If you don't like the hard-coded numbers, do a locate for the words "average:" for the starting point, and VBCrLf for the end point.
-
Sep 18th, 2002, 08:54 AM
#4
Thread Starter
Lively Member
Sorry but the number Cr/LF isn´t always pair, anyone has more ideas?
-
Sep 18th, 2002, 09:07 AM
#5
Frenzied Member
You need to code something like the following algorithm, based around the colons in the string:
Code:
String = YourTextBoxString
LOOP, while String Length > 16
NewString = String, starting at the location of ":" + 1
IF 1st character of NewString is a space THEN
UseFullString = Next 16 characters from NewString
END IF
String = NewString, starting at location 17
END LOOP
-
Sep 18th, 2002, 09:10 AM
#6
VB Code:
Private Function ReturnLastDigitsOfLine(ByVal strWholeLine As String)
Dim intChrCounter As Integer
ReturnLastDigitsOfLine = ""
For intChrCounter = 1 To Len(strWholeLine)
If Not IsNumeric(Mid(Right(strWholeLine, intChrCounter), 1, 1)) Then
If Not ((Mid(Right(strWholeLine, intChrCounter), 1, 1)) = "," Or _
(Mid(Right(strWholeLine, intChrCounter), 1, 1)) = "." Or _
(Mid(Right(strWholeLine, intChrCounter), 1, 1)) = " ") Then
ReturnLastDigitsOfLine = Trim(Right(strWholeLine, intChrCounter - 1))
Exit For
End If
End If
Next intChrCounter
End Function
Usage:
VB Code:
Private Sub Form_Load()
Dim strTemp As String
strTemp = "5:16pm up 9 min(s), 1 user, load average: 0.03, 0.06, 0.04"
MsgBox ReturnLastDigitsOfLine(strTemp)
End Sub
-
Sep 18th, 2002, 09:36 AM
#7
Frenzied Member
But that only gets the last bit of the string, rather than each item as it appears....
I understand that the string in the text box looks like this:
Code:
Text1 = "5:16pm up 9 min(s), 1 user, load average: 0.03, 0.06, 0.04" & vbCrLf & _
"6:16pm up 9 min(s), 2 user, load average: 0.03, 0.06, 0.05" & vbCrLf & _
"7:16pm up 9 min(s), 3 user, load average: 0.03, 0.06, 0.06"
and so this code will process that string, displaying the end of each line in the message box. It decodes the string based on the ":"
VB Code:
strString = Text1
While Len(strString) > 10
strNewString = Mid(strString, InStr(strString, ":") + 1)
If Left(strNewString, 1) = " " Then
MsgBox Mid(strNewString, 2, 16)
End If
strString = Mid(strNewString, 17)
Wend
-
Sep 18th, 2002, 09:41 AM
#8
okay now you've lost me completely 
I have several lines that are like this:
5:16pm up 9 min(s), 1 user, load average: 0.03, 0.06, 0.04
I just want this part of the line(0.03, 0.06, 0.04)
Sounds like he wants everything past the last ":" character, no?
-
Sep 18th, 2002, 09:46 AM
#9
Frenzied Member
Maybe we will have to see what the original poster says....
I was also taking the subject of the post: "Take part of all lines in a text box" ....
meaning that the text box had multiple lines in it.
If we take it that the text box only has one line in it, then a simple InStrRev looking for the ":" is all that is needed.
-
Sep 19th, 2002, 05:45 AM
#10
Thread Starter
Lively Member
I still can't get the last part of each line to the text box, i have tried this to take the part that i don't want, but the result is nothing, i don't know what i am doing wrong:
/
XP = FrmPrincipal.Text1
Do While Len(XP) > 10
XPP = Left(XP, 60)
If Left(XPP, 1) = " " Then
MsgBox Mid(XPP, 1, 60)
XP = Replace(XP, XPP, "")
End If
XP = Mid(XPP, 17)
Loop
/
someone has any idea about this?
thank's in advance
-
Sep 19th, 2002, 06:15 AM
#11
Frenzied Member
Do While Len(XP) > 10
XPP = Left(XP, 60)
At this point you only have 60 characters in XPP. You have thrown away the rest of the text box. Is this what you wanted to do??
If Left(XPP, 1) = " " Then
MsgBox Mid(XPP, 1, 60)
XP = Replace(XP, XPP, "")
End If
You show the MsgBox ONLY if the first character is a space.
What did you intend the "Replace" statement to do?
How about replacing that bit of code with this and see if its what you wanted:
VB Code:
Do While Len(XP) > 10
' find where the colon is in the string
x = InStr(1, XP, ": ")
' grab the rest of the string, after the colon
XPP = Mid(XP, x + 2)
' display the first 17 characters
MsgBox Left(XPP, 17)
' Loop around, with the rest of the string
XP = Mid(XPP, 17)
Loop
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
|