Click here to Skip to main content
15,897,519 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: printer from file Pin
The Man from U.N.C.L.E.12-Mar-10 8:35
The Man from U.N.C.L.E.12-Mar-10 8:35 
GeneralRe: printer from file Pin
Daniel Engelkes12-Mar-10 14:54
Daniel Engelkes12-Mar-10 14:54 
GeneralRe: printer from file Pin
Luc Pattyn12-Mar-10 15:50
sitebuilderLuc Pattyn12-Mar-10 15:50 
GeneralRe: printer from file Pin
Wayne Gaylard12-Mar-10 17:00
professionalWayne Gaylard12-Mar-10 17:00 
GeneralRe: printer from file Pin
Luc Pattyn12-Mar-10 18:43
sitebuilderLuc Pattyn12-Mar-10 18:43 
QuestionCode Question Pin
derekzundl11-Mar-10 8:20
derekzundl11-Mar-10 8:20 
AnswerRe: Code Question Pin
Smithers-Jones11-Mar-10 9:33
Smithers-Jones11-Mar-10 9:33 
Questionwriting to text file [modified] ... resolved Pin
Daniel Engelkes11-Mar-10 7:39
Daniel Engelkes11-Mar-10 7:39 
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
            '//filename3 = .FileName
            '  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

AnswerRe: writing to text file Pin
David Mujica11-Mar-10 7:45
David Mujica11-Mar-10 7:45 
AnswerRe: writing to text file Pin
Dave Kreskowiak11-Mar-10 9:08
mveDave Kreskowiak11-Mar-10 9:08 
Questioncodin prblm Pin
gcina11-Mar-10 2:35
gcina11-Mar-10 2:35 
RantRe: codin prblm Pin
Smithers-Jones11-Mar-10 3:00
Smithers-Jones11-Mar-10 3:00 
AnswerRe: codin prblm Pin
JHizzle11-Mar-10 3:11
JHizzle11-Mar-10 3:11 
GeneralRe: codin prblm Pin
εїзεїзεїз11-Mar-10 4:50
εїзεїзεїз11-Mar-10 4:50 
GeneralRe: codin prblm Pin
Dave Kreskowiak11-Mar-10 5:02
mveDave Kreskowiak11-Mar-10 5:02 
GeneralRe: codin prblm Pin
εїзεїзεїз11-Mar-10 5:16
εїзεїзεїз11-Mar-10 5:16 
GeneralRe: codin prblm Pin
Smithers-Jones11-Mar-10 5:17
Smithers-Jones11-Mar-10 5:17 
GeneralRe: codin prblm Pin
εїзεїзεїз11-Mar-10 5:44
εїзεїзεїз11-Mar-10 5:44 
GeneralRe: codin prblm Pin
Smithers-Jones11-Mar-10 6:04
Smithers-Jones11-Mar-10 6:04 
GeneralRe: codin prblm Pin
εїзεїзεїз11-Mar-10 6:06
εїзεїзεїз11-Mar-10 6:06 
GeneralTag Line Pin
The Man from U.N.C.L.E.11-Mar-10 7:55
The Man from U.N.C.L.E.11-Mar-10 7:55 
GeneralRe: Tag Line Pin
εїзεїзεїз11-Mar-10 8:46
εїзεїзεїз11-Mar-10 8:46 
GeneralRe: Tag Line Pin
The Man from U.N.C.L.E.12-Mar-10 8:37
The Man from U.N.C.L.E.12-Mar-10 8:37 
GeneralRe: codin prblm Pin
William Winner12-Mar-10 5:49
William Winner12-Mar-10 5:49 
AnswerRe: codin prblm Pin
DaveAuld11-Mar-10 3:17
professionalDaveAuld11-Mar-10 3:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.