[Help]Textbox / Reading

Posts 1–15 of 28 · Page 1 of 2
[Help]Textbox / Reading
Hello MPGH VB 2008 Coders
i want your Help ...
How i can make the TextBox Read this ///
[PHP]
[Infos]
Info1= 10 / i want the Textbox1 Read this
Info2= 20 / i want the Textbox2 Read this
[/PHP]
Please Help
Idk if that By ReadFiles
and Thank You
Quote Originally Posted by mo3ad001 View Post
Hello MPGH VB 2008 Coders
i want your Help ...
How i can make the TextBox Read this ///
[PHP]
[Infos]
Info1= 10 / i want the Textbox1 Read this
Info2= 20 / i want the Textbox2 Read this
[/PHP]
Please Help
Idk if that By ReadFiles
and Thank You
FileStream
StreamReader

Have a look in here: http://msdn.microsoft.com/en-us/libr...eamreader.aspx
Quote Originally Posted by 'Bruno View Post
FileStream
StreamReader
do you can Post Code how to use StreamReader or FileStream to read this ?
the link does not help me how to Read The Number after the Info1
Just how to Read file and i know how to read filesssss
Quote Originally Posted by mo3ad001 View Post
do you can Post Code how to use StreamReader or FileStream to read this ?
the link does not help me how to Read The Number after the Info1
Just how to Read file and i know how to read filesssss
get the string and then manipulate the string with IndexOf and Substring to get the number or so..
[php]
Private Function Sb(ByVal source As String, ByVal start As String, ByVal ending As String)
Dim part1() As String = Split(source, start)

If UBound(part1) > 0 Then
Dim part2() As String = Split(part1(1), ending)

If UBound(part2) > 0 Then
Return part2(0)
Else
Return -2
End If
Else
Return -1
End If
End Function

[/php]

[php] Using streami As New IO.StreamWriter("C:\test.txt")
streami.Write("[Infos]" & vbNewLine _
& "<info1>10</info1>" & vbNewLine _
& "<info2>20</info2>")
End Using[/php]

(Bad method)

[php] Dim full As String
Dim info1, info2 As Integer

Using reader As New IO.StreamReader("C:\test.txt")
full = reader.ReadToEnd

info1 = CInt(Sb(full, "<info1>", "</info1>"))
info2 = CInt(Sb(full, "<info2>", "</info2>"))
End Using[/php]

Idk what you are going to do exactly....
[php]using streami as new io.streamwriter("C:\test.txt", false)
streami.write("Text")
end using[/php]

I recommend you using .ini...you can sure do this with a streamwriter/streamreader but meh....
For tags he could just use XML.. plus maybe he is trying to read a file created by something else and not by him.. so... it maybe has to be XXX = X

anyway i dunno..
Ya...ini/xml...proper method...

Let's wait for his answer...

@OP, please offer more details.
OK, I quickly wrote a function for both methods (Tags / Assignment). You can use anyone based on your string structure. First add the following Enumeration and Function to the class:

Code:
Enum SeperationMethod
        Assignment
        Tags
    End Enum
    Function ExtractVariable(ByVal InputString As String, ByVal variableToExtract As String, Optional ByVal sepMethod As SeperationMethod = SeperationMethod.Assignment)
        Dim str As String = InputString
        Dim file As String = My.Computer.FileSystem.GetTempFileName() & Rnd() * 999999 & ".xxx"
        Dim final As String = ""
        My.Computer.FileSystem.WriteAllText(file, str, False)
        Dim reader As New IO.StreamReader(file)
        While Not reader.EndOfStream
            Dim curline As String = reader.ReadLine
            If Not curline.Trim = vbNullString Then
                If curline.Contains(variableToExtract) Then
                    If sepMethod = SeperationMethod.Assignment Then
                        Dim i1 As Integer = curline.IndexOf("=")
                        final = curline.Substring(i1 + 1)
                    Else
                        Dim i1 As Integer = curline.IndexOf("<" & variableToExtract & ">") + variableToExtract.Length + 3
                        Dim i2 As Integer = curline.IndexOf("</" & variableToExtract & ">", i1) + 1
                        final = Mid(curline, i1, i2 - i1)
                    End If
                End If
            End If
        End While
        reader.Dispose()
        Return final
        Try
            My.Computer.FileSystem.DeleteFile(file, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently, FileIO.UICancelOption.DoNothing)
        Catch ex As Exception
            'MsgBox("Error Deleting Temporary File...")
        End Try
    End Function
Now read the values by calling the function defined above:

If your structure is based on assignment operator '=', then use the Assignment constant:

Code:
Dim Str As String = "[Infos]" & vbCrLf & "Info1 = 10" & vbCrLf & "Info2 = 20"
Dim extractedValue As String = ExtractVariable(Str, "Info1", SeperationMethod.Assignment)
If your structure is based on Tags like XML, then use the Tags constant:

