|
Finally get it right. What a mistake i make! Thanks for help!!
|
|
|
|
|
Hello every one..
I am having a VB 2005 application.. Can i use a nested try and catch...
i.e can i have another try can catch block inside a catch block..
I will tell what want to achieve
My application has a distributed DB on 1-4 DB servers (Configurable)
I am reading the Primary Server IP from a text file and then read the remaining servers IP from the setting table in Primary server...
In a single system setup what i am doing is accessing the DB on the network path...
But when the network is down the i will like to access the same DB as local host
The structure is
'get network IP
Tyr
conn.open
catch
'get alternate server IP
conn.open
end try
My intention is to do error handling of second attempt to connect also. So i wanted to put a try and catch block in catch block
Is there any other or better way
Regards
Nishkarsh
|
|
|
|
|
Yes you can but why not put the connection creation in a seperate method and return the connction or nothing, then test the return value and try again if it is nothing
Dim oCon as SQLConnection = nothing
do while ocon is nothing or i > counter
ocon = create connection(sip)
if not ocon is nothing then
exit for
end if
loop
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I am a newbie to VB platform... i wanted to write a program that can compare two text files and display the common strings along with the number of times the strings are found and the line number !
I heard can use string parsing to do the job.Can anyone help me with some codes ,really appreatiate your help.
|
|
|
|
|
mahan wrote: I heard can use string parsing to do the job
No other way to do it, really.
A full on differencing engine is a lot of work. However, File.ReadAllLines will give you a file as a string array, you can easily do that for two files and compare line by line.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Function for Comparing Two Files
Source from .net snippet.
Private Function CompareFiles(ByVal file1 As String, ByVal file2 As String) As Boolean
'Set to true if the files are equal; false otherwise
Dim filesAreEqual As Boolean = False
With My.Computer.FileSystem
' Ensure that the files are the same length before comparing them line by line
If .GetFileInfo(file1).Length = .GetFileInfo(file2).Length Then
Using file1Reader As New FileStream(file1, FileMode.Open), _
file2Reader As New FileStream(file2, FileMode.Open)
Dim byte1 As Integer = file1Reader.ReadByte()
Dim byte2 As Integer = file2Reader.ReadByte()
' If byte1 or byte2 is a negative value, we have reached the end of the file
While byte1 > 0 And byte2 > 0
If (byte1 <> byte2) Then
filesAreEqual = False
Exit While
Else
filesAreEqual = True
End If
'Read the next byte
byte1 = file1Reader.ReadByte()
byte2 = file2Reader.ReadByte()
End While
End Using
End If
End With
Return filesAreEqual
End Function
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
1 - this won't compare words
2 - this won't let him do what he asked for, which was to mark words and lines that are the same
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
i have a listbox that contain ip address of the client, if my server can accept multiple client, how can i send data to the selected client.. so that it don't send the data to all client.. any guide..
|
|
|
|
|
Make the listbox multiselect, then send the data to all selected IPs ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
hi,
i'm now working in windows application vb.net, i have create one server and the problem is my server application only accept oly one client in one time.. when i start new client, the server accept the new client and the old client getting ignore by the server, is there any guide or step to make my server to receive multiple client in one time..
please help me...
|
|
|
|
|
Hard to say without seeing your code. I mean, it's obvious that it's written now in a way that connecting to more than one client is not possible, but why this is, I can't really say without seeing the code.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks for your attention.. it's my bad.. anyway i'm really appreciate that.. thanks again..
|
|
|
|
|
I was asking for more info so I could help, not telling you off. Why apologise and then start a new thread ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi
I am writing data from a table onto a Excel file. But the problem i am facing is i am not able to print the file in a single page.
I would like to do change the page orientation to "Landscape" Make the Margins (Left and Right ) to 0 and etc...
All these thing i am doing using Visual Studion 2003 and building a Windows Application.
Can any one help me in doing that.
|
|
|
|
|
The aim is to divide a 30 character long integer by e.g. 987.
|
|
|
|
|
Considering there is no such thing as an Int128 structure, unless you've made one yourself, this is going to be quite difficult. Perhap's you should be looking for a Big Integer library. Google results for ".net big integer[^]".
But, there's an example of a large integer library here[^] on CP.
|
|
|
|
|
thanks,
everything is working with the biginteger-class.
|
|
|
|
|
I want to add a Value at the specified position of a file
please help me .
for example I have a file
hello
how are you
I want to change it to
Hello Master
How are you
tanks .
|
|
|
|
|
The problem with that is that files are not line based, so you can't change a line without changing every following line throughout the entire file. Additionaly, files are not even text based, so you can't determine where a line or a character is in the file without reading the file and decoding it into text.
For example, depending on the encoding, the character following "o" in "hello", may (for the most common encodings) be at the file position 5, 8 or 12, so you have to read the file up to that position to know exactly where it is.
There are basically two ways of doing what you want:
1. Read the entire file into a string. Make the changes to the string. Rewrite the entire file with the string.
2. Read the file as a binary file, decoding each character to find out the file position where you want to insert the data. Read the rest of the file into a buffer (byte array). Reposition the file at the desired position. Endcode your text and write it to the file, followed by the contents of the buffer.
So, either way you will be reading the entire file, and rewriting it at least from the point where you want to change it until the end of the file.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Holy hell - why would you do 2, one is such a simple method on a text file. I know there are circumstaces where the binary read is valid but surely not on a text file!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: why would you do 2, one is such a simple method on a text file.
I mostly descibed it for completeness. You would only need to do something like that if the file is too large to load it into memory. Then you would actually move the contents of the file piece by piece, as much as would fit in a reasonably sized buffer. If you have enough disk space, it would of course be simpler to copy the data to a new file, though.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Why not use the String.Replace function?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Ashfield wrote: Why not use the String.Replace function?
Perhaps because it replaces text in a string, not in a file.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
True, but as you said in your ealier post, you have to read the file in some way before yuo can do anything to it. A text file is generally read into a string, hence the suggestion to use String.Replace
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Ok, it looked like you were suggesting an alternative...
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|