Results 1 to 16 of 16

Thread: I know, it will be a stupid question, however...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    I know, it will be a stupid question, however...

    Hi all, again me
    How to use the Replace function at the array of controls (the array TextBoxes)?
    thanks in advance
    I know, I know, my English is bad, sorry .....

  2. #2
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: I know, it will be a stupid question, however...

    You'll have to be more clear. Do you want to use the Replace function on the text of each textbox in the array?

  3. #3
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: I know, it will be a stupid question, however...

    With a simple loop:
    Code:
    Dim N As Long
    
    For N = 0 To (Text1.Count - 1)
        Text1(N).Text = Replace$(Text1(N).Text, "to replace", "replace with")
    Next N

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: I know, it will be a stupid question, however...

    thanks for replies

    @Logophobic:

    Yes, exactly. The sign of comma in my Country it's using as separate at decimals. And because I want to use the function Val then I have to exchange for calculations the sign of comma on sign the dot.

    tamgovb
    Last edited by Tamgovb; Jun 12th, 2007 at 05:10 PM.
    I know, I know, my English is bad, sorry .....

  5. #5

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: I know, it will be a stupid question, however...

    OK, OK Martin

    I want to use function Val in my programme, So….all users would have probably to alter settings, is not it?

    My programme will not be probably such attractive then as I would want this? What about this you think Martin?

    I greet tamgovb
    I know, I know, my English is bad, sorry .....

  7. #7
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: I know, it will be a stupid question, however...

    The simplest you could do is is to use Val and Replace comma with dot before using it. Like: Value = Val(Replace(Text1(Index).Text, ",", "."))

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: I know, it will be a stupid question, however...

    Hi Merri
    to get to know you pleasantly.

    I write unfortunately therefore that this doesn't want me to work.

    i greet tamgovb
    I know, I know, my English is bad, sorry .....

  9. #9

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: I know, it will be a stupid question, however...

    obviously!!!
    Attached Files Attached Files
    I know, I know, my English is bad, sorry .....

  11. #11
    Addicted Member malik641's Avatar
    Join Date
    Sep 2005
    Location
    South Florida :-)
    Posts
    221

    Re: I know, it will be a stupid question, however...

    What about something like:
    Code:
    Private Sub Command1_Click()
    Dim Index As Integer
    Label1.Caption = _
        Val(Replace(Replace( _
                (Replace(Text1(Index).Text, ",", "|") _
                    ), ".", "") _
            , "|", "."))
    End Sub
    So an example could be from 33.333,25 = 33333.25

    Is that what you're looking for?




    If you find any of my posts of good help, please rate it

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: I know, it will be a stupid question, however...

    sorry malik641 but still works only Text1 (0).text
    I know, I know, my English is bad, sorry .....

  13. #13
    Addicted Member malik641's Avatar
    Join Date
    Sep 2005
    Location
    South Florida :-)
    Posts
    221

    Re: I know, it will be a stupid question, however...

    I meant the return value for Val() in your procedure. Because in your original procedure if you have 33.333,25 you would end up with 33.333 and I thought you might want something different.
    Anyways, for the rest of your question I would just go with gavio's suggestion:
    Code:
    Private Sub Command1_Click()
    Dim Index As Integer
    
    For Index = 0 To (Text1.Count - 1)
        Text1(Index).Text = _
            Val(Replace(Replace( _
                    (Replace(Text1(Index).Text, ",", "|") _
                        ), ".", "") _
                , "|", "."))
    Next Index
    End Sub




    If you find any of my posts of good help, please rate it

  14. #14
    Addicted Member malik641's Avatar
    Join Date
    Sep 2005
    Location
    South Florida :-)
    Posts
    221

    Re: I know, it will be a stupid question, however...

    Forgot to mention it will change the values in the text boxes instead of labels




    If you find any of my posts of good help, please rate it

  15. #15
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: I know, it will be a stupid question, however...

    Do you need to use Val? You may be able to use CDbl instead, but you'll need to make sure the string is numeric first.
    Code:
    If IsNumeric(Text1.Text) Then
      dblValue = CDbl(Text1.Text)
    Else
      dblValue = 0
    End If
    As a function: (Returns 0 if not numeric)
    Code:
    Public Function MyVal(Number As String) As Double
      If IsNumeric(Number) Then MyVal = CDbl(Number)
    End Function
    Last edited by Logophobic; Jun 12th, 2007 at 08:20 PM.

  16. #16

Posting Permissions

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



Click Here to Expand Forum to Full Width