Results 1 to 11 of 11

Thread: Dynamic Control Fill...[SOLVED]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96

    Dynamic Control Fill...[SOLVED]

    I want to fill some Controls with information I read from a file...
    The text is stored as:
    Formname | ControlName | Value
    eg.
    Form1|Text1|Textvalue

    When I run my code I get a `invalid qualifier`- error...
    so theres something miss in the syntax...
    it should give me
    Form1.Text1 = Textvalue

    VB Code:
    1. Open FileName For Input As #fnum
    2.  
    3.  Do Until EOF(1)
    4.      Line Input #fnum, data
    5.         If Not data = "" Then
    6.         elements = Split(data, "|")
    7.         'MsgBox elements(UBound(elements) - 2) & "-" & elements(UBound(elements) - 1) & "-" & elements(UBound(elements))
    8.         elements(UBound(elements) - 2).elements(UBound(elements) - 1) = elements(UBound(elements))
    9.         End If
    10.  Loop
    Last edited by Chrissie; Dec 13th, 2002 at 04:14 AM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96
    VB Code:
    1. Forms(elements(UBound(elements) - 2)).Controls(elements(UBound(elements) - 1)) = elements(UBound(elements))

    I guess this is better...but it gives me back a Error 13...when running the code..

  3. #3
    Hyperactive Member
    Join Date
    Nov 2002
    Location
    india
    Posts
    418
    hi

    check whether you place all text boxes correctly on form and also check form names with data.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96
    Yeah I checked that already...

    When I run this it works perfect...so I doubt wether my code in my last post is correct...
    VB Code:
    1. Form1.Text1 = "Textvalue"
    When I read the following line using the code stated above...
    Form1|Text1|Textvalue

    It gives me..."Type Mismatch" - Error 13

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96

    Nobody?

    Nobody?

  6. #6
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    If you are filling the default properties, then this should work.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4. Dim Data As String
    5. Dim Elements() As String
    6.  
    7. Dim ctl As Control
    8. Dim frm As Form
    9.  
    10.     Open "c:\test.txt" For Input As #1
    11.    
    12.         Do Until EOF(1)
    13.             Line Input #1, Data
    14.            
    15.             If Not Data = "" Then
    16.                 Elements = Split(Data, "|")
    17.                
    18.                 For Each frm In Forms
    19.                     If frm.Name = Elements(0) Then
    20.                         Exit For
    21.                     End If
    22.                 Next frm
    23.                
    24.                 For Each ctl In frm.Controls
    25.                     If ctl.Name = Elements(1) Then
    26.                         ctl = Elements(2)
    27.                         Exit For
    28.                     End If
    29.                 Next ctl
    30.             End If
    31.         Loop
    32.     Close #1
    33. End Sub

  7. #7
    Addicted Member Sully's Avatar
    Join Date
    Nov 2002
    Location
    Lost in the far recesses of one's own mind.
    Posts
    165
    Also, you might try:

    trim(elements(ubound(elements)-2)).trim(elements(ubound(elements) -1)) = trim(elements(ubound(elements)))

    JS
    Disclaimer:

    * The preceding message was in no means meant to be critical, mean spirited, insincere, or facetious.

    Disclaimer for disclaimer:

    The preceding disclaimer may in fact be facetious in nature.

    Thanks,
    Jim

  8. #8
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    Originally posted by Sully
    Also, you might try:

    trim(elements(ubound(elements)-2)).trim(elements(ubound(elements) -1)) = trim(elements(ubound(elements)))

    JS
    The problem with this approach is the elements are being returned as strings and can not be converted to objects.

  9. #9
    Addicted Member Sully's Avatar
    Join Date
    Nov 2002
    Location
    Lost in the far recesses of one's own mind.
    Posts
    165
    You are correct Sir, I was just looking at that...but I think you should include the trim function in the if structures in your code above.

    JS
    Last edited by Sully; Dec 12th, 2002 at 01:01 PM.
    Disclaimer:

    * The preceding message was in no means meant to be critical, mean spirited, insincere, or facetious.

    Disclaimer for disclaimer:

    The preceding disclaimer may in fact be facetious in nature.

    Thanks,
    Jim

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96
    What if I have this info stored in the file...won't fill in the control arrays.
    frmInput|Text4(1)|Text4 - 1
    frmInput|Text4(0)|Text4 - 3

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96
    WOHOO! Got it finally working!!
    Thanks for all your help..

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim Data As String
    3. Dim Elements() As String
    4.  
    5. Dim ctl As Control
    6. Dim frm As Form
    7. Dim indexElements As String
    8.  
    9.     Open "C:\Data.txt" For Input As #1
    10.    
    11.         Do Until EOF(1)
    12.             Line Input #1, Data
    13.            
    14.             If Not Data = "" Then
    15.                 Elements = Split(Data, "|")
    16.                
    17.                 indexElements = ""
    18.                 If Right(Elements(1), 1) = ")" Then
    19.                     indexElements = Replace(Right(Elements(1), 2), ")", "")
    20.                     Elements(1) = Left(Elements(1), (Len(Elements(1)) - 3))
    21.                 End If
    22.                                
    23.                 For Each frm In Forms
    24.                     If frm.Name = Elements(0) Then
    25.                         Exit For
    26.                     End If
    27.                 Next frm
    28.                
    29.                 For Each ctl In frm.Controls
    30.                     If ctl.Name = Elements(1) Then
    31.                         If indexElements = "" Then
    32.                             ctl = Elements(2)
    33.                             Exit For
    34.                         Else
    35.                             If ctl.Index = indexElements Then
    36.                                 ctl = Elements(2)
    37.                                 Exit For
    38.                             End If
    39.                         End If
    40.                     End If
    41.                 Next ctl
    42.             End If
    43.         Loop
    44.     Close #1
    45. End Sub

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