PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] how to show Currency symbol like ( $ or Euro ) next to the price in a text-VBForums
Results 1 to 20 of 20

Thread: [RESOLVED] how to show Currency symbol like ( $ or Euro ) next to the price in a text

  1. #1

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,110

    Resolved [RESOLVED] how to show Currency symbol like ( $ or Euro ) next to the price in a text

    i did a program of expenses now im trying to show each time i do the calc
    to show me the simbol of a price

    examlpe:
    250 $ the symbol $ nnext to the price
    tnx

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,921

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    If you try to stuff a numeric value (Single, Double, Currency, etc.) into the TextBox's Text property you are implicitly invoking a conversion from numeric to String. This isn't the best thing since such habits can lead to all sorts of errors when such implicit conversions combine to produce bad results.

    Normally then you'd want to do something like:
    Code:
    Dim Amount As Single
    
    Amount = 4.3
    Text1.Text = CStr(Amount)
    CStr() is generally superior to using the older Str$() function because CStr() is locale aware and will use the proper decimal point character for your session's regional settings.

    However much of the time you want more control over the formatting used, and adding a currency symbol can be done as part of this. To handle this we have the Format$() function:
    Code:
    Dim Amount As Single
    
    Amount = 4.3
    Text1.Text = Format$(Amount, "$0.00")
    However in some cases you need to deal with negative values, showing the sign either before or after the currency symbol or even using the accounting notation which uses parenthese around the value to indicate a negative amount. Then you can use:
    Code:
    Text1.Text = Format$(Amount, "$0.00;-$0.00")
    or:
    Code:
    Text1.Text = Format$(Amount, "$0.00;($0.00)")
    See Format Function

    And User-Defined Numeric Formats (Format Function)

    Which of course you can find right in your online Help MSDN CDs that come with legitimate copies of VB6.

  3. #3

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,110

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    i just need the dollar symbol to show in the TxtCost.text

  4. #4

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,110

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    the currency i mean
    i tried this didnt work
    Code:
    Private Sub Form_Load()
    Dim Amount As Single
     Amount = "0.00"
     TxtCost.Text = Format$(Amount, "$0.00")
    Last edited by salsa31; Jun 1st, 2013 at 05:23 AM.

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,921

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    Why are you setting your Single variable to a String value there? I just warned you about implicit conversions and their many pitfalls.

    That (repeated) warning aside, I can't see any reason why it wouldn't work. I just tried it and it does exactly as expected.

  6. #6

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,110

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    so instead of single to put currency?

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,921

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    Values of type Currency are another topic altogether.

    No, in most simple cases Single would be fine. You are just doing something wrong.

  8. #8

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,110

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    this is the save code
    tell me whats wrong
    Code:
    Option Explicit
    
    Private Sub Form_Load()
        If NewRec Then
            Me.Caption = "new"
            BttnSave.Caption = "save"
        Else
            BttnSave.Caption = "update"
            With FrmExpenses.LsVw.SelectedItem
                Me.Caption = "update for"
                PickDate.Value = Format(.Text, "dd/mm/yyyy")
                Txt(1).Text = .SubItems(1)
                Txt(2).Text = .SubItems(2)
                Txt(3).Text = .SubItems(3)
            End With
            ChkRepeat.Enabled = False
        End If
    End Sub
    
    Private Sub BttnCancel_Click()
        Unload Me
    End Sub
    
    Private Sub BttnSave_Click()
     
        If Len(Trim$(Txt(1).Text)) = 0 Then
            MsgBox "value empty", vbInformation, ""
            Txt(1).SetFocus
            Exit Sub
        ElseIf Txt(2).Text = 0 Then
            MsgBox "value cant be 0 ", vbInformation, ""
            Txt(2).SetFocus
            Exit Sub
        ElseIf Txt(3).Text = 0 Then
            MsgBox "value empty ", vbInformation, ""
            Txt(3).SetFocus
            Exit Sub
        End If
        
        If NewRec Then
            Dim NewID As Long
            NewID = NextID("ExpID", "Expenses")
            CN.Execute "INSERT INTO Expenses " & _
                "(ExpID, ExpDate, ExpType, ExpQuantity, ExpCost) VALUES (" & _
                NewID & ", #" & _
                MyDate(PickDate.Value) & "#, '" & _
                RplS(Txt(1).Text) & "', " & _
                Replace$(Txt(2).Text, ",", ".") & ", " & _
                Replace$(Txt(3).Text, ",", ".") & ")"
            
            Set Itm = FrmExpenses.LsVw.ListItems.Add(, , Format(PickDate.Value, "dd/mm/yyyy"), , "dolar")
            Itm.Tag = NewID
            Itm.SubItems(1) = Txt(1).Text
            Itm.SubItems(2) = Replace$(Txt(2).Text, ",", ".")
            Itm.SubItems(3) = Replace$(Txt(3).Text, ",", ".")
            
            If ChkRepeat.Value Then
                PickDate.Value = Now
                Txt(1).Text = ""
                Txt(2).Text = 1
                Txt(3).Text = 0
                ChkRepeat.Value = 0
                PickDate.SetFocus
                Exit Sub
            End If
        Else
            With FrmExpenses.LsVw.SelectedItem
                CN.Execute ("UPDATE Expenses SET " & _
                    "ExpDate= #" & MyDate(PickDate.Value) & "#, " & _
                    "ExpType= '" & RplS(Txt(1).Text) & "', " & _
                    "ExpQuantity= " & Replace$(Txt(2).Text, ",", ".") & ", " & _
                    "ExpCost= " & Replace$(Txt(3).Text, ",", ".") & _
                    " WHERE ExpID= " & .Tag)
                
                .Text = Format(PickDate.Value, "dd/mm/yyyy")
                .SubItems(1) = Txt(1).Text
                .SubItems(2) = Txt(2).Text
                .SubItems(3) = Txt(3).Text
                 
     
     
     
    
     
            End With
        End If
        Unload Me
    End Sub
    
    Private Sub DTPicker1_GotFocus()
        Lbl(0).FontBold = True
        Lbl(0).FontItalic = True
        Lbl(0).FontUnderline = True
    End Sub
    
    Private Sub DTPicker1_LostFocus()
        Lbl(0).FontBold = False
        Lbl(0).FontItalic = False
        Lbl(0).FontUnderline = False
    End Sub
    
    Private Sub Txt_GotFocus(Index As Integer)
        Lbl(Index).FontBold = True
        Lbl(Index).FontItalic = True
        Lbl(Index).FontUnderline = True
    End Sub
    
    Private Sub Txt_KeyPress(Index As Integer, KeyAscii As Integer)
        If Index Like "[23]" Then
            If Not (Chr$(KeyAscii) Like "[0-9,]") And KeyAscii <> 8 Then KeyAscii = 0
        End If
    End Sub
    
    Private Sub Txt_LostFocus(Index As Integer)
        Lbl(Index).FontBold = False
        Lbl(Index).FontItalic = False
        Lbl(Index).FontUnderline = False
        If Index = 2 Then
            If Not IsNumeric(Txt(2).Text) Then Txt(2).Text = 1
        ElseIf Index = 3 Then
            If Not IsNumeric(Txt(3).Text) Then Txt(3).Text = 0
        End If
    End Sub

  9. #9

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,110

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    this is the form
    Code:
    Option Explicit
    Private m_hookedLV As Boolean
     
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    
    Private Const GW_CHILD = 5
    Private Const GWL_EXSTYLE = (-20)
    Private Const WS_EX_LAYOUTRTL = &H400000
    
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Declare Function InvalidateRect Lib "user32.dll" (ByVal hwnd As Long, lpRect As RECT, ByVal bErase As Long) As Long
    Private Declare Function GetWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    
    Private Sub ListRTL(Liv As ListView)
        Dim rClientRect As RECT
        Dim ReturnStyle As Long
        Dim Header_hWnd As Long
        
        ReturnStyle = GetWindowLong(Liv.hwnd, GWL_EXSTYLE)
        SetWindowLong Liv.hwnd, GWL_EXSTYLE, ReturnStyle Or WS_EX_LAYOUTRTL
        GetClientRect Liv.hwnd, rClientRect
        InvalidateRect Liv.hwnd, rClientRect, True
        Header_hWnd = GetWindow(Liv.hwnd, GW_CHILD)
        ReturnStyle = GetWindowLong(Header_hWnd, GWL_EXSTYLE)
        SetWindowLong Header_hWnd, GWL_EXSTYLE, ReturnStyle Or WS_EX_LAYOUTRTL
        GetClientRect Header_hWnd, rClientRect
        InvalidateRect Header_hWnd, rClientRect, True
    End Sub
    
    
    Private Sub BttnDelete_Click()
        LsVw.SetFocus
        If MsgBox("?delete", vbInformation + vbDefaultButton2 + vbYesNo, LsVw.SelectedItem) = vbNo Then Exit Sub
        
        Dim NewIdx As Long
        Set RS = CN.Execute("DELETE * FROM Expenses WHERE ExpID= " & LsVw.SelectedItem.Tag)
        With LsVw
            NewIdx = IIf(.SelectedItem.Index = .ListItems.Count, .ListItems.Count - 1, .SelectedItem.Index)
            .ListItems.Remove .SelectedItem.Index
            If .ListItems.Count > 0 Then Set .SelectedItem = .ListItems(NewIdx)
        End With
    End Sub
    
    Private Sub bttnreport_Click()
    Set dtrrpt.DataSource = CN.Execute("select * from expenses ")
    dtrrpt.Show 1
    End Sub
    
    Private Sub Form_Load()
     
     
         Me.WindowState = 2
        LsVw.ColumnHeaders(1).Icon = "asc"
        Set RS = CN.Execute("SELECT * FROM Expenses ORDER BY ExpDate")
        While Not RS.EOF
            Set Itm = LsVw.ListItems.Add(, , Format(RS!ExpDate, "dd/mm/yyyy"), , "dolar")
            Itm.Tag = RS!ExpID
            Itm.SubItems(1) = RS!ExpType
            Itm.SubItems(2) = RS!ExpQuantity
            Itm.SubItems(3) = RS!ExpCost
            RS.MoveNext
        Wend
        ListRTL LsVw
            mLVClrHdr.HookToLV LsVw.hwnd, True
        mLVClrHdr.glHdrBkClr = &HD1B499
        mLVClrHdr.glHdrTextClr = vbWhite
        m_hookedLV = True
    End Sub
    
    Private Sub BttnBack_Click()
        Unload Me
    End Sub
    
     
    
    Private Sub BttnEdit_Click()
        NewRec = False
        LsVw.SetFocus
        FrmNewExpense.Show 1
    End Sub
    
    Private Sub BttnNew_Click()
        NewRec = True
        LsVw.SetFocus
        FrmNewExpense.Show 1
    End Sub
    
    Private Sub LsVw_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
        If ColumnHeader.Index = 1 Then
            LsVw.ListItems.clear
            ColumnHeader.Icon = IIf(ColumnHeader.Icon = "asc", "desc", "asc")
        
            If ColumnHeader.Icon = "asc" Then
                Set RS = CN.Execute("SELECT * FROM Expenses ORDER BY ExpDate")
            Else
                Set RS = CN.Execute("SELECT * FROM Expenses ORDER BY ExpDate DESC")
            End If
        
            LsVw.ListItems.clear
            While Not RS.EOF
                Set Itm = LsVw.ListItems.Add(, , Format(RS!ExpDate, "dd/mm/yyyy"), , "dolar")
                Itm.Tag = RS!ExpID
                Itm.SubItems(1) = RS!ExpType
                Itm.SubItems(2) = RS!ExpQuantity
                Itm.SubItems(3) = RS!ExpCost
                RS.MoveNext
            Wend
        End If
    End Sub
    
    Private Sub lvButtons_H5_Click()
    
    End Sub
    
    Private Sub refresh_Click()
    LsVw.Refresh
    End Sub
    
    Private Sub report_Click()
    
    End Sub
    
    Private Sub Tmr_Timer()
     
    
    
    
     
        If LsVw.ListItems.Count = 0 Then
            BttnEdit.Enabled = False
            BttnDelete.Enabled = False
            TxtQuantity.Text = 0
            TxtCost.Text = 0
            Exit Sub
            
        Else
            BttnEdit.Enabled = True
            BttnDelete.Enabled = True
        End If
        Set RS = CN.Execute("SELECT SUM(ExpQuantity) as SumQ, SUM(ExpCost) as SumC FROM Expenses")
        If RS.EOF Then
            TxtQuantity.Text = 0
            TxtCost.Text = 0
        Else
            TxtQuantity.Text = RS!SumQ
            TxtCost.Text = RS!SumC
        End If
    End Sub
    Private Sub Form_Resize()
    If MDImain.WindowState <> 2 Then Exit Sub
        
        With LsVw
            .Width = Me.Width - 500
            .Height = Me.Height - 1800
            .Left = ((Me.Width - .Width) / 2) - 50
            For I = 1 To 4
                .ColumnHeaders(I).Width = .Width / 4 - 110
            Next
        
            bttnreport.Top = .Top + .Height + 200
            lvButtons_H2.Top = .Top + .Height + 300
            BttnDelete.Top = .Top + .Height + 200
            lvButtons_H3.Top = .Top + .Height + 300
            BttnEdit.Top = .Top + .Height + 200
            lvButtons_H1.Top = .Top + .Height + 300
            BttnNew.Top = .Top + .Height + 200
            lvButtons_H4.Top = .Top + .Height + 300
            Label1.Top = .Top + .Height + 100
            Label2.Top = .Top + .Height + 500
            TxtQuantity.Top = .Top + .Height + 100
            TxtCost.Top = .Top + .Height + 500
            TxtQuantity.Left = .Left + 200
            TxtCost.Left = .Left + 200
            
         
          
           
          
        End With
        DoEvents
    End Sub

  10. #10
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    Debug.Print FormatCurrency(3.5) '==== $3.50

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,921

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    Scary to see somebody messing around with API calls when they can't get trivial VB code to work.

    I can't begin to describe how many ways this is wrong:
    Code:
    PickDate.Value = Format(.Text, "dd/mm/yyyy")
    Can you hire a programmer?

  12. #12

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,110

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    Quote Originally Posted by dilettante View Post
    Scary to see somebody messing around with API calls when they can't get trivial VB code to work.

    I can't begin to describe how many ways this is wrong:
    Code:
    PickDate.Value = Format(.Text, "dd/mm/yyyy")
    Can you hire a programmer?
    so this is why its not working?

    are you available ?

  13. #13
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,346

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    Is this what you want?

    vb Code:
    1. Private Sub Form_Load()
    2. Text1.Text = Format$(100, "$0.00")
    3. End Sub
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  14. #14

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,110

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    yes but it still dosnt show me the symbol next to the price
    Code:
     TxtCost.Text = Format$(100, "$0.00")

  15. #15
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    You have to use the Format$ function everywhere you assign a value to the TextBox
    Code:
    Private Sub Tmr_Timer()
         If LsVw.ListItems.Count = 0 Then
            BttnEdit.Enabled = False
            BttnDelete.Enabled = False
            TxtQuantity.Text = 0
            TxtCost.Text = Format$(CStr(0), "$0.00")
            Exit Sub
        Else
            BttnEdit.Enabled = True
            BttnDelete.Enabled = True
        End If
        Set RS = CN.Execute("SELECT SUM(ExpQuantity) as SumQ, SUM(ExpCost) as SumC FROM Expenses")
        If RS.EOF Then
            TxtQuantity.Text = 0
            TxtCost.Text = CStr(0)
        Else
            TxtQuantity.Text = RS!SumQ
            TxtCost.Text = CStr(RS!SumC)
        End If
        TxtCost.Text = Format$(TextCost.Text, "$0.00")
    End Sub
    It terrifies me that you're doing this in a timer though

  16. #16

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,110

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    tnk you it works!!!
    but it dosnt show me the currency of my country (euro)
    is there a way to change that?
    by the way instead of using timer what you suggest?

  17. #17
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    Use FormatCurrency (as suggested earlier):
    Code:
    Private Sub Tmr_Timer()
         If LsVw.ListItems.Count = 0 Then
            BttnEdit.Enabled = False
            BttnDelete.Enabled = False
            TxtQuantity.Text = 0
            TxtCost.Text = FormatCurrency(CStr(0), 2)  'This will produce the format as defined in Regional Settings
            Exit Sub
        Else
            BttnEdit.Enabled = True
            BttnDelete.Enabled = True
        End If
        Set RS = CN.Execute("SELECT SUM(ExpQuantity) as SumQ, SUM(ExpCost) as SumC FROM Expenses")
        If RS.EOF Then
            TxtQuantity.Text = 0
            TxtCost.Text = CStr(0)
        Else
            TxtQuantity.Text = RS!SumQ
            TxtCost.Text = CStr(RS!SumC)
        End If
        TxtCost.Text = FormatCurrency(TextCost.Text, 2)
    End Sub

  18. #18

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,110

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    genius!!!
    tnk you all for the help
    good day

  19. #19
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    Quote Originally Posted by salsa31 View Post
    genius!!!
    Actually no; all I did was to put together everyone else's suggestions

  20. #20

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,110

    Re: how to show Currency symbol like ( $ or Euro ) next to the price in a text

    creative!!
    this is not the first time you helping me
    take care amigo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width