|
Liqz wrote: Somebody correct me if I'm wrong but is 'exit sub' generally regarded as 'dirty' programming?
Yes, it's generally preferred that a method should have only one exit point, so that the code is easier to follow.
You should however consider if adding more exit points makes the code significantly simpler. Sometimes the robustness of the code stands in conflict with the elegance of the code, and it's robustness that makes the code work well.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Next time you have a question like "what is the difference between x and y" try searching google for something like "x vs y". Its usually quite effective.
try this
|
|
|
|
|
Hiii
The Return statement is used in Function to return the any value that is retrieve in function and return the control on calling function.
and then Exit Sub statement is used in the subroutine to exit from current routine.
exit sub return the control on last line in our routine(on End Sub statement)
May be this post is useful for you.
Thanx
Mitesh Khatri
|
|
|
|
|
When used within a function, the return statement allows a value to be specified; that value will be given to the calling program.
Within function 'foo', for example, one could replace:
foo = 5
Exit Sub
with
Return 5
The Return statement may also be used without an argument, in which case it will behave like 'Exit Sub'. Earlier versions of VB required "Exit Sub", while other languages use "Return". Generally, I prefer Return, though that may be a matter of style. Note that in prior versions of VB, Return was a valid statement, but it meant something very different from in vb.net.
As for whether performing a 'Return' in the middle of a function constitutes good structured programming, I would suggest that there are cases where it is appropriate and places where it is not. If a sub or function will sometimes do nothing, it's better to use an 'early abort' test and return statement than to enclose the entire routine in a giant 'if'. On the other hand, a Return statement in the middle of a routine that generally runs to the end can sometimes cause confusion.
The biggest thing to watch out for, historically, has been with routines that begin some action that needs to be cleaned up. An early-exit test which skips the routine before it does anything requiring cleanup poses no problem, but returns in the middle can pose a problem. If the routine has allocated any resources, they need to be deallocated before the routine exits. This has typically been handled by putting some cleanup code before every Return or Exit statement. Such an approach could frequently lead to bugs, if cleanup requirements changed but not all the cleanup code was adjusted.
In a modern language like vb.net, structures like Try/Finally blocks and Using statements can alleviate some of the cleanup issues associated with mid-function exits. On the other hand, they can also cause code to be executed in confusing sequence. If a 'Return' or 'Exit Sub' is performed within a Try/Finally block, the 'Finally' clause will be executed, but code following the block will not.
|
|
|
|
|
If I'm not mistaken, "Return" simply tells your function to return its result to whatever called it (for instance boolean true or false). Exit Sub ends the current subroutine.
|
|
|
|
|
Hello all, I found a problem with my database connection. It prompout 2 error message,the following are the 2 message prompout:
1. An unhandled exception of type 'System.ArgumentException' occurred in mysql.data.dll
2. An unhandled exception of type 'System.TypeInitializationException' occurred in Unknown Module. Additional information: The type initializer for "POS_.Module1" threw an exception.
Public ObjMyComm As New MySqlCommand
Public ObjMyRead As MySqlDataReader
Public MyConn As MySqlConnection = New MySqlConnection(Connect())
Public strSetKey As String
Public ADD_BINLOG As String = "ADD_BINLOG"
Public Conn As String
Public Conn_localServer As String
Public Conn_localDb As String
Public Conn_localDbUID As String
Public Conn_localDbPassword As String
Public Conn_localDbPort As String
Public Function Connect()
'Data load from App.Config file
Conn_localDb = ConfigurationSettings.AppSettings("MyLocalDb")
Conn_localServer = ConfigurationSettings.AppSettings("MyLocalServer")
Conn_localDbUID = ConfigurationSettings.AppSettings("MyLocalUID")
Conn_localDbPassword = ConfigurationSettings.AppSettings("MyLocalPass")
Conn_localDbPort = ConfigurationSettings.AppSettings("MyLocalPort")
Conn = "DATABASE=" & Conn_localDb & ";DSN=" & Conn_localDb & ";OPTION=3;PORT=" & Conn_localDbPort & ";SERVER=" & Conn_localServer & ";UID=" & Conn_localDbUID & ";"
MessageBox.Show(Conn)
Return Conn
End Function
Public Function LoadBlnStartupData(ByVal strSetKey As String)
Dim test As String
Try
MessageBox.Show("**** = " & strSetKey & " " & TerminalLocate & " " & TerminalID & " ")
MessageBox.Show(TerminalLocate)
'ObjMyComm = New MySqlCommand("SELECT * FROM pos_setting WHERE LocationCode=' " & TerminalLocate & " ' AND SettingKey='ADD_BINLOG' ", MyConn)
ObjMyComm = New MySqlCommand("SELECT * FROM pos_setting", MyConn)
MyConn.Open()
ObjMyRead = ObjMyComm.ExecuteReader
If ObjMyRead.Read Then
test = ObjMyRead.Item(0)
MessageBox.Show("This is " & test & "")
Else
MessageBox.Show("No value")
End If
MyConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MyConn.Close()
End Try
End Function
The 1st Error are pointing to > Public MyConn As MySqlConnection = New MySqlConnection(Connect())
Could anyone give me some solution about this matter?
Thank you for reading.
|
|
|
|
|
Hi,
Are you sure your connectionstring is correct ?
I use the following one without any issues (VS2005):
Private sConnString As String = String.Format("server={0};port=3306;user id={1};password={2};database={3};pooling=false", _
My.Settings.dbserver, My.Settings.dbuser, My.Settings.dbpassword, My.Settings.database)
Private conn As New MySqlConnection(sConnString)
conn.open()
|
|
|
|
|
Hello Noctris,
I doesn't found any problem with my connection string as I have create a udl file to check if I get the right connection but it shows me the connection string is correct. I'm using VS 2003 .NET. Is that problem cause by this version of Visual Studio? I heard ppl said that is alot of problem in this version of Visual Studio. Anyone have other suggestion for this solution?
Regards
Drex
|
|
|
|
|
Hmm.. couldn't tell you that.. i never used the Mysql.NET connector in VS2003.. always 2005
at the last part in your "catch ex to exception", can you change to MessageBox.Show(Ex.ToString) and this ?
The actual error will give a lot more information about the issue.
|
|
|
|
|
It def. seems like your conn string is badly formed. Try a simple app first.
Might have luck using this tutorial also:
www.vbmysql.com[^]
|
|
|
|
|
To add, there is a vb.net example that gets installed with the .net connector, it is in
C:\Program Files\MySQL\MySQL Connector Net 5.1.6\Samples\Table Editor\vb
You can use that as a guide.
|
|
|
|
|
hi all
im having a problem trying to create a scalable picture box in VB.net, does anyone no how to do this or has already created one?
regards
Iain
|
|
|
|
|
hi
this is a good example.
http://www.bobpowell.net/tipstricks.htm
regards
|
|
|
|
|
thanx but what i need is for the picture scale to the picture box size so if i made the picture box bigger or smaller the whole picture would still be visible
if that makes any sense?
regards
|
|
|
|
|
A picture box is often mistaken for a high end control. It's there for people who are incapable of writing some basic drawing code. I'd create my own control, have it draw the image in it's paint event, then it's trivial to have it draw the image to the bounds of the control, and not hard to make it draw as big as it can with the correct aspect ratio.
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 have build an application which needs to write log files in user specified folder during settings with in the application + it need to connect with Access and update the records. When my application runs on XP it works fine but when It runs on Vista it do not get the default credentials and used to have readonly rights on the machine.So write log fails and while updating access it does not allow me.
I can check the default rights using system.security.principle class but how can set the default credentials for application as the user who run's the application do have rights to read/write/delete on machine.
Any idea's
Best Regards
Rizwan Bashir
|
|
|
|
|
Does any one have an idea on how to create a word document with open xml format together with font styles that i can apply to the text??
|
|
|
|
|
Hi, Im doing a conversion to an old calculation program at work. It has 1000+ input variables, which I have grouped in 15 or so classes, which I declare arrays of to simulate a database. Then I have a function that reads or writes these to disc.
The passing of the array seems to change the array to a system.array[] instead of the original <whateverclass>[]
Declaration
Private Function ReadDataClassAllFieldsToDisk(ByRef CheckObject() As Object) As Boolean
Called with
ReadDataClassAllFieldsToDisk(Hissdata_Arr)
So, Question 1: Why does the CheckObject I get in the function throw an error when I finish with the function saying that the objects are not of the same type?
Question 2: Can i automatically add a new object of the same type as the otherones in the array? (know I have a select thingy to check the type and make a new instance and add to the array?)
Thanks for just reading this, I hope anyone can help?
/Jocke
|
|
|
|
|
Hi Jocke,
Supposing that you are using vb.net, and not knowing the rest of the code in the function, the error might not point to the objects in your array.
Generally speaking a function will work like so:
Private Function MyStringAlittleShorter(ByVal MyInputString As String, Byval Divider as integer) As String
Return MyInputString.Substring(1, MyInputString.Length / Divider)
End Function
...because I am returning the same type as I declared my function to be (even though one of the Byvals is of a different type).
Now your Byval is an array of type Object, which means that it can contain elements of different types. If you are also trying to return an array, and your function is declared boolean, you would get a type mismatch error. I.e. declare the function to be an array of type object, or perform the logic inside the function, and return a boolean.
Maybe that is the case ?
As for your second question: if the array is of type Object, than you should be able to add new elements of any type. You might get Index out of bounds errors ofcourse.
Hope it helps,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
hi...
i ve a parent node as question, i need a ans to tat question in a child node,by clicking on the button........
spriya
|
|
|
|
|
Shanmugapriya.G wrote: need a ans to tat question in a child node,by clicking on the button
You also need to learn to type. Post your code and someone will help - if they can understand your question.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
hi all,
i have developed an application in vb.net and mssql 2000 and create some reports using crystal reports. it is working perfectly on my pc but create some problem on my client's pc.
i used an ODBC Connection Say CrRptOdbc while creating Crystal reports.
normaly i have to create an odbc connection on the Client's pc when i install my application.
in this particular case my client has MS SQLExpress 2005. when i created a SETUP i attached the database file in it. But when i install the same on the client's pc other than Crystal Reports rest is working perfectly.
when i try to fetch a report it show me a dialog box which demand user id and password when i always used Window's Authitications. i tried to create ODBC connection but could not find the file which i attached.
kinly help me how can i configure my crystal reports in this case.
Thanks.
rmshah
Developer
|
|
|
|
|
Hi
You can use dataset For Crystal Report.it's easiast way to use the crystal report.
With the dataset connection string,User Id,Password is not needful.
Cheers
Anubhava Dimri
anubhava.prodata@gmail.com
919250168195
|
|
|
|
|
|
You have to design on your own.
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|