|
cleako wrote: Does that take care of the flush and everything?
Disposing a StreamWriter, or any file stream for that matter, automatically calls Flush and Close.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
If I have, say 5 writers, to write to 5 files depending on a condition, if I use the keyword Using and I create all 5 is there a way to avoid that indenting?
Cleako
|
|
|
|
|
If you're writing to all 5 files for each record you write, no there isn't unless you turn off the automatic formatting in Tools/Options. But do that also turns off the formatting for every file in every project you open from then on.
If your picking which file you are going to write to for each record, then create a StreamWriter when you need to write to that particulare file. Don't open the file(s) unless you need to write to it. But, there is a performance penality for doing this, so you might want to test it before you nail it down as production code. But, if you sacrifice performance just to make the code "look pretty", I'll frown up you if you ever end up on my team...
Basically, no there isn't. It's not so bad. I've seen C++ and C# code indented 20-30 levels deep because of nested IF's and loops. It happens...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
You're saying there is a performance hit to open the file everytime you need to write to it or to open 5 and write if you need to when you need to until you are done and then closing them all?
Also, checking for nothing establishes if it is ok to Flush and Close?
One more, , are you saying I could simply call .Dispose and it would take care of the Flush/Close instead of me calling those 2 in addition to the .Dispose?
Cleako
|
|
|
|
|
cleako wrote: You're saying there is a performance hit to open the file everytime you need to write to it or to open 5 and write if you need to when you need to until you are done and then closing them all?
Yes, there is a performance penalty for opening and closing a file. Try it. Write a little app that opens a file, writes 10,000 lines of text to it, then closes it. Then rewrite that loop so it opens the file, writes a line to it, then closes it, 10,000 times. See which one runs faster.
cleako wrote: checking for nothing establishes if it is ok to Flush and Close?
You're checking to see if it is safe to call Flush and Close, and even Dispose, on that object. If that object is Nothing, then any call you make on it will result in a Null Reference Exception.
cleako wrote: are you saying I could simply call .Dispose and it would take care of the Flush/Close instead of me calling those 2 in addition to the .Dispose?
Yep.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Dear All,
I have a file which is archived with RAR and Password protected now I simply can't get it way. Is there any way to get its data as it's really required.
Develop2Program & Program2Develop
|
|
|
|
|
What does this have to do with VB.NET???
You have to have the password to open the RAR since the data is encoded with it. You can probably try Googling for some cracking tools, but don't get your hopes up.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I am running VB.NEt(2003). I have a solution with 2 projects - the True project and the Setup project. User documentation is in a Help directory which contains 29 htm, bmp, and ico files. A year ago, both projects were fine and Setup project successfully deployed to several computers. I've completed some maintenance to the True project, which compiles and tests OK in Debug mode.
When I change to Release mode, the Setup project will not compile. It seems to make no difference whether I click Build or Rebuild for either the Setup project or the Solution.
Sometimes I get this error message C:\Development\VBN\VAQSO\VAQSO_Setup\VAQSO_Setup.vdproj Could not find file 'C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\Deployment\.\MsiRedist\1033\MsiLoadr.Bin' 'Interface not registered' Note the \.\ in the middle. The file & path (without the period) exist.
Usually I get this error message C:\Development\VBN\VAQSO\VAQSO_Setup\VAQSO_Setup.vdproj Could not find file 'C:\Development\VBN\VAQSO\VAQSO\bin\Help\Clear.ico' 'Interface not registered' This file and path also exist. This file is in the Setup project in a directory under the Application Folder. I can make this error go away in three steps. 1-Delete the entry from the Setup project. 2-Rename the file on my hard drive. 3-Add the renamed file back into the Setup project. Usually this works on this file, but another file in the same folder will come up missing the next build.
I figure I've busted a setting someplace, but I have no idea which one. This is the only VB project I maintain so I'm on thin ice here. Any ideas why the compiler is behaving this way?
Thanks
--HamCoder
|
|
|
|
|
Hi,
Although not the exact same problem, I have experienced similar things. You could probably investigate and experiment until you're ready to chuck your PC out of the window , but I recommend trying any of the following slightly more radical solutions:
1. delete the installer project, and add a new one to the solution.
2. start a new empty solution, add the main project (add existing project), and create a new installer project
3. uninstall and reinstall .NET Studio, and then solution 2.
I have spend about a week trying to solve my own problem, before I solved it in 15 minutes with solution 2.
Good luck,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
A call to PInvoke function 'Project1!Project1.Module1::NGIMAPBR_AutoDetectAndDecode2DBarcode' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

