|
OK. Looks like this is a "tip of the iceberg" problem from converting VB6 to VB 2008 .net. I'll get started. Thanks!
|
|
|
|
|
Yeah, I pretty much recommend just scrapping an old VB6 project and rewriting from scratch.
You CAN use the upgrade wizard to convert a project, but no converter does a perfect job and rewrite is inevitable. You just gain the advantange of being able to rewrite modules of the code when possible instead of having to rewrite the entire solution all at once. But, in the end, you'll still be rewriting the whole thing.
|
|
|
|
|
This program IS a wizard-converted VB6. Re-writing modules of code might not help - I would have re-written the code to look just like it does, which doesn't work. Your original point is the key, to set the options to strict data conversions, and re-write the db I/O parts. Thanks again.
|
|
|
|
|
Hi.
I have a rather perplexing problem when printing a file.
My application reads a file in from a folder, lists it in a ListView control and then sends it to the printer.The problem I'm having is that when I send it to a printer the text is preceded by half a page of block characters before the actual text starts. As a sanity check, I went back and tried printing from a textbox on my form and it worked perfectly.
Does anyone have any ideas on how I can look at the bytes coming in from the file and going out to the printer or what may be wrong?
Here is my print code:
Private Sub PrtTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrtTest.Click
Try
Dim _fs As FileStream
_fs = New FileStream("C:\Components\Test-Page1.txt", FileMode.Open, FileAccess.Read)
_Printstream = New StreamReader(_fs)
Dim pd As New PrintDocument()
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
pd.PrinterSettings.PrinterName = _printername
PrintPreviewDialog2.Document = pd
PrintPreviewDialog2.ShowDialog()
If pd.PrinterSettings.IsValid Then
pd.Print()
Else
MessageBox.Show("Printer is invalid.")
End If
Catch ex As Exception
MessageBox.Show("An error occurred while printing", _
ex.ToString())
End Try
End Sub
Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim numChars As Integer
Dim numLines As Integer
Dim stringForPage As String
Dim strFormat As New StringFormat
Dim PrintFont As New Font("Arial", 10, FontStyle.Regular)
Dim PrintString As String = _Printstream.ReadToEnd
Dim rectDraw As New RectangleF( _
ev.MarginBounds.Left, ev.MarginBounds.Top, _
ev.MarginBounds.Width, ev.MarginBounds.Height)
Dim sizeMeasure As New SizeF(ev.MarginBounds.Width, _
ev.MarginBounds.Height - PrintFont.GetHeight(ev.Graphics))
'PrintString = _Printstream.ReadToEnd()
strFormat.Trimming = StringTrimming.Word
ev.Graphics.MeasureString(PrintString, PrintFont, _
sizeMeasure, strFormat, numChars, numLines)
stringForPage = PrintString.Substring(0, numChars)
ev.Graphics.DrawString(stringForPage, PrintFont, _
Brushes.Black, rectDraw, strFormat)
If numChars < PrintString.Length Then
PrintString = PrintString.Substring(numChars)
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
End Sub
|
|
|
|
|
The text you are reading in from the file will have non printable control charachters.
You will maybe want to read the file into a buffer and then strip out the non printables. Look up an ASCII table to see the the codes at the start of the table.
There are probably some methods in the encoding classes that can do this for you, but don't know off the top of my head.
|
|
|
|
|
Thanks for the reply Dave. I was thinking that the problem may be something like that. I assume (yes, that can be dangerous)that I could use the standard ASCII class regular expression [\x00-\x1F\x7F] to filter out the control characters(I believe ASCII and UTF-8 chars are the same in this range). I'm wondering whether I would need a buffered stream in place of the StreamReader that would wrap around the filestream or do I still need the StreamReader. Also, will I need to reformat the stream before sending it out to the printer? I'll have to consider how much overhead this will add to my app.
Let me know if you have any advice on this. Thanks again.
Randy
|
|
|
|
|
Hi there,
wonder if you can help...
I have a piece of VB code which uploads 2 large XMLs to SQL and then more code which allows the manipulation of the data to provide various bits of info which is then presented to Excel..
I was initially uploading each test XML file which were about 40K lines which made 16K Rows in each SQL table. I could then compare the two tables.
The implementation requires XMLs of around 660K lines which, after uploading, become 144763 and 146741 rows in each table in SQL.
My problem is that the statement I was using to compare these two tables, which worked with test data fails (no error is given)
here is the code:
<br />
SQLStr = "Select * into Temp_Delete_Oldest from " & First & " Select * into Temp_Delete_Newest from " & Second & " <br />
DELETE Temp_Delete_Oldest FROM Temp_Delete_Oldest INNER JOIN Temp_Delete_Newest ON Temp_Delete_Newest.Fullpath = Temp_Delete_Oldest.Fullpath"<br />
This works in SQL when it is entered as a New Query but fails when implemnted from the VB code.
So, does anybody know why this fails and what I can do to stop it failing, bearing in mind it works with smaller SQL tables....
Cheers
nhsal69
|
|
|
|
|
Why don't you catch the exception and read what it tells you... That may help?
|
|
|
|
|
The error generated is:
A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Which is not really of any help, as this is the standard error when anything goes wrong when working with SQL from VB....
|
|
|
|
|
Did you use Exception.ToString() which shows ALL the available information, or just Exception.Message which only gives one line of text?
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Check what the SQLStr evaluates to and try running that in SQL. This is building dynamically so if there was a type in the First or second variables then it will crash.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
the full error is:
"Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."
This only occurs when the input files are the "large" ones, they also use the same variables "first and "second" as the small ones which complete successfully.
After a bit of further investigation it appears as it is only when the VB send the calculation query to SQL that the error occurs (it creates the tables, which is the previous step)...
I am attempting to increase the timeout period from default of 15 sec to more but this doesn't appear to resolve the problem...
Any thoughts???
***edit***
when stepping though the code and executing the "SQLCmd.ExecuteNonQuery()" it takes a count of approx 30 before the timeout error occurs, no matter what the "Connection Timeout=***;" in the connection string is set to...
|
|
|
|
|
Just goes to show the importance of checking the error message fully, doesn't it? You need to set both the connection and query timeouts I suspect.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Problem resolved,
here is the code for the SQL connection:
<br />
Dim mycon As New SqlConnection(conString)<br />
<br />
Dim SQLConn As New SqlConnection() 'The SQL Connection<br />
Dim SQLCmd As New SqlCommand() 'The SQL Command<br />
<br />
SQLConn.ConnectionString = myconnection 'Set the Connection String<br />
SQLConn.Open() 'Open the connection<br />
<br />
SQLCmd.Connection = SQLConn 'Sets the Connection to use with the SQL Command<br />
SQLCmd.CommandText = SQLStr 'Sets the SQL String<br />
SQLCmd.CommandTimeout = 60<br />
<br />
<br />
SQLCmd.ExecuteNonQuery() 'Executes SQL Commands Non-Querys only<br />
<br />
SQLConn.Close() 'Close the connection <br />
mycon.Close()<br />
Console.WriteLine("Connection Closed")<br />
The Bolded lin ei the new one which resolves my issue..
Thanks
|
|
|
|
|
Good
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
A couple of possibilities worth checking.
In Object Explorer right click on the SQL Server 2005 instance select Properties.
On the Connections tab check the value of Remote_query timeout.
On the Advanced tab check the value of Remote Login Timeout.
Either of these would take precedence over your connection string settings.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
Hi,
I have a simple console application using an if statement
if the user types "y" i would like form1 vb.net to be shown.
I tried my.forms.form1.show however this didn't work.
I added a console app to the main application by going on file / add / new project - to get the console application
as when i tried to add an existing item it didn't have a console application?
the console app works perfectly i just need to get on to the forms made in vb.net!
Many thanks
|
|
|
|
|
I don't think this is the way it should work. A console application is a simple text in text out app, that does not have any interaction with windows (aka forms). Simlarly a forms application does not (in general) interact with the console. If you are trying to offer an optional form according to user selection then your forms application should start with a form as dialog and then show form 1 or whatever else as appropriate.
|
|
|
|
|
You really can't do this. The .NET CLR doesn't support mixed-mode applications like this. This is because the startup environment for Console and Windows Forms app are very different and not compatible with each other.
|
|
|
|
|
First, let me say that as Richard wrote above, this is NOT the best way to do things. That said, if you actually do have a good reason for this, it can be done.
The trick is that a console app doesn't set up a message loop, which is what GUI apps need to function... It's easy, but you have to do it yourself.
[STAThread()]
static void Main(string[] args)
{
Console.WriteLine("Hit a key: ");
Console.ReadKey();
System.Windows.Forms.Form frm = new System.Windows.Forms.Form() { Text = "Test" };
System.Windows.Forms.Application.Run(frm);
}
Note that the form pops up behind the console, and that the console will remain open (Closing the console will end the program).
The same code works in WPF, except you create a new System.Windows.Application and call the run method on that instance.
(Tested in VS2008, CLR 3.5)
|
|
|
|
|
It can be done, but probably not a recommended practice.
See the following example;
1) Create a new console application project
2) Add a reference to System.Windows.Forms
3) Add a new Windows Form to the project
Copy the code below;
Module Module1
Sub Main()
Dim inputString As String = String.Empty
Do While inputString.Equals(String.Empty)
Console.Clear()
Console.Out.Write("Press the Y key to continue...")
inputString = Console.ReadLine
inputString = inputString.ToUpper
If inputString.StartsWith("Y") Then
Dim xForm As New Form1
xForm.ShowDialog()
End If
inputString = String.Empty
Loop
End Sub
End Module
This example will keep your console application in a loop, and everytime you press Y and enter the windows form will pop up.
modified on Wednesday, November 18, 2009 5:09 PM
|
|
|
|
|
I have a vb.net (WebForm) program that is for initial data entry and if the transaction needs to be corrected it doubles as Edit/Update. I have a series of DropDownLists that work perfect when in initial entry mode.
The problem comes when re-populating the transaction and appropiate dropdownlists are being populated in the code-behind.
The problem is that the dropdownlists need to be populated with all employees and then the specific employee that is to appear (normally selected, now force selected in code-behind) does not fire the SelectedIndexChanged Event a second time without a page level update.
Normally just changing the SelectedValue will cause the correct employee to appear. But, all of the elements of the dropdownlist have just been set, so the system does not recognize the new selection as one that is to be displayed.
With SelectedIndexChanged being a "Server Side" Event is there a way to force this event from the clientside in code-behind? Or maybe there is a way to reset the selectedindexchanged property to think is has not been changed yet?
If so, could you be kind enough to supply an example?
|
|
|
|
|
ASk this in the ASP.NET Forum.
|
|
|
|
|
Hi there..
I'm currently working on a project application in which I'm dealing with
multiple data reports. Use of multiple data reports are causing generation
of multiple temporary(*.tmp) files in the application directory.
So, I programmed a method to delete those temporary files from the app
directory.
The code for the method goes as follows:
Public Sub deleteTMPFiles()
Dim oFSO As New FileSystemObject
Dim oFolder As Folder, oSF As File
Set oFolder = oFSO.GetFolder(App.Path)
On Error GoTo KillErr
For Each oSF In oFolder.Files
If Right(oSF.Name, 4) = ".tmp" Then
SetAttr oSF.Path, vbNormal
Kill oSF.Path ' This line's generating error
End If
Next
Exit Sub
KillErr:
MsgBox Err.Description
End Sub
But the method is generating an error, when it comes to delete the file.
It gives a description as Permission Denied
I'm calling the method from MDIForm's unload event.
I just want to delete the temporary files from the application directory.
I've also tried the DeleteFile API function. It seemed as if the code ran
but reflected no changes in the system.
Any help will be appreciated..
|
|
|
|
|
Sounds like the file is in use still, and so will not be deletable.
By the way it looks like you are writing VB6 code. If you are posting in the future I suggest you include that information in your post, and probably also the header line.
It will get you some flac these days as VB6 is a legacy platform, no longer supported in any form by Microsoft. Though strangely I see MSDN subscribers can now download the VB6 IDE. Odd thing for microsoft to do.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|