Code:
Dim Str As String = "[Infos]" & vbCrLf & "<Info1>10</Info1>" & vbCrLf & "Info2 = 20"
Dim extractedValue As String = ExtractVariable(Str, "Info1", SeperationMethod.Tags)
Quote Originally Posted by Blubb1337 View Post
[php]
Private Function Sb(ByVal source As String, ByVal start As String, ByVal ending As String)
Dim part1() As String = Split(source, start)

If UBound(part1) > 0 Then
Dim part2() As String = Split(part1(1), ending)

If UBound(part2) > 0 Then
Return part2(0)
Else
Return -2
End If
Else
Return -1
End If
End Function

[/php]

[php] Using streami As New IO.StreamWriter("C:\test.txt")
streami.Write("[Infos]" & vbNewLine _
& "<info1>10</info1>" & vbNewLine _
& "<info2>20</info2>")
End Using[/php]

(Bad method)

[php] Dim full As String
Dim info1, info2 As Integer

Using reader As New IO.StreamReader("C:\test.txt")
full = reader.ReadToEnd

info1 = CInt(Sb(full, "<info1>", "</info1>"))
info2 = CInt(Sb(full, "<info2>", "</info2>"))
End Using[/php]

Idk what you are going to do exactly....
Yes That work Fin thank you
You always
Thank you but exactly the number was example i mean For Every things word number
Note : i don't understand code number1

Quote Originally Posted by Hassan View Post
OK, I quickly wrote a function for both methods (Tags / Assignment). You can use anyone based on your string structure. First add the following Enumeration and Function to the class:

Code:
Enum SeperationMethod
        Assignment
        Tags
    End Enum
    Function ExtractVariable(ByVal InputString As String, ByVal variableToExtract As String, Optional ByVal sepMethod As SeperationMethod = SeperationMethod.Assignment)
        Dim str As String = InputString
        Dim file As String = My.Computer.FileSystem.GetTempFileName() & Rnd() * 999999 & ".xxx"
        Dim final As String = ""
        My.Computer.FileSystem.WriteAllText(file, str, False)
        Dim reader As New IO.StreamReader(file)
        While Not reader.EndOfStream
            Dim curline As String = reader.ReadLine
            If Not curline.Trim = vbNullString Then
                If curline.Contains(variableToExtract) Then
                    If sepMethod = SeperationMethod.Assignment Then
                        Dim i1 As Integer = curline.IndexOf("=")
                        final = curline.Substring(i1 + 1)
                    Else
                        Dim i1 As Integer = curline.IndexOf("<" & variableToExtract & ">") + variableToExtract.Length + 3
                        Dim i2 As Integer = curline.IndexOf("</" & variableToExtract & ">", i1) + 1
                        final = Mid(curline, i1, i2 - i1)
                    End If
                End If
            End If
        End While
        reader.Dispose()
        Return final
        Try
            My.Computer.FileSystem.DeleteFile(file, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently, FileIO.UICancelOption.DoNothing)
        Catch ex As Exception
            'MsgBox("Error Deleting Temporary File...")
        End Try
    End Function
Now read the values by calling the function defined above:

If your structure is based on assignment operator '=', then use the Assignment constant:

Code:
Dim Str As String = "[Infos]" & vbCrLf & "Info1 = 10" & vbCrLf & "Info2 = 20"
Dim extractedValue As String = ExtractVariable(Str, "Info1", SeperationMethod.Assignment)
If your structure is based on Tags like XML, then use the Tags constant:

Code:
Dim Str As String = "[Infos]" & vbCrLf & "<Info1>10</Info1>" & vbCrLf & "Info2 = 20"
Dim extractedValue As String = ExtractVariable(Str, "Info1", SeperationMethod.Tags)
Thank you For Read my Post and Help
But I'm not Copy and Past ....
and i don't understand Your Code
i hope explanation the code
Quote Originally Posted by mo3ad001 View Post
Thank you For Read my Post and Help
But I'm not Copy and Past ....
and i don't understand Your Code
i hope explanation the code
Glad to see that you are not C+P
OK here's the explanation (Excluding easy statements):

Create a string to store temp file path.
Code:
Dim file As String = My.Computer.FileSystem.GetTempFileName() & Rnd() * 999999 & ".xxx"
'Final will store the extracted variable...
'Use WriteAllText method to write the data to the file. We will read the written data using StreamRead class.
'Reader variable defines the new streamreader class and as an input takes the temp file path.

Code:
Dim final As String = ""
My.Computer.FileSystem.WriteAllText(file, str, False)
Dim reader As New IO.StreamReader(file)
'Loop through the read class until the end of file is reached...
'curLine stores the Current Line the reader is reading...
'Check if after trimming the current line the string at least contains something...
'If it contains something then check if it contains the variable name to extract...
'If seperation method is Assignment '=', then create an integer i1 that gets and stores the index of assignment operator with in the current Line...
'Final = Curline.substring(i1+1) 'Extracts the substring i.e; starts extracting from the index of assignment operator '=' to the end of the current line...hence the variable value..
'If separation method is tag based then it extracts two indexes.
1: <VariableToExtract> 'Tag's Opening
2: </VariableToExtract>'Closing Tag

