Formatting a list to be more presentable


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 10 of 10

Thread: Formatting a list to be more presentable

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    Formatting a list to be more presentable

    [Originally posted by Adrian]

    My curreent list output looks similar to this
    10˙ ˙  20
    20˙ ˙  40
    30˙ ˙  60
    40˙ ˙  80

    I would like it to look like this

    **********************
    *˙ Value˙ * Double it*
    **********************
    *˙  10˙ ˙ *˙ ˙  20˙  *
    *˙  20˙ ˙ *˙ ˙  40˙  *
    *˙  30˙ ˙ *˙ ˙  60˙  *
    *˙  40˙ ˙ *˙ ˙  80˙  *
    **********************

    can anyone help me please

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Formatting a list to be more presentable

    [Originally posted by Greg DeBacker]

    What control are you using? Are you outputting to a printer, TextBox, ListBox, ???

    Grex

  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Formatting a list to be more presentable

    [Originally posted by Adrian]

    I am outputting to a list box,
    from a commnd button called table

  4. #4
    Join Date
    Aug 2004
    Posts
    43,023

    Program lists Centigrade and farenheit

    [Originally posted by Adrian]

    Basically the program is this :-
    3 labelled text boxes called
    txtstart
    txtfinal
    txtstep
    1 Comand button called cmdtable
    1 list box called lsttable

    The start and end temp in centigrade is input with the step.

    The output prints to the listbox

    the data I have input runs but the fotmat is crap.

    try it yourselves, any replies would be gratefully received

    adeandsare@aol.com

    Private Sub cmdtable_Click()
    Dim listitem As String
    Dim centstart As Integer
    Dim centfinal As Integer
    Dim centstep As Integer
    Dim fahtemp As Integer
    centstart = Val(txtstart.Text)
    centfinal = Val(txtfinal.Text)
    centstep = Val(txtstep.Text)
    centemp = centstart
    temploop:
    fahtemp = (centemp * 9) / 5 + 32
    listitem = Str(centemp) & "˙ **˙ ˙ " & Str(fahtemp) & "*"
    lstTable.AddItem listitem
    centemp = centemp + centstep
    If centemp <= centfinal Then
    ˙ ˙ GoTo temploop
    End If
    End Sub

  5. #5
    Join Date
    Aug 2004
    Posts
    43,023

    Program lists Centigrade and farenheit

    [Originally posted by Adrian]

    Basically the program is this :-
    3 labelled text boxes called
    txtstart
    txtfinal
    txtstep
    1 Comand button called cmdtable
    1 list box called lsttable

    The start and end temp in centigrade is input with the step.

    The output prints to the listbox

    the data I have input runs but the fotmat is crap.

    try it yourselves, any replies would be gratefully received

    adeandsare@aol.com

    Private Sub cmdtable_Click()
    Dim listitem As String
    Dim centstart As Integer
    Dim centfinal As Integer
    Dim centstep As Integer
    Dim fahtemp As Integer
    centstart = Val(txtstart.Text)
    centfinal = Val(txtfinal.Text)
    centstep = Val(txtstep.Text)
    centemp = centstart
    temploop:
    fahtemp = (centemp * 9) / 5 + 32
    listitem = Str(centemp) & "˙ **˙ ˙ " & Str(fahtemp) & "*"
    lstTable.AddItem listitem
    centemp = centemp + centstep
    If centemp <= centfinal Then
    ˙ ˙ GoTo temploop
    End If
    End Sub

  6. #6
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Formatting a list to be more presentable

    [Originally posted by qixinghua]

    Hi,there
    ˙ i believe that the following codes will help you work it out.

    ˙ qixinghua

    '////////////////////////////
    Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long

    Private Const WS_CHILD = &H40000000

    Private Const WS_BORDER = &H800000

    Private Const WS_MINIMIZE = &H20000000
    Private Const LBS_SORT = &H2&

    Private Const WS_MINIMIZEBOX = &H20000

    Private Const WS_VSCROLL = &H200000

    Private Const WS_HSCROLL = &H100000

    Private Const WS_VISIBLE = &H10000000

    Private Const LBS_MULTICOLUMN = &H200&

    Private Const LBS_MULTIPLESEL = &H8&

    Private Const LBS_NOTIFY = &H1&

    Private Const LBS_STANDARD = (LBS_NOTIFY Or LBS_SORT Or WS_VSCROLL Or WS_BORDER)

    Private Const LB_SETHORIZONTALEXTENT = &H194
    Private Const LBS_WANTKEYBOARDINPUT = &H400&
    Private Const LBS_HASSTRINGS = &H40&
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const LBS_USETABSTOPS = &H80&
    Private Const LB_ADDSTRING = &H180
    Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
    Private Const LB_GETCOUNT = &H18B
    Private Const IDC_List = &H1003
    Private Const LB_GETTEXT = &H189
    Private Const LB_SETITEMHEIGHT = &H1A0
    Private Const LB_SETTABSTOPS = &H192

    Private Const LB_SETCOLUMNWIDTH = &H195
    Dim hList As Long

    Private Sub Form_Activate()
    hList = CreateWindowEx(&H200, "listbox", vbNullString, LBS_HASSTRINGS Or LBS_USETABSTOPS Or WS_VISIBLE Or WS_CHILD Or LBS_NOTIFY Or WS_VSCROLL Or WS_HSCROLL, 0, 0, 800, 300, hwnd, IDC_List, App.hInstance, 0)
    Dim ListTab(2) As Long
    ListTab(0) = 15
    ListTab(1) = 15
    ListTab(2) = 32
    SendMessage hList, LB_SETITEMHEIGHT, 0, ByVal 140

    SendMessage hList, LB_SETHORIZONTALEXTENT, 8192, 0
    SendMessage hList, LB_SETTABSTOPS, 3, ListTab(0)

    SendMessage hList, LB_SETCOLUMNWIDTH, ByVal 3, ByVal 800


    Erase ListTab
    For i% = 0 To 150
    strTmp$ = "192.168.66.5" & vbTab & "192.168.66.51" & vbTab & "我们ghjgjgjgjgj" & Chr(13) & Chr(10)
    SendMessage hList, LB_ADDSTRING, 0, ByVal strTmp$

    Next
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    DestroyWindow hList
    End Sub

  7. #7
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Formatting a list to be more presentable

    [Originally posted by Adrian]

    What the fox that ?????

    lost me on that one, try something simpler

  8. #8
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Re:Formatting a list to be more presentable

    [Originally posted by allen]

    Check out this link:
    http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=354
    It sets tab stops in a list box, what the other post is trying to do, but this link may be˙ cleaner and easier to understand.

  9. #9
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Program lists Centigrade and farenheit

    [Originally posted by allen]

    Try something like:

    Option Explicit

    Private Sub cmdtable_Click()
    Dim listitem As String
    Dim centstart As Integer
    Dim centfinal As Integer
    Dim centstep As Integer
    Dim fahtemp As Integer
    Dim centemp As Integer
    centstart = Val(txtstart.Text)
    centfinal = Val(txtfinal.Text)
    centstep = Val(txtstep.Text)
    centemp = centstart
    lstTable.Font = "Courier New"
    listitem = " * " & vbTab & "Cels" & vbTab & " * " & vbTab & "Fahr" & vbTab & "*"
    lstTable.AddItem listitem
    For centemp = centstart To centfinal Step centstep
    ˙ fahtemp = (centemp * 9) / 5 + 32
    ˙ listitem = " * " & vbTab & Rformat(centemp, "###0") & vbTab & " *" & vbTab & Rformat(fahtemp, "###0") & vbTab & "*"
    ˙ lstTable.AddItem listitem
    Next
    End Sub

    Public Function Rformat(Value, FormatString As String, Optional StringLen As Integer = 0) As String
    Dim result As String
    If StringLen > 0 Then result = Space(StringLen) Else result = Space(Len(FormatString))
    RSet result = Format(Value, FormatString)
    Rformat = result
    End Function


  10. #10
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Program lists Centigrade and farenheit

    [Originally posted by Adrian]

    Thanks Allen, I will give this a try tonight here
    in South Wales in the UK.

    Keep an eye on this site as I may well be be back.

    Thanks again.˙ Ade

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center