Logo
English Russian German French Spanish Italian
contact usprivacy
   Support Forums
chart
• Adjust flexgrid cell
• Animation
• Centering form text
• Coffee machine
• Creating fileshares
• Creating shortcuts
• Custom buttons
• Directory browser
• Disable mouse events
• File search by ext
• File transfer
• File watcher
• Formatting flexgrid
• Get Content Type
• Get HTML source
• Get modem port
• HTTP proxy
• ipconfig
• Large file split/merge
• MAPI
• MCI Sound Player
• Menu with images
• MP3 normalizer
• Net Send
• Netstat 2000
• No duplicate entries
• Outlook Address Book
• Set font color
• Shapes
• SOAP test
• Text-to-image
• Text file viewer
• Text find/replace
• UPS component
• View NT groups
• Word template
• Writing DNS control
    • Using DNS control
• Writing SMTP control
    • Sending email
    • Mailing list
• Writing WhoIs control
    • Using WhoIs control
• View HTML source
VB projects - Formatting numeric FlexGrid cells

Description: Format numbers in FlexGrid cells in American or Europian standards
Minimum requirements: vb
Download: source code
Screenshot:
formatting flexgrid (3017 bytes)
Project: Standard EXE
Controls: grd (flexgrid), txtValue (textbox), cmbRow (combobox), cmbCol (combobox), cmbAlign (combobox), cmbFormat (combobox), cmdSubmit (button)
Code:
Private Sub cmdSubmit_Click()
    If txtValue <> "" Then
        grd.Row = cmbRow
        grd.Col = cmbCol
        grd.CellAlignment = cmbAlign.ItemData(cmbAlign.ListIndex)
        grd.Text = FormatIt(txtValue)
    End If
End Sub

Private Sub Form_Load()
    Dim i As Integer
    Dim ctrl As Control

    For i = 1 To grd.Rows - 1
        cmbRow.AddItem i
    Next
    For i = 1 To grd.Cols - 1
        cmbCol.AddItem i
    Next
    With cmbAlign
        .AddItem "Left"
        .ItemData(.NewIndex) = 1
        .AddItem "Center"
        .ItemData(.NewIndex) = 4
        .AddItem "Right"
        .ItemData(.NewIndex) = 7
    End With
    cmbFormat.AddItem "American number"
    cmbFormat.AddItem "Europian number"
   
    For Each ctrl In Me.Controls
        If TypeOf ctrl Is ComboBox Then ctrl.ListIndex = 0
    Next
End Sub
   
Private Sub grd_Click()
    cmbCol = grd.Col
    cmbRow = grd.Row
    txtValue = grd.Text
End Sub
   
Private Function FormatIt(ByVal s As String) As String
    Dim DecimalChar As String
    Dim ThousandChar As String
    Dim i As Integer: Dim temp As String
   
    Select Case cmbFormat.ListIndex
    Case 0
        DecimalChar = "."
        ThousandChar = ","
    Case 1
        DecimalChar = ","
        ThousandChar = "."
    End Select
    If InStr(s, DecimalChar) > 0 Then
        i = Len(Mid(s, InStr(s, DecimalChar) + 1))
        Select Case i
        Case 0: s = s & "00"
        Case 1: s = s & "0"
        Case Else: s = Left(s, Len(s) - (i - 2))
        End Select
    Else
        s = s & DecimalChar & "00"
    End If
    If InStr(s, ThousandChar) > 0 Then
        temp = Mid(s, InStr(s, ThousandChar) + 1)
        If Len(Left(temp, InStr(temp, DecimalChar) - 1)) < 3 Then _
            s = Left(s, InStr(s, ThousandChar) - 1) & Mid(s, InStr(s, ThousandChar) + 1)
    End If
    If InStr(s, ThousandChar) = 0 Then
        i = Len(Left(s, InStr(s, DecimalChar) - 1))
        If i > 3 Then s = Left(s, i - 3) & ThousandChar & Mid(s, i - 2)
    End If
    FormatIt = s
End Function

Copyright © 1996-2008 OstroSoft. All rights reserved. info@ostrosoft.com