Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Need help with formatting text  (Read 859 times)

0 Members and 1 Guest are viewing this topic.
Need help with formatting text
« on: February 27, 2008, 01:37:53 am »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
I have to write a program that shows the depreciation value of some object over time.  That was the easy part, now I'm having trouble formatting the text properly.  Here's what I mean..



I need those prices to be lined up with each other no matter what data is displayed.  Of course, I have no idea how to do this in Visual Basic.  Here's my code..

Code: [Select]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Deprec As Double '//during year
        Dim Deprec_End As Double '//total at the end of the year
        Dim Deprec_Start As Double '//start of the year
        Dim Year_Start As Integer '//the starting year
        Dim Year_Count As Integer '//how many years there are

        ListBox1.Items.Clear()
        Year_Start = CInt(TextBox2.Text)
        Year_Count = Year_Start + CInt(TextBox4.Text)
        Deprec_Start = CDbl(TextBox3.Text)
        ListBox1.Items.Add("Description: " & TextBox1.Text)
        ListBox1.Items.Add("Year of Purchase: " & TextBox2.Text)
        ListBox1.Items.Add("Cost: " & TextBox3.Text)
        ListBox1.Items.Add("Estimated Life: " & TextBox4.Text)
        ListBox1.Items.Add("Method of depreciation: Straight-Line")
        ListBox1.Items.Add("")
        ListBox1.Items.Add(" Year          Value at start          Deprec. during year          end of year")

        Do While (Year_Start <= Year_Count)
            Deprec = Deprec_Start * (1 / CDbl(TextBox4.Text))
            Deprec_End += Deprec
            ListBox1.Items.Add(Str(Year_Start) & "         " & FormatCurrency(Deprec_Start) & "               " & FormatCurrency(Deprec) & "                        " & FormatCurrency(Deprec_End))
            Deprec_Start = Deprec
            'Deprec_End += Deprec

            Year_Start += 1

        Loop
Logged



i love big weenies and i cannot lie
Re: Need help with formatting text
« Reply #1 on: February 28, 2008, 05:50:01 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 775
use a maxlen for char 32, which is space
Const spclen = 10
then add spaces and trim the line with a varying subtractor depending on the length of the text you output:
this is the text to add instead of your "spaces" strings: String(spclen - Len(TextAhead))
Ie.
L1 = FormatCurrency(Deprec_Start)
.Add Str(Year_Start) & String(spclen - Len(L1)) & L1

edit: btw change spclen to something that fits, and you should have figured out by now
that you need a font with constant charwidth ie. a console font such as FixedSys or Lucida Console

« Last Edit: February 28, 2008, 06:00:47 pm by Gonzo »
Logged

My Child Is Student of The Month at Neverland Ranch!
  • SSEdit
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.459 seconds with 43 queries.