|
I'd also avoid method 2, or atleast avoid returning a value by using MyFunction = value and always use Return value . It's more readable and also much easier if you decide to change the function name while coding.
Best Regards,
MicroVirus
|
|
|
|
|
I would use
Public Function ByteArrayToStream(ByRef byteIn() as byte) as System.IO.MemoryStream
Dim returnValue as System.IO.MemoryStream = Nothing
If byteIn IsNot Nothing then
returnValue = New System.IO.MemoryStream(byteIn, True)
end if
return returnValue
End Function
|
|
|
|
|
Method 2 is definitely not preferred. Return is standard for C anything and it's very nice that VB.Net now lets you return instead of setting the function name to the value or object.
With Try /Catch segments, I always just put the one line that could cause an exception. I would go with:
Public Function ByteArrayToStream(ByRef byteIn() as Byte) as System.IO.MemoryStram
If byteIn Is Nothing Then Return Nothing
Try
Return New System.IO.MemoryStream(byteIn, True)
Catch ex as Exception
Return Nothing
End Try
End Function
You want to avoid using extra memory. Option 3 uses extra memory by creating a new variable. Granted, it's really only a placeholder...a single address in memory pointing to the actual object, but it's still something. Personally, I think #1 is fine. I would assume that the IO.MemoryStream function first checks to see if there was anything actually passed in, so you could probably get rid of the If byteIn Is Nothing section.
|
|
|
|
|
I've developed a PPC app and I'm currently writing the documentation for it. I wanted to add screen shot to the documentation to make it easier for the user. I tried running the program from the IDE using the emulator and using the Alt-Print Screen keyboard command and it won't take a screen shot of the emulator window or anything while the emulator is the active window. Has anyone else tried this? Is there a way to do it while the app is running on the PPC? Any help would be greatly appreciated.
|
|
|
|
|
Have you tried to take away focus from that window so that it isn't active any more and then doing a screenshot of the complete screen? Then just crop your window.
What about software for capturing the screen? Did you try any? As far as I know, IrfanView (it's free) does that (but only for non-commercial use), else google for other free screenshot applications."I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
I was hoping it was just a setting or something else so that I could easily capture just the emulator window to save time. Oh well...I'll check out that program though, thank you.
|
|
|
|
|
Hi all.
I want to know that how to hide source code of my program so that it can not be seen by some softwares like- reflector or others.
Is it possible to write my own cryptographic algorithm to hide source code? If yes then suggest me what and how should I do.
Thanks.
Gagan
|
|
|
|
|
So, you are looking for an obfuscator.
Gagan.20 wrote: Is it possible to write my own cryptographic algorithm to hide source code?
Yes it is possible but it is not a trivial task. There are some open source projects like NCloak[^] where you can see the code.
And here[^] you can find an obfuscator list. Some of them are free others not.
And remember if your code is so important that you feel the need to obfuscate it, then don't try to create your own obfuscator, just use the existing ones.
|
|
|
|
|
Ok. Thanks for your help
|
|
|
|
|
In my app I need to come up with a way to differentiate between a database connection error and a database read error. Let me give you an example. Say I have a Class Category with a function GetCategory that returns a category object like this,
Private Function GetCategory(ByVal CategoryID) As Category
Using mycon As New MySqlConnection(My.Settings.Orders)
Dim myCat As New Category
mycon.Open()
'Code to return category her
Return myCat
End Using
End Function
Normally to call this you would have some code like this :
Try
Dim newCategory As Category = GetCategory(myCatID)
Catch ex As MySqlException
'error handling code here
End Try
but if you do it like this then you can't tell whether the exception was caused by a faulty db connection or whether the
exception was thrown in reading the table.
What I have done so far is to create 2 custom exceptions (DBRead and DBOpen Exceptions) and then trap the mysqlexception twice in each routine like this
Private Function GetCategory(ByVal CategoryID) As Category
Dim mycon As New MySqlConnection(My.Settings.Orders)
Try
Dim myCat As New Category
mycon.Open()
Try
'code to get category from db
Catch ex As MySqlException
Throw New DBReadException(ex.Message, ex)
End Try
Return myCat
Catch ex As MySqlException
Throw New DBOpenException(ex.Message, ex)
Finally
If mycon.State = ConnectionState.Open Then
mycon.Close()
End If
End Try
End Function
but this solution seems really klunky and very inelegant, as I would have to trap errors twice in each function as a pose to only when I call the function as in the first example. If someone has a better approach I would really appreciate knowing how you do it.
|
|
|
|
|
I don't know the MySqlException class, but by analogy to SqlException and OracleException, I would guess that there is some sort of error code that you can look at to determine the exact nature of the underlying error. C.f. SqlException.Errors or OracleException.Code. By looking at this you should be able to tell whether it is a read error or not.
As for creating your own exception type, use the same approach: you have one exception, MyDbException, and add a property to that, e.g. MyDbException.ErrorCode where ErrorCode tells you what went wrong (Connect or Read). Then you only have one exception to deal with. There are other advantages to this, for example you are then hiding the dependency on MySql so if you ever do switch to a different database you won't have so much code to rework.
|
|
|
|
|
In the MySqlException Class you have a Number Property that returns an int containting the MySql Error Code (The ErrorCode Property Returns the HResult) but that could be all of nearly 4000 codes, depending on the specific error (i.e 1049 - Unknown Database Error, 1045 - Access Denied Error) and to check for these seems overboard really.
I like your idea of adding a property to my custom exceptions so that in the calling function I only need to trap one error instead of 2, although I can't see it helping me when I trap the original error unless I can get the MySql connector to actually throw my custom exception (impossible ?). I don't really know to be honest, but many thanks for your input.
|
|
|
|
|
Hi All,
Last month I posted this question, but I think I didnt get response for that. Anyways, I would like to ask again:
I am one vb.net windows application installed on my client's PC. Now my client has asked some changes in the code and re-send that application, so that he can uninstall the previous version and install the updated version.
From my end, I have done the requested modification and created a Setup & Deployment project in VS2005.
Now I dont want him to uninstall the previous version of that application installed on his PC. I want to update his installed application with the updated one ( which I made on my PC) without un-installing his last version.
Can someone Pls let me know how to create this? Any patch building is required or not? I am new to this, though i can send him the updated exe so that he can uninstall the previous version and install the new version, but i dont want him to do...I want him to directly update his present verion of the application already installed.
Anyhelp would be appreciated.
Regard,
R.S.
|
|
|
|
|
As far as I know, the Setup and Deployment project doesn't create patches. You can it it to upgrade a previous verison of the package, so long as you have the ProductCode that it used, then the current one will uninstall the old version and install the new one.
I don't use the Setup and Deployment project, so I'm surely no authority on it. I use real setup and deployment tools, such as Wise Package Studio, InnoSetup, and InstallShield.
|
|
|
|
|
Hello to All,
Where are temporary internet files stored in Firefox ? (like IE stores them in temporary internet files).
Thanks
If you can think then I Can.
|
|
|
|
|
To go to the disk cache section , type in:
about:cache?device=disk
in the address bar of FF.
Also have a look at this[^] addon.
|
|
|
|
|
where i can type this .
If you can think then I Can.
|
|
|
|
|
He already told you:
in the address bar of FF.
|
|
|
|
|
How the hell did this question end up in the Visual Basic forum?
I fail to see the link between FF and VB.......am i missing some info here?
|
|
|
|
|
daveauld wrote: am i missing some info here?
Yep, I believe you are; and so am I.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
I m with ur favor.
If you can think then I Can.
|
|
|
|
|
Hi CP,
I developed an appl. in that i am having controls like textbox, combobox, list box,button ,etc and some other controls from PowerPacks.
I implemented successfully Cut/ Copy / Paste of these controls within the application .
Now i have to implement the things in Clipboard . How can i serialize the class which is maintaining the list of controls.
Public Class Temp
Dim lTempControls As List(Of Object) = Nothing
End Temp
So how can i serialize to clipboard and get all the things when i exit & open the application ?
Regards,
For1206
|
|
|
|
|
The Clipboard is common across the system, you interact with the clipboard through the MyComputer.Clipboard object.
|
|
|
|
|
You beat me to it!
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
Yeh, but notice we both got voted 1.
Now was that because the suggestions weren't an acceptable answer for the OP, or did someone else think we were taking the pi$$.
Guess we will never know!
Do you want a 5 exchange?
|
|
|
|