|
|
|
|
|
Have you tried what it says?
---
single minded; short sighted; long gone;
|
|
|
|
|
Public Declare Function NGIMAPBR_AutoDetectAndDecode2DBarcode Lib "imgap32.dll" Alias "_NGIMAPBR_AutoDetectAndDecode2DBarcode@28" (ByVal hInputDIB As Long, ByVal rectSearchLocation As rect, ByVal lSearchOption As Long, ByRef lNoofBarcodes As Long, ByVal lphBarcodeInformation As Long, ByVal lphreserved1 As Long, ByVal lphreserved2 As Long) As Long
i used the above function it says thet the struct Rect must be used as the marshall attribute to be passed as argument
|
|
|
|
|
Apparently, you're trying to use a VB6 signature in VB.NET code. That won't work without some conversion.
For example, a Long in VB6 is a 32-bit signed integer, while in VB.NET the same Long keyword is a 64-bit signed integer. If you want to translate the code, you have to replace the VB6 Long 's with VB.NET Integer 's. This is the biggest reason why people get this error message when using code they don't understand.
Also, any structures must be passed as an actual structure, not a Long or Integer.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
How can i export datagridview to excel in vb.net 2005? Please give me a example.
Thanks
................
|
|
|
|
|
You don't export the DataGridView. You export the data that the grid is bound to, like a DataTable or a DataSet object. In either case, the process is the same. The easy way is to create a normal Text file with a filename of something.CSV (comma seperated values) and iterate through your data tables, row-by-row, writing each column value, converted to a string, to the file with a comma between the values.
The harder way is to instantiate an Excel object, create a new workbook, then a new worksheet in the workbook, go through your data tables the same way you do for a CSV file, and place each value in the tables into a cell in the worksheet, saving the workbook when your done.
There's tons of examples out on the net. All you have to do is Google for "VB.NET export datagrid to excel".
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I want to set a column in a datagrid to display a time and not a date i am using vb.net 2003
|
|
|
|
|
You can specify a format string for a datetime, or call ToShortTimeString() to get the time only
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
How i add com reference to smart device project in vb.net 2003?
|
|
|
|
|
Click Project at the top and go to project properties. There is a reference tab. you can add it there
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Hi
I can connect to the local COM port thru VB.Net
How can I connect to a COM port on a remote machine? What URL/URI do I give for the port address: is it "servername:port number" or something else?
What is the valid specification to access a remote port?
Obviously, I have not yet found any answers to the questions above. Can somebody help me in getting the answers?
Shreekar
|
|
|
|
|
You can't. There's no way you can just "connect" to a remote COM port like that. You have to have a remote application running on the target machine to use that machines COM port, then you establish a connection between your local app and the remote app over the network using any method you want, like .NET Remoting, WinSock, ...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I want to check if my string contains the character '"' how do I check that
I am using Instr() presently, but the line of code
InStr(sFile, """)
but this gives an error
Can you please help
|
|
|
|
|
Are you trying to see if the string contains a quote character? If so you need to double it up inside the string. Also are you using vb.net or vb6. If it's .net you should use the 'contains' method
sfile.Contains("""")
If it's not .net then just use
InStr(sFile,"""")
|
|
|
|
|
I am using vb6 not .net
I want to check for a double quote but only " once.
Will the expression you stated above check for "" or just " , which i want
|
|
|
|
|
It will check for a single double quote as in ". You need to double it up inside the string though to use it as a literal quote so you need """".
|
|
|
|