Hi, i got a textfile contain an IP address. Then i need to read iyt and pass into the application to able to run my application. How do i read from a textfile using vb.net? Can u pls show mi some example codes? Thanks all...
Printable View
Hi, i got a textfile contain an IP address. Then i need to read iyt and pass into the application to able to run my application. How do i read from a textfile using vb.net? Can u pls show mi some example codes? Thanks all...
if you know the url already....
if you dont know the url you could try this...VB Code:
[Color=Blue]Private[/COLOR] [Color=Blue]Sub[/COLOR] Button1_Click([Color=Blue]ByVal[/COLOR] sender [Color=Blue]As[/COLOR] System.Object, [Color=Blue]ByVal[/COLOR] e [Color=Blue]As[/COLOR] System.EventArgs) [Color=Blue]Handles[/COLOR] Button1.Click [Color=Blue]Dim[/COLOR] sReader [Color=Blue]As[/COLOR] [Color=Blue]New[/COLOR] StreamReader([Color=Blue]New[/COLOR] FileStream("C:\your_textfile_path.txt", FileMode.Open)) [Color=Blue]Dim[/COLOR] url [Color=Blue]As[/COLOR] [Color=Blue]String[/COLOR] = "http://google.com" [Color=Green]'///[/COLOR] [Color=Green]your[/COLOR] [Color=Green]link[/COLOR] [Color=Green]to[/COLOR] [Color=Green]use[/COLOR] [Color=Green]from[/COLOR] [Color=Green]in[/COLOR] [Color=Green]the[/COLOR] [Color=Green]textfile. [/COLOR] [Color=Blue]While[/COLOR] [Color=Blue]Not[/COLOR] sReader.Peek [Color=Blue]If[/COLOR] sReader.ReadLine = url [Color=Blue]Then [/COLOR] Process.Start("IEXPLORE.EXE", url) [Color=Green]'///[/COLOR] [Color=Green]or[/COLOR] [Color=Green]to[/COLOR] [Color=Green]use[/COLOR] [Color=Green]the[/COLOR] [Color=Green]default[/COLOR] [Color=Green]browser[/COLOR] [Color=Green]window[/COLOR] [Color=Green]rather[/COLOR] [Color=Green]than[/COLOR] [Color=Green]internet[/COLOR] [Color=Green]explorer... [/COLOR] [Color=Green]'///Process.Start[/COLOR] [Color=Green]([/COLOR] [Color=Green]url[/COLOR] [Color=Green])[/COLOR] [Color=Green] [/COLOR] [Color=Blue]End[/COLOR] [Color=Blue]If [/COLOR] [Color=Blue]End[/COLOR] [Color=Blue]While [/COLOR] sReader.Close() [Color=Blue]End[/COLOR] [Color=Blue]Sub[/COLOR]
VB Code:
[Color=Blue]Private[/COLOR] [Color=Blue]Sub[/COLOR] Button2_Click([Color=Blue]ByVal[/COLOR] sender [Color=Blue]As[/COLOR] System.Object, [Color=Blue]ByVal[/COLOR] e [Color=Blue]As[/COLOR] System.EventArgs) [Color=Blue]Handles[/COLOR] Button2.Click [Color=Blue]Dim[/COLOR] sReader [Color=Blue]As[/COLOR] [Color=Blue]New[/COLOR] StreamReader([Color=Blue]New[/COLOR] FileStream("C:\your_textfile_path.txt", FileMode.Open)) [Color=Blue]Dim[/COLOR] url [Color=Blue]As[/COLOR] [Color=Blue]String[/COLOR], strText [Color=Blue]As[/COLOR] [Color=Blue]String [/COLOR] [Color=Blue]While[/COLOR] [Color=Blue]Not[/COLOR] sReader.Peek strText = sReader.ReadLine [Color=Blue]If[/COLOR] strText.StartsWith("http://") [Color=Blue]Then [/COLOR] url = strText Process.Start("IEXPLORE.EXE", url) [Color=Green]'///[/COLOR] [Color=Green]or[/COLOR] [Color=Green]to[/COLOR] [Color=Green]use[/COLOR] [Color=Green]the[/COLOR] [Color=Green]default[/COLOR] [Color=Green]browser[/COLOR] [Color=Green]window[/COLOR] [Color=Green]rather[/COLOR] [Color=Green]than[/COLOR] [Color=Green]internet[/COLOR] [Color=Green]explorer... [/COLOR] [Color=Green]'///Process.Start[/COLOR] [Color=Green]([/COLOR] [Color=Green]url[/COLOR] [Color=Green])[/COLOR] [Color=Green] [/COLOR] [Color=Blue]End[/COLOR] [Color=Blue]If [/COLOR] [Color=Blue]End[/COLOR] [Color=Blue]While [/COLOR] sReader.Close() [Color=Blue]End[/COLOR] [Color=Blue]Sub[/COLOR]
If i am using a data adapter, how do i change e connection by reading the text file?
Y does ur code got this line? i not using web application one.
strText.StartsWith("http://")
It has nothing to do with web or windows application. It just searches for strings that start with "http://"Quote:
Originally posted by berrie_luv
If i am using a data adapter, how do i change e connection by reading the text file?
Y does ur code got this line? i not using web application one.
strText.StartsWith("http://")
If I understood you well, you are searching for a way to extract an IP address from a text file and pass it to your connection string. Is that right? Do you know the format of IP in the text, is it going to be decimal or binary? Is it nested in a tag or just somewhere is the file?
the format of the ip address is in decimal one.. wat u mean by nested in a tag or just somewhere is the file??
For example your file may read:
<ip>192.168.1.1</ip>
or maybe
IP Address=192.168.1.1
or non of the aboves and just somewhere in the text there is 192.168.1.1. just like the previous sentence.
Hi, if i wan save e call text file (ip address) in a form, then the rest of my forms will call my ip address form 1st before going in each of the various form functions, how to do ah?
You want the contents of the file be available to all of your forms? You can keep it in a module or class level variable. But if the data is large, you must be careful of the resources it may require.
Ok, i save it in a class. Then how to call e class in my form? how to import e class to my form?