|
|
Dear all,
I need to write a sub procedure to show a specified window form, based on the criteria and options choose by user. But it seems the code is so long and also maybe expand later.
Private Sub CallSubForm(ByVal Criteria As String, ByVal UserOption As Integer)
IF Criteria = "A" Then
IF UserOption = 1 Then
FormMainA1.Show()
Elseif UserOption = 2 Then
FormMainA2.Show()
Else
FormMainA3.Show()
End if
Elseif Criteria = "B" Then
IF UserOption = 1 Then
FormMainB1.Show()
Elseif UserOption = 2 Then
FormMainB2.Show()
Else
FormMainB3.Show()
End if
Elseif Criteria = "C" Then
Elseif Criteria = "D" Then
:
:
:
End if
End Sub
Can I pass the name of specified form to a procedure and show it out ?
Like this:
Private Sub CallSubForm(ByVal FormName As String)
:
:
End Sub
Many Thanks !!!
Leo
|
|
|
|
|
Sure you can
Sub SetForSelect()<br />
Dim oFrm As New Form 'declare an empty object<br />
Select Case CriteraOption 'fill the object according to your rules<br />
Case 1<br />
If OtherChoice - 1 Then<br />
oFrm = New frmBaseDlg<br />
Else<br />
oFrm = New frmBaseDlg<br />
End If<br />
Case 2<br />
oFrm = New frmCheckStatus<br />
End Select<br />
<br />
If Not oFrm Is Nothing Then 'Test the object to see if it was filled<br />
oFrm.ShowDialog(Me)<br />
Else<br />
MessageBox.Show("Unsupported criteria")<br />
End If<br />
End Sub
|
|
|
|
|
I have the following code. I am returning a string. If I use return where I have in this way is there a chance I could have left some database connections open still?
Does it skip the connection "Finish with resources" section?
I believe this is the cause to alot of timeout exceptions. Any help much appreciated.
<br />
'Gets any previosuly create about us text <br />
Public Function GetAboutUs(ByVal ProductID As Int32) As String<br />
' Create Connection<br />
Dim HSConn As New SqlConnection(ConfigurationManager.ConnectionStrings("RemoteSqlServer").ConnectionString)<br />
' Create data reader<br />
Dim dr As SqlDataReader<br />
'Declare Command<br />
Dim HSComm As New SqlCommand()<br />
<br />
Try<br />
HSConn.Open()<br />
' Provide connection<br />
HSComm.Connection = HSConn<br />
' Provide command type and command<br />
HSComm.CommandType = CommandType.StoredProcedure<br />
HSComm.Parameters.AddWithValue("ProductID", ProductID)<br />
HSComm.CommandText = "SP_ProductAboutUsSelect"<br />
<br />
'Execute the command<br />
dr = HSComm.ExecuteReader<br />
<br />
While dr.Read()<br />
'If there is a Tagline return it. Otherwise return nothing<br />
If dr.IsDBNull(0) Then<br />
Return Nothing<br />
Else<br />
Return dr.GetString(0)<br />
End If<br />
End While<br />
<br />
'Return in case value is not found<br />
Return Nothing<br />
<br />
Catch ex As Exception<br />
' Failed to retrieve tagline so return false<br />
Emailer.ErrorEmail(ex, Page)<br />
Return Nothing<br />
End Try<br />
<br />
' Finish up with resources<br />
dr.Close()<br />
HSConn.Close()<br />
<br />
End Function
|
|
|
|
|
Hi,
this does not look OK; everytime you return, the remainder of the function is not executed,
in particular the Close statements at the end.
There are two solutions to this:
1. don't use return except as the last statement; instead store the result value in some
variable (say result), and proceed throughout the function, that ends on return result
2. use a try/catch/finally construct with the Close lines in the finally block; they will
get executed even when you exit the try or catch parts in whatever way (even with return).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
No. It gave me a headache just looking at it
You should rewrite it a bit.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
I am stuck on this handler. I have 16 buttons to increment. Button1.text is the btn_click. How do I make this handle all 16 buttons when they are clicked???
[code] Private Sub Btn_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If sender.text = "" Then
sender.text = "1"
ElseIf sender.text = "1" Then
sender.text = "2"
ElseIf sender.text = "2" Then
sender.text = "3"
ElseIf sender.text = "3" Then
sender.text = "4"
ElseIf sender.text = "4" Then
sender.text = ""
End If
End Sub[/code] Thank You Very Much!
|
|
|
|
|
Hi,
two remarks:
1.
you can specify an event list, i.e. multiple events, following the handles keyword;
doing so the same sub can serve many buttons.
2.
sender.txt will not compile as long as sender is of type object.
You need to cast sender to a Button, and then its Text property will be available.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Is there a pre defined snippet to attach for an event list in VB 2005? I don't know how to code a list.
Thanks
|
|
|
|
|
I have no details on eventlists; there is an alternative that may suit your needs better,
that's AddHandler, which attaches the handler at run-time rather than compile-time.
I hope MSDN is sufficiently clear on that (I'm not that familiar with VB).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thank you for your answers, I'll look at the MSDN site
Much appreciated
|
|
|
|
|
I am new to vb.net and having great difficulties writing out a PCL file. I am reading it fine.
The best article I have read anywhere was on this site
http://www.codeproject.com/vb/net/vb_file_handling.asp
but still not understanding streamreader,streamwriter,binaryreader,binarywriter,filestream. It would be great if i could see an example of code that reads PCL by vbCRLF or even by the page, and writes it back out to another file without PCL changing!
Thanks much!
|
|
|
|
|
So what does a PCL file look like?? Are you talking about the page description language commonly used for HP's laser printers??
|
|
|
|
|
You are correct HP Printer Control Language.
The file would be a mix of ASCII text and binary bits for fonts, graphics, control codes etc.
a string in (bold) (hex not bold) may look like:
2A743330 30521B2A 72343133 73383854 1B2A7231 411B2A62 324D1B2A 623657D5 *t300R.*r413s88T.*r1A.*b2M.*b6WÕ
00FFFFFB 001B2A62 3857D600 0001FFFF FB001B2A 623857D6 000201FF FEFB001B .ÿÿû..*b8WÖ...ÿÿû..*b8WÖ...ÿþû..
same string out ends up like:
2A743330 30521B2A 72343133 73383854 1B2A7231 411B2A62 324D1B2A 623657EF *t300R.*r413s88T.*r1A.*b2M.*b6Wï
BFBD00EF BFBDEFBF BDEFBFBD 001B2A62 3857EFBF BD000001 EFBFBDEF BFBDEFBF ¿½.���..*b8W�...��ï¿
So upto the byte before hex D5 in this case everyting is OK after that its downhill. Several different approaches with litte difference although using example below changing Default to ASCII and all the other options had some effect but not good.
Dim btFile As Byte()
btFile = System.Text.Encoding.Default.GetBytes(sText)
Where sText was the input string from reading the pcl.
|
|
|
|
|
PCL is a binary format, not a mix of binary and text. It just APPEARS as text in places.
You have to use the BinaryReader/BinaryWriter classes to read/write these files. Open a FileStream on the file itself, then use a BinaryReader to read the data from that stream, byte-by-byte. There is no CrLf that is a line terminator. None of the encodings will work on this file, that I know of anyway.
|
|
|
|
|
Thank you Dave,
So far i found must use both binaryreader and binarywriter (i know i know but i don't need to alter any of the binary bytes) i could not simply use streamreader to read a line in (there are vbcrlf in there works fine since the days of qbasic) and binarywriter to write out the string because string was already corrupted by streamreader. this is now a slowed down compared to vb6 due to byte by byte processing. I'll have to re-examine my test and post the little code later for better/faster reading writing.
|
|
|
|
|
I am trying to write an SQL statement in .Net to fill a listview. The SQL statement retreives information from two tables. The problem I am having is that one of the keys (subjob) can have a null value. Any records where the second key is null are not retrieved. I found a note on the internet indicating the following;
Programmers should take special care when joining tables on columns that can contain NULL values, since NULL will never match any other value (or even NULL itself), unless the join condition uses explicitly the IS NULL or IS NOT NULL predicates.
Can someone please show me where the ISNULL should go to fix this SQL statement.
SELECT Ordmstr.OrdNum, Ordmstr.JobNum, Ordmstr.SubJob, JobMstr.JobDesc
FROM Ordmstr INNER JOIN JobMstr ON (Ordmstr.JobNum = JobMstr.JobNum) AND (Ordmstr.SubJob = JobMstr.SubJob)
Thank you.
digicd1
|
|
|
|
|
Which table contains records where SubJob can be NULL?
If it is Ordmstr, the following should work:
SELECT Ordmstr.OrdNum, Ordmstr.JobNum, Ordmstr.SubJob, JobMstr.JobDesc
FROM JobMstr LEFT JOIN Ordmstr
ON (Ordmstr.JobNum = JobMstr.JobNum)
AND ((Ordmstr.SubJob = JobMstr.SubJob) OR Ordmstr.SubJob IS NULL)
Paul Marfleet
|
|
|
|
|
Both tables have nulls. Every Order has a record in the Job Master table. The key to the Job Master is Job/Sub Job. For whatever reason, when the application was originally developed, the programmer used null in the sub job if there was not a value. This is also carried onto the Order Master table.
Job Sub Desc
00100 Null ABC
00100 100 DEF
00200 Null GHI
00201 100 JKL
Again, when the tables are joined - the only records that are retrieved are thos where the subjob is not null.
digicd1
|
|
|
|
|
Use the ISNULL function as a wrapper around the each field when specifying the join between the 2 Subjob fields. Use the same default value in both cases. This will eliminate the NULL values and allow your original query to work.
Paul Marfleet
|
|
|
|
|
How can I code to get a calculated answer which is shown in a textbox to a listbox, and further answers added to that list box.
|
|
|
|
|
Your question doesn't provide any details, but you add a string, even if it's the result of a calculation, to a listbox by doing something like:
Dim result As Integer = x * y
ListBox1.Items.Add(result.ToString("N"))
|
|
|
|
|
I have the product of a quantity and price (both doubles) to give total
dim total as double
the total is then displayed in a textbox when a button is clicked.
How would I get this result (total) in a listbox by clicking a button, and other subsequent results into that listbox.
What is "N" in your above response
Thank you
|
|
|
|
|
It works thanks a million.
With the totals displayed in the listbox, how can I find the total of the
numbers displayed to with two decimal places
|
|
|
|
|
"A fatal error has occurred and debugging needs to be terminated...."
Thanks
|
|
|
|