|
Here are some examples of the use of the form objects in the class.
Private Sub frmClientCommon1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
' close any sub forms that are open ...
If fbFormInstanceExists(ClientContacts) Then
If ClientContacts.bDataChangeStatus Then
MsgBox("Information Has Been Changed On The 'Client Emergency Contacts' Screen, But Has Not Been Saved. " & _
"Please save the information on this form prior to closing.", MsgBoxStyle.Exclamation, Me.Text)
ClientContacts.TopMost = True
e.Cancel = True
Exit Sub
Else
ClientContacts.Close()
ClientContacts.Dispose()
End If
End If
End Sub
Private Sub sHandleCommand(ByVal sender As Object, ByVal e As CommandClickEventArgs)
Select Case e.Command.Text
Case "Emergency Contacts"
If Not fbFormInstanceExists(ClientContacts) Then
ClientContacts = New frmClientContacts
End If
ClientContacts.tMode = tPassedMode
ClientContacts.lClientUniqueNumber = lClientNumber
ClientContacts.tClientName = ftFormatClientName(txtFirstName.Text, _
txtMiddleName.Text, txtLastName.Text, "2")
Me.Cursor = Cursors.WaitCursor
ClientContacts.Show()
ClientContacts.BringToFront()
Case "BLAH"
'Same stuff different form
Case "BLah2" 'etc
End Select Humble Programmer
|
|
|
|
|
Can anyone know how to make a relational query in vb.net?
thanks!
-robayas
|
|
|
|
|
You're going to have to explain a bit more than that. Which database are you using? Are you using LINQ? Relating a couple of DataTable objects? What?
|
|
|
|
|
We're using access database and we are not familiar with LINQ.
What we are planning is to use Access SQL. Like CREATE VIEW or like that.
Do you have any good idea or suggestion to solve our problem.
Thank you in advance. =)
-rob00
|
|
|
|
|
Use the query designer in Access then either cut and paste the SQL code generated in your VB.NET program, or save the query in Access and perform your SELECT, INSERT DELETE command upon the Access Query.
Research the System.Data.Oledb namespace, in particular the OleDbConnection, OleDbCommand, OleDbDataReader and the OleDbDataAdaptor classes.Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
And research the limitaions of SQL. Access does not support real stored procedures nor named parameters in parameterized queries.
|
|
|
|
|
When the following code is executed.
Dim strPrint As New StringBuilder
For Me.counter = 0 To 19
strPrint.Append(writeline(Me.counter) & vbCrLf)
Next Me.counter
'e.Graphics.DrawString(strPrint.ToString, printFont, System.Drawing.Brushes.Black, 10, 10)
If System.IO.File.Exists(SaveFileDialog1.FileName) Then
printfile = File.OpenText(SaveFileDialog1.FileName)
printfile = System.IO.File.OpenText(SaveFileDialog1.FileName)
Do Until printfile.Peek = -1
menuitem(printcounter) = printfile.ReadLine
e.Graphics.DrawString(printfile.ReadToEnd, printFont, _
System.Drawing.Brushes.Black, 10, 10)
printcounter = printcounter + 1
Loop
printfile.Close()
End If
It does not print the in the same way on how it looks in notepad. Any Ideas. You can get writeline code on the forum discussion title "writing to text file" Any ideas how to resolve issues.
issues as has been resolved by changing the font name..modified on Friday, March 12, 2010 9:16 PM
|
|
|
|
|
Hi,
1.
Daniel Engelkes wrote: It does not print the in the same way on how it looks in notepad
is not a symptom we can work on. What does it do, and how is that different from what you want/expect?
2.
A do-loop containing printfile.ReadToEnd will iterate only once. Your first line goes to "menuitem", everything else goes to "DrawString", there isn't a second iteration.
3.
Most often, the correct way to print a number of lines is by having a loop, where each iteration prints one line of text, at a different location; so you need to have coordinates (x,y) which change as you iterate your loop.
4.
Very likely, I haven't checked that part of your code: in order to write a number of strings to a text file, there is no need to concatenate the text and write all in one go. One can:
- either use a FileStream and the WriteLine method;
- or fill a string array and use File.WriteAllLines().
|
|
|
|
|
I would load the file into a List or similar collection (coll ) off String Array objects and then iterate through the collection, setting the x,y coordinates as appropriate:
'Read each line into an array and then put each array into a Generic.List(Of Array)
' Then do something like this in the PrintPage Event...
Dim l As Single = e.MarginBounds.Left ' Left margin
Dim y as Single = e.MarginBounds.Top ' Top margin
Dim h as Integer = 18 ' Row Height
Dim ws() As Single = {100, 50, 50, 50) ' Column widths
Dim sfs() As StringFormat = {StringFomat.Alignment.Far, StrngFormat.Alignment.Centre, _
StringFormat.Alignment.Near, StringFormat.Far}
Dim cuRow As Integer = 0
Dim linesReq As Integer = coll.Count - 1
Dim fnt as New Font("Courier New", 10, FontStype.Regular)
Dim pageline as Integer = 1
Dim linesPerPage as Integer = Math.Floor((e.MarginBounds.Bottom-y)/h)
For i as Integer = curRow to coll.Count -1
Do While (pageLine <= linesPerPage) And (curRow <= linesReq)
PrintText(e, coll.Item(curRow), l, y, ws, h, fnt, Brushes.Black, sfs())
y += h
pageLine += 1
curRow += 1
Loop
If (cuRow > linesReq)
Exit For
End If
Next i
...
Private Sub PrintText(ByVal e as PrintPageEventArgs, txtArray As Array, _
ByVal l as Single, ByVal y as Single, ByVal ws As Array, _
ByVal h As Single, ByVal fnt As Font, ByVal br as Brush, _
ByVal sfs As Array)
For i as Integer = 0 To txtArray.Count - 1
e.Graphics.DrawString(txtArray(i), l, y, ws(i), h, fnt, br, sfs(i))
l += ws(i)
Next
End Sub
<edited because="" i="" was="" drinking="" when="" wrote="" the="" reply="" -="" probably="" won't="" compile="" but="" you="" get="" idea="">I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
modified on Friday, March 12, 2010 3:28 AM
|
|
|
|
|
How you read or write the file has nothing to do with how it prints.
Are you using the same font?
How are you handling the PrintDocument events for new Pages etc.?
Do you have the margins set up the same as notepad does?
The questions are endless.
|
|
|
|
|
when I write to the file this is the format
Menu Items Qty Unit Cost Total Cost
---------- --- --------- ----------
cheeseburger 0 $5.00 $0.00
onion rings 0 $6.00 $0.00
chicken sdwch 0 $5.00 $0.00
milk shake 0 $2.00 $0.00
mexican rice 0 $5.00 $0.00
quasidella 0 $2.00 $0.00
shrimp cocktail 0 $5.00 $0.00
lasagne 0 $3.00 $0.00
spagehtti 0 $5.00 $0.00
cake 1 $2.00 $2.00
cookies 1 $6.00 $6.00
OrderTotal:$8.00
DrinkTotal:$0.00
---------------
SubTotal:$8.00
Tax Amount:$0.60
---------------
Grand Total:$8.60
but when I print the document from the program it end up like this
MenuItemsQty Unit Cost Total Cost
---------- --- --------- ----------
cheeseburger 0 $5.00 $0.00
onion rings 0 $6.00 $0.00
chicken sdwch 0 $5.00 $0.00
milk shake 0 $2.00 $0.00
mexican rice 0 $5.00 $0.00
quasidella 0 $2.00 $0.00
shrimp cocktail 0 $5.00 $0.00
lasagne 0 $3.00 $0.00
spagehtti 0 $5.00 $0.00
cake 1 $2.00 $2.00
cookies 1 $6.00 $6.00
it needs the same format. any ideas.
|
|
|
|
|
Ha, we finally got a symptom. Seems you want columnar results without using one DrawString for each cell. So you are relying on tabs (very difficult) or on spaces to get data formatted in columns. Unless you print individual cells, you need to choose a non-proportional or monospaced font, such as Courier New, and NOT a proportional font such as Arial. (If you choose Arial in Notepad, the data will look bad too!)
|
|
|
|
|
This is how I do my report printing. I have adapted one of my reports to sort of get what you are looking for. I used a set of arrays to input the data, whereas you would obviously get it from the app.
Private items() As String = {"Cheeseburger", "Onion Rings", "Chicken Sandwich", "Milk Shake"}
Private costs() As Integer = {5, 6, 5, 2}
Private quantities() As Integer = {1, 2, 2, 2}
Private intLinesPerPage As Integer = 25
Private intLinesPrinted As Integer
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
PrintHeadings(e)
PrintDetails(e)
End Sub
Private Sub PrintHeadings(ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim recMenu As New System.Drawing.Rectangle(40, 20, 100, 40)
Dim recQuantity As New System.Drawing.Rectangle(120, 20, 60, 40)
Dim recCost As New System.Drawing.Rectangle(180, 20, 60, 40)
Dim recTotal As New System.Drawing.Rectangle(260, 20, 80, 40)
Dim fntDefault As New System.Drawing.Font("Arial", 8, FontStyle.Underline)
Dim fmtCentre As New StringFormat
fmtCentre.Alignment = StringAlignment.Center
e.Graphics.DrawString("Menu Items", fntDefault, Brushes.Black, recMenu, fmtCentre)
e.Graphics.DrawString("Quantity", fntDefault, Brushes.Black, recQuantity, fmtCentre)
e.Graphics.DrawString("Cost Price", fntDefault, Brushes.Black, recCost, fmtCentre)
e.Graphics.DrawString("Total", fntDefault, Brushes.Black, recTotal, fmtCentre)
End Sub
Private Sub PrintDetails(ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim strMenu As New StringBuilder("")
Dim strQuantity As New StringBuilder("")
Dim strCost As New StringBuilder("")
Dim strTotal As New StringBuilder("")
Dim recMenu As New System.Drawing.Rectangle(20, 80, 100, 600)
Dim recQuantity As New System.Drawing.Rectangle(120, 80, 60, 600)
Dim recCost As New System.Drawing.Rectangle(180, 80, 60, 600)
Dim recTotal As New System.Drawing.Rectangle(240, 80, 80, 600)
Dim intLastLine As Integer = intLinesPrinted + intLinesPerPage
If intLastLine >= items.Length - 1 Then
intLastLine = items.Length - 1
e.HasMorePages = False
Else
e.HasMorePages = True
End If
Dim i As Integer
For i = intLinesPrinted To intLastLine
Dim strMenuItem As String = items(i)
If Len(strMenuItem) > 30 Then
strMenuItem = Microsoft.VisualBasic.Left(strMenuItem, 27) & "..."
End If
strMenu.Append(strMenuItem & ControlChars.NewLine)
strQuantity.Append(quantities(i) & ControlChars.NewLine)
strCost.Append(Format(costs(i), "0.00") & ControlChars.NewLine)
strTotal.Append(Format(quantities(i) * costs(i), "0.00") & ControlChars.NewLine)
Next
intLinesPrinted = i
Dim fntDefault As New System.Drawing.Font("Arial", 7)
Dim fmtCentre As New StringFormat
fmtCentre.Alignment = StringAlignment.Center
Dim fmtLeft As New StringFormat
fmtLeft.Alignment = StringAlignment.Near
Dim fmtRight As New StringFormat
fmtRight.Alignment = StringAlignment.Far
e.Graphics.DrawString(strMenu.ToString, fntDefault, Brushes.Black, recMenu, fmtRight)
e.Graphics.DrawString(strQuantity.ToString, fntDefault, Brushes.Black, recQuantity, fmtCentre)
e.Graphics.DrawString(strCost.ToString, fntDefault, Brushes.Black, recCost, fmtRight)
e.Graphics.DrawString(strTotal.ToString, fntDefault, Brushes.Black, recTotal, fmtRight)
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PrintDocument1.Print()
End If
End Sub
You would need to play around with this a bit, but should get where you want to go with it. Hope this helps.
|
|
|
|
|
Aha, filling columns each with a string inside a rectangle. Interesting.
|
|
|
|
|
I am trying to figure out what the code is scrolling down one cell without actually having it name the cell. Below is the code right now but I dont want it to say a666, i just want it to go down 1 cell from what the end of the list is. Is there a way to do that.
Selection.End(xlDown).Select
ActiveWindow.SmallScroll Down:=12
Range("A666").Select
ActiveSheet.Paste
|
|
|
|
|
Going down one cell from the active cell should look something like that (haven't done this for a while):
ActiveCell.Offset(1, 0).activate "I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
when I execute the follow code
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
Try
With SaveFileDialog1
' See the code demonstrating the OpenFileDialog control
' for examples using most properties, which are the same
' for both controls, for the most part.
' Add the default extension, if the user neglects to add an extension.
' The default is True.
.AddExtension = True
' Check to verify that the output path actually exists. Prompt before
' creating a new file? Prompt before overwriting?
' The default is True.
.CheckPathExists = True
' The default is False.
.CreatePrompt = False
' The default is True.
.OverwritePrompt = True
' The default is True.
.ValidateNames = True
' The default is False.
.ShowHelp = True
' If the user doesn't supply an extension, and if the AddExtension property is
' True, use this extension. The default is "".
.DefaultExt = "txt"
' Prompt with the current file name if you've specified it.
' The default is "".
'.FileName = filename3
'
' lblfilename.Text = SaveFileDialog1.FileName
' The default is "".
.Filter = _
"Text files (*.txt)|*.txt|" & _
"All files|*.*"
.FilterIndex = 1
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
counter = 0
writeline(0) = " Menu Items" + vbTab + "Qty" + vbTab + _
"Unit Cost" + vbTab + "Total Cost"
writeline(1) = " ----------" + vbTab + "---" + vbTab + _
"---------" + vbTab + "----------"
Dim y As Integer = 0
For x As Integer = 2 To 12
'writeline(2).PadLeft(5)
writeline(x) = frmtodayscafe.filename(y) + vbTab + Format(frmtodayscafe.totalitemquantity(y)) + vbTab + _
FormatCurrency(frmtodayscafe.filename1(y)) + vbTab + vbTab + FormatCurrency(frmtodayscafe.cost(y))
y = y + 1
Next
'writeline(2) = filename(0) + vbTab + frmtodayscafe.totalitemquantity(0) + vbTab + _
'FormatCurrency(filename1(0)) + vbTab + vbTab + FormatCurrency(frmtodayscafe.cost(0))
'writeline(3) = filename(1) + vbTab + frmtodayscafe.totalitemquantity(1) + vbTab + _
'FormatCurrency(filename1(1)) + vbTab + vbTab + FormatCurrency(frmtodayscafe.cost(1))
' writeline(4) = filename(2) + vbTab + frmtodayscafe.totalitemquantity(2) + vbTab + _
' FormatCurrency(filename1(2)) + vbTab + vbTab + FormatCurrency(frmtodayscafe.cost(2))
' writeline(5) = filename(3) + vbTab + frmtodayscafe.totalitemquantity(3) + vbTab + _
'FormatCurrency(filename1(3)) + vbTab + vbTab + FormatCurrency(frmtodayscafe.cost(3))
' writeline(6) = filename(4) + vbTab + frmtodayscafe.totalitemquantity(4) + vbTab + _
'FormatCurrency(filename1(4)) + vbTab + vbTab + FormatCurrency(frmtodayscafe.cost(4))
' writeline(7) = filename(5) + vbTab + frmtodayscafe.totalitemquantity(5) + vbTab + _
'FormatCurrency(filename1(5)) + vbTab + vbTab + FormatCurrency(frmtodayscafe.cost(5))
' writeline(8) = filename(6) + vbTab + frmtodayscafe.totalitemquantity(6) + vbTab + _
'FormatCurrency(filename1(6)) + vbTab + vbTab + FormatCurrency(frmtodayscafe.cost(6))
'writeline(9) = filename(7) + vbTab + frmtodayscafe.totalitemquantity(7) + vbTab + _
'FormatCurrency(filename1(7)) + vbTab + vbTab + FormatCurrency(frmtodayscafe.cost(7))
' writeline(10) = filename(8) + vbTab + frmtodayscafe.totalitemquantity(8) + vbTab + _
' FormatCurrency(filename1(8)) + vbTab + vbTab + FormatCurrency(frmtodayscafe.cost(8))
' writeline(11) = filename(9) + vbTab + frmtodayscafe.totalitemquantity(9) + vbTab + _
'FormatCurrency(filename1(9)) + vbTab + vbTab + FormatCurrency(frmtodayscafe.cost(9))
' writeline(12) = filename(10) + vbTab + frmtodayscafe.totalitemquantity(10) + vbTab + _
'() 'ormatCurrency(filename1(10)) + vbTab + vbTab + FormatCurrency(frmtodayscafe.cost(10))
writeline(13) = vbNewLine + vbTab + vbTab + vbTab + vbTab + " OrderTotal:" + FormatCurrency(ordertotal)
writeline(14) = vbTab + vbTab + vbTab + vbTab + " DrinkTotal:" + FormatCurrency(frmtodayscafe.totaldrinktotal)
writeline(15) = vbTab + vbTab + vbTab + vbTab + " ---------------" + vbCrLf
writeline(16) = vbTab + vbTab + vbTab + vbTab + " SubTotal:" + FormatCurrency(subtotal)
writeline(17) = vbTab + vbTab + vbTab + vbTab + " Tax Amount:" + FormatCurrency(taxsamount)
writeline(18) = vbTab + vbTab + vbTab + vbTab + " ---------------" + vbCrLf
writeline(19) = vbTab + vbTab + vbTab + vbTab + "Grand Total:" + FormatCurrency(grandtotal)
inputfile = System.IO.File.CreateText(SaveFileDialog1.FileName)
inputfile.WriteLine()
inputfile.WriteLine()
For Me.counter = 0 To 19
'System.IO.File.AppendText(.FileName)
'inputfile.Write(filename(counter))
'inputfile.Write(vbTab)
'inputfile.Write(frmtodayscafe.totalitemquantity(counter))
'inputfile.Write(vbTab)
'inputfile.Write(FormatCurrency(filename1(y)))
'inputfile.Write(vbTab + vbTab)
'inputfile.WriteLine(FormatCurrency(frmtodayscafe.cost(y)))
inputfile.WriteLine(writeline(counter))
Next
inputfile.Close()
btnprint.Enabled = True
btncancel.Visible = False
btnclose.Visible = True
End If
End With
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text)
End Try
End Sub
I get the following results
Menu Items Qty Unit Cost Total Cost
---------- --- --------- ----------
cheeseburger 0 $5.00 $0.00
onion rings 0 $6.00 $0.00
chicken sdwch 1 $5.00 $5.00
milk shake 0 $2.00 $0.00
mexican rice 0 $5.00 $0.00
quasidella 0 $2.00 $0.00
shrimp cocktail 0 $5.00 $0.00
lasagne 0 $3.00 $0.00
spagehtti 0 $5.00 $0.00
cake 0 $2.00 $0.00
cookies 0 $6.00 $0.00
OrderTotal:$5.00
DrinkTotal:$0.00
---------------
SubTotal:$5.00
Tax Amount:$0.38
---------------
Grand Total:$5.38
I need to make the file into columnar format. I tried using padleft and padright functions do not work.
by changing the for loop code to the following resolved issues
Dim y As Integer = 0
For x As Integer = 2 To 12
'writeline(2).PadLeft(5)
Dim tempwriteline As String
Dim writebuilder As New StringBuilder
tempwriteline = frmtodayscafe.filename(y)
writebuilder.Append(tempwriteline.PadLeft(15, " "))
tempwriteline = String.Format(" {0,10} ", frmtodayscafe.totalitemquantity(y))
writebuilder.Append(tempwriteline)
tempwriteline = String.Format(" {0,10} ", FormatCurrency(frmtodayscafe.filename1(y)))
writebuilder.Append(tempwriteline)
tempwriteline = String.Format(" {0,10} ", FormatCurrency(frmtodayscafe.cost(y)))
writebuilder.Append(tempwriteline)
writeline(x) = writebuilder.ToString
y = y + 1
Next
modified on Thursday, March 11, 2010 8:33 PM
|
|
|
|
|
|
The pad function DO work, but you will get screwy results if you use tabs. If you need "ascii" tabular data, lined up perfectly, use ONLY spaces and padded fields to align your data. Do not use any tab characters.
|
|
|
|
|
hi
i have problem whn it coms to loop
mey gyz send some examples of loops
|
|
|
|
|
gcina wrote: hi
i have problem whn it coms to loop
mey gyz send some examples of loops
You also seem to have a problem, when it comes to proper writing."I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
What..the...hell
Firstly: you've said that you've got a problem with loops...EXPLAIN. What's the problem you have?
Secondly: You've already made people less likely to help you if you are talking 1337 txtspk, K?
Lastly, I have no idea what the first two words of that last line are meant to be. I might be offended, I might be honoured, I have no clue because it's incomprehensible.
|
|
|
|
|
Be kind man it was the His First Post , if you cannot understand then dont post answer , its not a must
Read the Rules for Answering . Dont give bad impression of CP to new ones
______________________________________________________________________________________________________
Apologies for the shouting but this is important.
When answering a question please:
Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
_______________________________________________________________________________________________________Best Regards,
SOFTDEV
If you have knowledge, let others light their candles at it
|
|
|
|
|
What's important is txtspeak is for 9 year olds. People who are serious about this can type complete words and sentances.
|
|
|
|
|
Yes Dave
Its not must to answer any post , if you cannot answer then dont post (whatever the reason is) , see daveauld and Luc Pattyn simply posted the answer without any ...... and i know one 10 years old Best Regards,
SOFTDEV
If you have knowledge, let others light their candles at it
|
|
|
|
|