When the indexes are stored we finally call the Mid method to extract the values between strings (equivalent to 'Substring' method).

Code:
While Not reader.EndOfStream
            Dim curline As String = reader.ReadLine
            If Not curline.Trim = vbNullString Then
                If curline.Contains(variableToExtract) Then
                    If sepMethod = SeperationMethod.Assignment Then
                        Dim i1 As Integer = curline.IndexOf("=")
                        final = curline.Substring(i1 + 1)
                    Else
                        Dim i1 As Integer = curline.IndexOf("<" & variableToExtract & ">") + variableToExtract.Length + 3
                        Dim i2 As Integer = curline.IndexOf("</" & variableToExtract & ">", i1) + 1
                        final = Mid(curline, i1, i2 - i1)
                    End If
                End If
            End If
        End While

'As soon the control is outside the loop, dispose the reader from memory so it stops occupying system resources.

'As it is a function, we use the 'Return' keyword to return the variable value...

Code:
reader.Dispose()
Return final
I hope you understand. It's basic and easy if you concentrate a bit
Quote Originally Posted by Blubb1337 View Post
[php]Dim line As String
dim i as integer = 0
Dim info1, info2 As Integer

Using reader As New IO.StreamReader("C:\test.txt")
while not reader.endofstream
line = reader.readline

if line.tolower.contains("info") then
listbox1.items.add(cint(line, "<info" & i & ">", "</info" & i & ">")))
i += 1
end while
End Using [/php]

Tell me, what exactly are you going to do?
exactly i want to make a File to save the Infos and back To Read it
Like a Settings but not Settings i want to infos ..
and i wanna add the infos for listbox items ..
and that Code have Error

Quote Originally Posted by Hassan View Post


Glad to see that you are not C+P
OK here's the explanation (Excluding easy statements):

Create a string to store temp file path.
Code:
Dim file As String = My.Computer.FileSystem.GetTempFileName() & Rnd() * 999999 & ".xxx"
'Final will store the extracted variable...
'Use WriteAllText method to write the data to the file. We will read the written data using StreamRead class.
'Reader variable defines the new streamreader class and as an input takes the temp file path.

Code:
Dim final As String = ""
My.Computer.FileSystem.WriteAllText(file, str, False)
Dim reader As New IO.StreamReader(file)
'Loop through the read class until the end of file is reached...
'curLine stores the Current Line the reader is reading...
'Check if after trimming the current line the string at least contains something...
'If it contains something then check if it contains the variable name to extract...
'If seperation method is Assignment '=', then create an integer i1 that gets and stores the index of assignment operator with in the current Line...
'Final = Curline.substring(i1+1) 'Extracts the substring i.e; starts extracting from the index of assignment operator '=' to the end of the current line...hence the variable value..
'If separation method is tag based then it extracts two indexes.
1: <VariableToExtract> 'Tag's Opening
2: </VariableToExtract>'Closing Tag

When the indexes are stored we finally call the Mid method to extract the values between strings (equivalent to 'Substring' method).

Code:
While Not reader.EndOfStream
            Dim curline As String = reader.ReadLine
            If Not curline.Trim = vbNullString Then
                If curline.Contains(variableToExtract) Then
                    If sepMethod = SeperationMethod.Assignment Then
                        Dim i1 As Integer = curline.IndexOf("=")
                        final = curline.Substring(i1 + 1)
                    Else
                        Dim i1 As Integer = curline.IndexOf("<" & variableToExtract & ">") + variableToExtract.Length + 3
                        Dim i2 As Integer = curline.IndexOf("</" & variableToExtract & ">", i1) + 1
                        final = Mid(curline, i1, i2 - i1)
                    End If
                End If
            End If
        End While

'As soon the control is outside the loop, dispose the reader from memory so it stops occupying system resources.

'As it is a function, we use the 'Return' keyword to return the variable value...

Code:
reader.Dispose()
Return final
I hope you understand. It's basic and easy if you concentrate a bit
now i'm backed to read this wait To Read and thx For this big work
[php]Dim line As String
dim i as integer = 0
Dim info1, info2 As Integer

Using reader As New IO.StreamReader("C:\test.txt")
while not reader.endofstream
line = reader.readline

if line.tolower.contains("info") then
listbox1.items.add(cint(line, "<info" & i & ">", "</info" & i & ">")))
i += 1
end while
End Using [/php]

Tell me, what exactly are you going to do?
from what i read, i think he wants the first line of a document to be in textbox1...
and the second line in a document to be in textbox2...
so... yah.
Quote Originally Posted by mnpeepno2 View Post
from what i read, i think he wants the first line of a document to be in textbox1...
and the second line in a document to be in textbox2...
so... yah.
Thank you for your contribution. . I think they've already figured this out and solved it.
Posts 1–15 of 28 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?