dcsimg
Results 1 to 11 of 11

Thread: Assign dinamyc value to tetxtbox

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,918

    Assign dinamyc value to tetxtbox

    I have this code:


    for i=1 to 2

    me.tetxbox(i).text =myvar

    next i

    now i need to assign to the 3 textboxes the value of i in for next

    ...
    how to?

    have arror....

    in my form have text1,text2, text3
    Last edited by luca90; Jul 28th, 2018 at 07:25 AM.

  2. #2
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,099

    Re: Assign dinamyc value to tetxtbox

    Hi,

    here a sample ...
    add a Textbox to the Form with Index=0
    Code:
    Option Explicit
    
    Private Sub Form_Load()
      Dim mMonth As Long
       Dim mYear As Long
       Dim i As Long
       Dim d As Date
       
          mMonth = 7
          mYear = 2018
          d = CDate("01." & mMonth & "." & mYear)
          
          Text1(0).Text = d
          For i = 1 To 30
             d = d + 1
             If Month(d) <> mMonth Then
                Exit For
             End If
             Load Text1(i)
             Text1(i).Text = d
          Next
                
        'first part of Month
          For i = 1 To 14
             With Text1(i)
                .Top = Text1(0).Top + i * (.Height * 1.5)
                .Visible = True
             End With
          Next
          'rest of month
          For i = 15 To Text1.UBound
             With Text1(i)
                .Top = Text1(0).Top + (i - 15) * (.Height * 1.5)
                .Left = Text1(0).Left + (.Width + 300)
                .Visible = True
             End With
          Next
          
    End Sub
    depending on how many Days the Month has, the Textboxes will be added

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,189

    Re: Assign dinamyc value to tetxtbox

    now i need to assign to the 3 textboxes the value of i in for next
    Huh?
    You want text1 to show "1"? You want text2 to show "2"? What about text3?

    Why would you want to show the value of i in those textboxes? (your loop will only occur twice---one when i is 1, and once when i is 2.

    You
    have arror....
    ??? If so, what is it? Might it be because you have an array of textboxes (as indicated in this code of yours---
    Code:
    me.tetxbox(i).text =myvar
    ? Is it because maybe you misspelled 'textbox' (tetxbox)??

    Anyway, a very confusing post (and with what Chris posted I am concerned you might not understand what he did). Can you answer my questions and/or explain a little better what you are trying to do? Do you have an array of textboxes AND three other textboxes named text1, text2 and text3?

    PS "dynamic" is the correct spelling...you inverted the y and i (in your title of this thread).

  4. #4
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,099

    Re: Assign dinamyc value to tetxtbox

    @ sam, well spotted..
    ? Is it because maybe you misspelled 'textbox' (tetxbox)??
    didn't see that

    I thought he wanted to add as many Textboxes as his myvar value

    let's see what Luca says

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,918

    Re: Assign dinamyc value to tetxtbox

    Quote Originally Posted by ChrisE View Post
    @ sam, well spotted..

    didn't see that

    I thought he wanted to add as many Textboxes as his myvar value

    let's see what Luca says

    regards
    Chris

    Sorry for bad explain...

    i need to assign to me.text a simple value of for next...

    for example:

    i need me.text"&i&".text"

    me.text1.text

    and not use (i) as index value of textboxes

  6. #6
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,099

    Re: Assign dinamyc value to tetxtbox

    Hi,

    try this...
    add Text1 to Form and set Index =0
    Code:
    Private Sub Command4_Click()
    Dim i As Long
       
          For i = 1 To 5
            i = Text1.UBound + 1
            Load Text1(i)
             With Text1(i)
                .Top = .Top + i * .Height * 1.3
                .Text = .Text & "(" & i & ")"
                .Visible = True
             End With
          Next
    End Sub


    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  7. #7
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,189

    Re: Assign dinamyc value to tetxtbox

    That should get him started, Chris.

    Hopefully he understands about arrays of textboxes and how to use them. THEN comes his problem of assigning 'what' to each text box....varying values of myVar? OR, just add that number (myVar) of textboxes...

    Let's see....

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,969

    Re: Assign dinamyc value to tetxtbox

    I am wondering why he is wanting to use text1 text2 text3 and not use a control array. It makes no sense. If the text boxes had descriptive names then maybe I could understand as the descriptive names make it easier to read the code but to use the default text box names rather than a control array is nonsense in such a case.

  9. #9
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,979

    Re: Assign dinamyc value to tetxtbox

    Probably because Luca codes in VBA (as with 95% of his posts), and in Office/VBA there is no Control-Array!
    Maybe a case for Elroy's "kind-of-control-Array" in VBA from 2-3 months ago
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  10. #10
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,132

    Re: Assign dinamyc value to tetxtbox

    I don't know if Luca doesn't use control arrays because this is VBA and it is a limitation but in VB6 (not sure about VBA) you can iterate through the controls collection and set the text of a textbox based on the textbox name.
    Code:
    Private Sub Command1_Click()
    Dim i As Integer
    Dim txt As TextBox
    Dim txtBoxName As String
    Dim strText As String
    
    
        strText = "hello world"
        
        For i = 1 To 3
            txtBoxName = "Text" & i
            Set txt = Controls(txtBoxName)
            txt.Text = strText
            Set txt = Nothing
        Next i
    End Sub

  11. #11
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,969

    Re: Assign dinamyc value to tetxtbox

    If it is indeed VBA then it really should not be posted here. Belongs in the Office section.

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